@napi-rs/cli 3.7.4 → 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.
- package/README.md +33 -0
- package/cli.mjs +9 -12
- package/dist/cli.js +9248 -1311
- package/dist/index.cjs +9268 -1331
- package/dist/index.d.cts +175 -157
- package/dist/index.d.ts +175 -157
- package/dist/index.js +9248 -1311
- package/docs/artifacts.md +33 -0
- package/docs/build.md +58 -0
- package/docs/create-npm-dirs.md +32 -0
- package/docs/new.md +39 -0
- package/docs/pre-publish.md +37 -0
- package/docs/rename.md +37 -0
- package/docs/universalize.md +31 -0
- package/docs/version.md +31 -0
- package/docs/wasi.md +161 -0
- package/package.json +11 -10
- package/src/api/__tests__/__snapshots__/templates.spec.ts.md +1019 -114
- package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
- package/src/api/__tests__/artifacts.spec.ts +17 -0
- package/src/api/__tests__/create-npm-dirs.spec.ts +14 -15
- package/src/api/__tests__/new.spec.ts +41 -5
- package/src/api/artifacts.ts +934 -108
- package/src/api/build.ts +1317 -188
- package/src/api/create-npm-dirs.ts +472 -101
- package/src/api/new.ts +354 -35
- package/src/api/pre-publish.ts +2845 -99
- package/src/api/rename.ts +1638 -124
- package/src/api/templates/js-binding.ts +216 -38
- package/src/api/templates/load-wasi-template.ts +1641 -111
- package/src/api/templates/wasi-worker-template.ts +32 -3
- package/src/commands/rename.ts +8 -3
- package/src/def/artifacts.ts +2 -2
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +2 -2
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/misc.spec.ts +124 -3
- package/src/utils/__tests__/version.spec.ts +47 -1
- package/src/utils/config.ts +15 -2
- package/src/utils/metadata.ts +155 -47
- package/src/utils/misc.ts +6079 -0
- package/src/utils/target.ts +66 -8
- package/src/utils/typegen.ts +1223 -63
- 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 {
|
|
4
|
-
import { resolve } from 'node:path'
|
|
5
|
-
import { fileURLToPath } from 'node:url'
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|