Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm init neon --lib #1014

Merged
merged 50 commits into from
May 6, 2024
Merged

npm init neon --lib #1014

merged 50 commits into from
May 6, 2024

Conversation

dherman
Copy link
Collaborator

@dherman dherman commented Jan 7, 2024

Add to create-neon the ability to create Neon libraries with sensible zero-config defaults set up for pre-builds, including fully functional CI/CD.

Follow-up issues:

Example:

% npm init neon -y --lib example-project

Wrote to /Users/dherman/neon-XAqoAt/example-project/package.json:

{
  "name": "example-project",
  "exports": {
    ".": {
      "import": {
        "types": "./lib/index.d.mts",
        "default": "./lib/index.mjs"
      },
      "require": {
        "types": "./lib/index.d.cts",
        "default": "./lib/index.cjs"
      }
    }
  },
  "types": "./lib/index.d.cts",
  "main": "./lib/index.cjs",
  "files": [
    "lib/**/*.?({c,m}){t,j}s"
  ],
  "scripts": {
    "test": "tsc && cargo test",
    "cargo-build": "tsc && cargo build --message-format=json > cargo.log",
    "cross-build": "tsc && cross build --message-format=json > cross.log",
    "postcargo-build": "neon dist < cargo.log",
    "postcross-build": "neon dist -m /target < cross.log",
    "debug": "npm run cargo-build --",
    "build": "npm run cargo-build -- --release",
    "cross": "npm run cross-build -- --release",
    "prepack": "tsc && neon update",
    "version": "neon bump --binaries platforms && git add .",
    "release": "gh workflow run release.yml -f dryrun=false -f version=patch",
    "dryrun": "gh workflow run publish.yml -f dryrun=true"
  },
  "neon": {
    "type": "library",
    "org": "@example-project",
    "platforms": {},
    "load": "./ts/load.cts"
  },
  "devDependencies": {
    "@neon-rs/cli": "^0.1.68",
    "@tsconfig/node18": "^18.2.2",
    "@types/node": "^20.11.16",
    "typescript": "^5.3.3"
  },
  "dependencies": {
    "@neon-rs/load": "^0.1.68"
  },
  "version": "1.0.0",
  "keywords": [],
  "author": "",
  "license": "MIT",
  "description": ""
}


✨ Created Neon project `example-project`. Happy 🦀 hacking! ✨
% ls example-project
Cargo.toml	README.md	package.json	platforms	src		ts		tsconfig.json

@dherman dherman changed the title npm init neon --lib [WIP] npm init neon --lib Jan 7, 2024
@@ -11,7 +11,7 @@ function readChunks(input: Readable): Readable {
});
input.on("close", () => {
output.write(decoder.end());
output.destroy();
output.end();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .destroy() call happened to work in the past but wasn't the right method to use, and it broke in more recent versions of Node.

@dherman dherman changed the title [WIP] npm init neon --lib npm init neon --lib Mar 27, 2024
David Herman and others added 13 commits March 27, 2024 09:58
- generates necessary boilerplate to be a portable Node library implemented in Rust
- uses TS by default (can be disabled)
- generates GitHub Actions boilerplate by default (can be disabled) to make publishing push-button
- README improveements
  * copy edits
  * coalesce directory layout docs into a table
- build.yml takes ref instead of branch
- setup action shares common setup routines
- scripts contain a `"release"` script instead of `"tag"`, which simply dispatches release.yml
@dherman dherman marked this pull request as ready for review March 27, 2024 17:27
@dherman
Copy link
Collaborator Author

dherman commented Mar 28, 2024

An example repo generated by this PR: https://github.com/dherman/create-neon-manual-test-project

@kjvalencik
Copy link
Member

Thanks so much for the example repo! That's really helpful for the review. ❤️

pkgs/create-neon/data/templates/.gitignore.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/.npmignore.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/README.md.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ts/index.mts.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ci/github/comments.yml.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ci/github/release.yml.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ci/github/setup.yml.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ci/github/setup.yml.hbs Outdated Show resolved Hide resolved
pkgs/create-neon/data/templates/ci/github/.env.hbs Outdated Show resolved Hide resolved
dherman added 9 commits April 15, 2024 09:54
- use a wrapper type instead of a string subtype as the example wrapper logic, for clarity
- use `declare module` for a better suggested style of interacting with the addon (to avoid the any type)
- cfg matrix should have .script: string not .cross: boolean
- prepack should include `tsc &&` for TS projects

### Creating a Portable Library

To create a portable npm library with pre-built binaries:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, it might not be obvious to a potential user what "portable" means.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point--I added some explanatory text.

"neonPublish": "v0.4.1",
"dotenv": "v1",
"ghRelease": "v1",
"releaseDownloader": "v1.7"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does GitHub offer any protections on these tags changing? They didn't used to, but I'm not sure if they added it.

If not, can we use explicit SHA on unofficial actions?

Copy link
Collaborator Author

@dherman dherman May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I divided the versions.json metadata into two categories, one for verified and one for unverified actions:

  "actions": {
    "verified": {
      "checkout": "v3",
      "githubScript": "v7",
      "setupNode": "v3",
      "setupRust": "v1",
      "cargoInstall": "v2",
      "neonBuild": "v0.9",
      "neonPublish": "v0.4.1"
    },
    "unverified": {
      "dotenv": {
        "tag": "v1.1.2",
        "sha": "d1cd55661714e830a6e26f608f81d36e23424fed"
      },
      "ghRelease": {
        "tag": "v2.0.4",
        "sha": "9d7c94cfd0a1f3ed45544c887983e9fa900f0564"
      },
      "releaseDownloader": {
        "tag": "v1.10",
        "sha": "c39a3b234af58f0cf85888573d361fb6fa281534"
      }
    }
  }

And I changed the template to generate an explicit SHA reference with a comment noting the version tag, e.g.:

- name: Set Environment Variables
  uses: falti/dotenv-action@d1cd55661714e830a6e26f608f81d36e23424fed # v1.1.2

Copy link
Member

@kjvalencik kjvalencik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic! I'm super excited. 🎉

@dherman dherman merged commit 62440e2 into main May 6, 2024
9 checks passed
@dherman dherman deleted the create-neon-lib branch May 6, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants