neon-bindings / neon

Rust bindings for writing safe and fast native Node.js modules.
https://www.neon-bindings.com/
Apache License 2.0
7.98k stars 282 forks source link

`npm init neon --lib` #1014

Closed dherman closed 3 months ago

dherman commented 7 months ago

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 commented 5 months ago

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

kjvalencik commented 5 months ago

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