Skip to content

Commit 673d2c2

Browse files
kraenhansenclaude
andcommitted
feat(ferric): default to Node-API version 10 (#487)
* chore(ferric-example): target Node-API version 10 Bump the napi crate feature from napi3 to napi10, the highest version the host supports, and update the matching snippet in the ferric README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U2xSE1mz5goMZqhntiYJfa * docs(ferric): note napi3 as a smaller option when threadsafe functions aren't needed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U2xSE1mz5goMZqhntiYJfa * feat(ferric): default ferric init to Node-API version 10 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U2xSE1mz5goMZqhntiYJfa --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8d51f0a commit 673d2c2

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎.changeset/ferric-init-command.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Add a `ferric init [path]` command, scaffolding a package building a Rust Node-A
66

77
It writes the `package.json`, `Cargo.toml`, `build.rs`, `src/lib.rs` and `.gitignore` a package needs, and adds it to the workspace of the mono-repo it is initialized into. Run against a package that already exists, it bumps outdated dependencies and crates in place, and prints a diff for every update. A differing entrypoint or source file is skipped with a diff to merge by hand, unless `--force` is passed. `--dry-run` prints all of this without writing anything.
88

9-
A new `Cargo.toml` can be configured with `--node-api-version`, `--napi-crate-version`, `--napi-derive-crate-version`, `--napi-build-crate-version` and `--release-profile`.
9+
A new `Cargo.toml` enables Node-API version 10 by default, and can be configured with `--node-api-version`, `--napi-crate-version`, `--napi-derive-crate-version`, `--napi-build-crate-version` and `--release-profile`.

‎packages/ferric-example/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib"]
1111
version = "3.14.2"
1212
# see https://nodejs.org/api/n-api.html#node-api-version-matrix
1313
default-features = false
14-
features = ["napi3"]
14+
features = ["napi10"]
1515

1616
[dependencies.napi-derive]
1717
version = "3.6.12"

‎packages/ferric/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Before building, `ferric build` asks Cargo for the crate's resolved features for
1515
[dependencies.napi]
1616
version = "3"
1717
default-features = false
18-
features = ["napi3"]
18+
features = ["napi10"]
1919
```
2020

21+
From `napi4` onward, napi-rs's runtime uses threadsafe functions. If your addon doesn't need them (or anything else above Node-API 3), `napi3` gives a slightly smaller binary (about 5 KB for a minimal addon).
22+
2123
Pass `--skip-feature-check` to bypass the check.
2224

2325
## `ferric init [path]`
@@ -41,7 +43,7 @@ Running it against a package which already exists updates rather than overwrites
4143

4244
A newly created `Cargo.toml` can be configured with:
4345

44-
- `--node-api-version <version>`: the `napiN` feature to enable, defaulting to 3.
46+
- `--node-api-version <version>`: the `napiN` feature to enable, defaulting to 10.
4547
- `--napi-crate-version`, `--napi-derive-crate-version` and `--napi-build-crate-version`: the crate versions, defaulting to those tested with `ferric-example`. These also set what an existing `Cargo.toml` is bumped to.
4648
- `--release-profile <speed|size|none>`: `speed` (the default) enables `lto` and a single codegen unit, `size` also optimizes for size and strips symbols, and `none` leaves `[profile.release]` out.
4749

‎packages/ferric/src/init.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ describe("planInit", () => {
381381
assert.match(change.contents, /"\r?\n$/);
382382
});
383383

384-
it("defaults to Node-API version 3", async (context) => {
384+
it("defaults to Node-API version 10", async (context) => {
385385
const packagePath = setupTempDirectory(context);
386386
const plan = await planInit({ packagePath });
387-
assert.equal(DEFAULT_NODE_API_VERSION, 3);
387+
assert.equal(DEFAULT_NODE_API_VERSION, 10);
388388
const change = plan.changes.find(({ path: filePath }) =>
389389
filePath.endsWith("Cargo.toml"),
390390
);
391391
assert(change);
392-
assert.match(change.contents, /features = \["napi3"\]/);
392+
assert.match(change.contents, /features = \["napi10"\]/);
393393
});
394394

395395
it("rejects versions it cannot use", async (context) => {

‎packages/ferric/src/init.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import {
3838
const PACKAGE_ROOT = path.join(import.meta.dirname, "..");
3939
const TEMPLATES_PATH = path.join(PACKAGE_ROOT, "templates");
4040

41-
export const DEFAULT_NODE_API_VERSION = 3;
41+
export const DEFAULT_NODE_API_VERSION = 10;
4242

4343
export const DEFAULT_CRATE_VERSIONS: CrateVersions = {
4444
napi: "3.14.2",

0 commit comments

Comments
 (0)