@napi-rs/cli 3.7.3 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +33 -0
  2. package/cli.mjs +9 -12
  3. package/dist/cli.js +9277 -1313
  4. package/dist/index.cjs +9266 -1302
  5. package/dist/index.d.cts +176 -158
  6. package/dist/index.d.ts +176 -158
  7. package/dist/index.js +9277 -1313
  8. package/docs/artifacts.md +33 -0
  9. package/docs/build.md +58 -0
  10. package/docs/create-npm-dirs.md +32 -0
  11. package/docs/new.md +39 -0
  12. package/docs/pre-publish.md +37 -0
  13. package/docs/rename.md +37 -0
  14. package/docs/universalize.md +31 -0
  15. package/docs/version.md +31 -0
  16. package/docs/wasi.md +161 -0
  17. package/package.json +11 -10
  18. package/src/api/__tests__/__snapshots__/templates.spec.ts.md +1019 -114
  19. package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
  20. package/src/api/__tests__/artifacts.spec.ts +17 -0
  21. package/src/api/__tests__/create-npm-dirs.spec.ts +14 -15
  22. package/src/api/__tests__/new.spec.ts +41 -5
  23. package/src/api/artifacts.ts +934 -108
  24. package/src/api/build.ts +1325 -194
  25. package/src/api/create-npm-dirs.ts +472 -101
  26. package/src/api/new.ts +354 -35
  27. package/src/api/pre-publish.ts +2845 -99
  28. package/src/api/rename.ts +1638 -124
  29. package/src/api/templates/js-binding.ts +216 -38
  30. package/src/api/templates/load-wasi-template.ts +1641 -111
  31. package/src/api/templates/wasi-worker-template.ts +32 -3
  32. package/src/commands/rename.ts +8 -3
  33. package/src/def/artifacts.ts +2 -2
  34. package/src/utils/__tests__/__fixtures__/optional-napi-derive/Cargo.toml +3 -0
  35. package/src/utils/__tests__/__fixtures__/optional-napi-derive/main-crate/Cargo.toml +8 -0
  36. package/src/utils/__tests__/__fixtures__/optional-napi-derive/main-crate/src/lib.rs +1 -0
  37. package/src/utils/__tests__/__fixtures__/optional-napi-derive/napi-derive/Cargo.toml +5 -0
  38. package/src/utils/__tests__/__fixtures__/optional-napi-derive/napi-derive/src/lib.rs +1 -0
  39. package/src/utils/__tests__/__fixtures__/optional-napi-derive/with-optional-derive/Cargo.toml +11 -0
  40. package/src/utils/__tests__/__fixtures__/optional-napi-derive/with-optional-derive/src/lib.rs +1 -0
  41. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +2 -2
  42. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  43. package/src/utils/__tests__/metadata.spec.ts +43 -2
  44. package/src/utils/__tests__/misc.spec.ts +124 -3
  45. package/src/utils/__tests__/version.spec.ts +47 -1
  46. package/src/utils/config.ts +15 -2
  47. package/src/utils/metadata.ts +206 -7
  48. package/src/utils/misc.ts +6079 -0
  49. package/src/utils/target.ts +66 -8
  50. package/src/utils/typegen.ts +1223 -63
  51. package/src/utils/version.ts +96 -0
package/README.md CHANGED
@@ -15,6 +15,11 @@ yarn add @napi-rs/cli -D
15
15
  yarn napi build
16
16
  ```
17
17
 
18
+ ## Requirements
19
+
20
+ `@napi-rs/cli` supports Node.js `^20.17.0`, `^22.13.0`, and `>=23.5.0`.
21
+ Earlier Node.js releases are no longer supported by the CLI runtime.
22
+
18
23
  ## Commands
19
24
 
20
25
  | Command | desc | docs |
@@ -28,6 +33,34 @@ yarn napi build
28
33
  | version | Update version in created npm packages by `create-npm-dirs` | [./docs/version.md](./docs/version.md) |
29
34
  | pre-publish | Update package.json and copy addons into per platform packages | [./docs/pre-publish.md](./docs/pre-publish.md) |
30
35
 
36
+ ## Disposing generated WASI bindings
37
+
38
+ Generated WASI bindings expose deterministic cleanup through a non-enumerable
39
+ symbol on the binding object:
40
+
41
+ ```js
42
+ const binding = require('<package>')
43
+ const dispose = binding[Symbol.for('napi.rs.wasi.dispose')]
44
+
45
+ if (dispose) {
46
+ await dispose()
47
+ }
48
+ ```
49
+
50
+ The symbol is present only when the loaded binding is WASI. Browser WASI
51
+ loaders expose it on their default export. Disposal releases the instance: it
52
+ destroys the emnapi context and then terminates the workers owned by that
53
+ binding. Pending napi-rs runtime promises are settled or cancelled first only
54
+ when the binary exports the `napi_prepare_wasm_env_cleanup` preparation hook
55
+ (a planned napi-side follow-up); otherwise they may remain pending forever,
56
+ so settle in-flight work before disposing. Concurrent calls share one
57
+ promise, successful disposal is idempotent, and a failed cleanup phase can be
58
+ retried by calling the same function again. Do not call addon exports after
59
+ disposal completes.
60
+
61
+ See [WASI targets and loaders](./docs/wasi.md) for threaded, threadless,
62
+ browser, and workerd packaging behavior.
63
+
31
64
  ### Debug mode
32
65
 
33
66
  ```bash
package/cli.mjs CHANGED
@@ -1,15 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { execSync } from 'node:child_process'
4
- import { resolve } from 'node:path'
5
- import { fileURLToPath } from 'node:url'
3
+ import { existsSync } from 'node:fs'
6
4
 
7
- execSync(
8
- `node --import @oxc-node/core/register ${resolve(
9
- fileURLToPath(import.meta.url),
10
- '../src/cli.ts',
11
- )} ${process.argv.slice(2).join(' ')}`,
12
- {
13
- stdio: 'inherit',
14
- },
15
- )
5
+ const isSourceCheckout = existsSync(new URL('../Cargo.toml', import.meta.url))
6
+
7
+ if (isSourceCheckout) {
8
+ await import('@oxc-node/core/register')
9
+ await import('./src/cli.ts')
10
+ } else {
11
+ await import('./dist/cli.js')
12
+ }