@napi-rs/cli 3.9.0 → 3.10.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 +17 -4
- package/dist/cli.js +10359 -8729
- package/dist/index.cjs +10381 -8751
- package/dist/index.d.cts +83 -16
- package/dist/index.d.ts +83 -16
- package/dist/index.js +10359 -8729
- package/docs/wasi.md +318 -4
- package/package.json +5 -6
- package/src/api/__tests__/__snapshots__/templates.spec.ts.md +4003 -53
- package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
- package/src/api/__tests__/build-regressions.spec.ts +210 -3
- package/src/api/__tests__/build.spec.ts +2333 -3
- package/src/api/__tests__/create-npm-dirs.spec.ts +105 -3
- package/src/api/__tests__/pre-publish.spec.ts +153 -1
- package/src/api/__tests__/templates.spec.ts +1309 -1
- package/src/api/build.ts +756 -30
- package/src/api/create-npm-dirs.ts +23 -10
- package/src/api/new.ts +13 -18
- package/src/api/pre-publish.ts +34 -11
- package/src/api/rename.ts +10 -21
- package/src/api/templates/binding-target.ts +176 -0
- package/src/api/templates/index.ts +1 -0
- package/src/api/templates/js-binding.ts +54 -10
- package/src/api/templates/load-wasi-template.ts +661 -58
- package/src/api/templates/wasi-worker-template.ts +36 -31
- package/src/commands/build.ts +1 -1
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +18 -28
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/misc.spec.ts +4 -0
- package/src/utils/__tests__/reconciliation.spec.ts +676 -0
- package/src/utils/__tests__/serialize.spec.ts +55 -0
- package/src/utils/__tests__/target.spec.ts +221 -0
- package/src/utils/__tests__/typegen.spec.ts +115 -0
- package/src/utils/config.ts +50 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/misc.ts +351 -79
- package/src/utils/serialize.ts +47 -0
- package/src/utils/target.ts +150 -1
- package/src/utils/typegen.ts +608 -42
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const WASI_WORKER_TEMPLATE = `import fs from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { parse } from
|
|
4
|
-
import { WASI } from
|
|
5
|
-
import { parentPort, Worker } from
|
|
1
|
+
export const WASI_WORKER_TEMPLATE = `import fs from 'node:fs'
|
|
2
|
+
import { createRequire } from 'node:module'
|
|
3
|
+
import { parse } from 'node:path'
|
|
4
|
+
import { WASI } from 'node:wasi'
|
|
5
|
+
import { parentPort, Worker, workerData } from 'node:worker_threads'
|
|
6
6
|
|
|
7
|
-
const require = createRequire(import.meta.url)
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
8
|
|
|
9
9
|
const {
|
|
10
10
|
instantiateNapiModuleSync,
|
|
@@ -12,12 +12,12 @@ const {
|
|
|
12
12
|
getDefaultContext,
|
|
13
13
|
emnapiAsyncWorkPlugin,
|
|
14
14
|
emnapiTSFNPlugin,
|
|
15
|
-
} = require(
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
16
|
|
|
17
17
|
if (parentPort) {
|
|
18
|
-
parentPort.on(
|
|
19
|
-
globalThis.onmessage({ data })
|
|
20
|
-
})
|
|
18
|
+
parentPort.on('message', (data) => {
|
|
19
|
+
globalThis.onmessage({ data })
|
|
20
|
+
})
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
Object.assign(globalThis, {
|
|
@@ -25,18 +25,25 @@ Object.assign(globalThis, {
|
|
|
25
25
|
require,
|
|
26
26
|
Worker,
|
|
27
27
|
importScripts: function (f) {
|
|
28
|
-
|
|
28
|
+
// oxlint-disable-next-line no-eval -- WASI importScripts polyfill
|
|
29
|
+
;(0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f)
|
|
29
30
|
},
|
|
30
31
|
postMessage: function (msg) {
|
|
31
32
|
if (parentPort) {
|
|
32
|
-
parentPort.postMessage(msg)
|
|
33
|
+
parentPort.postMessage(msg)
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
|
-
})
|
|
36
|
+
})
|
|
36
37
|
|
|
37
|
-
const emnapiContext = getDefaultContext()
|
|
38
|
+
const emnapiContext = getDefaultContext()
|
|
38
39
|
|
|
39
|
-
const
|
|
40
|
+
const __cwd = process.cwd()
|
|
41
|
+
const __rootDir =
|
|
42
|
+
(workerData && typeof workerData.rootDir === 'string' && workerData.rootDir) ||
|
|
43
|
+
parse(__cwd).root
|
|
44
|
+
const __hostRoot =
|
|
45
|
+
(workerData && typeof workerData.hostRoot === 'string' && workerData.hostRoot) ||
|
|
46
|
+
(process.platform === 'android' ? __cwd : __rootDir)
|
|
40
47
|
|
|
41
48
|
const handler = new MessageHandler({
|
|
42
49
|
onLoad({ wasmModule, wasmMemory }) {
|
|
@@ -44,9 +51,10 @@ const handler = new MessageHandler({
|
|
|
44
51
|
version: 'preview1',
|
|
45
52
|
env: process.env,
|
|
46
53
|
preopens: {
|
|
47
|
-
[__rootDir]:
|
|
54
|
+
[__rootDir]: __hostRoot,
|
|
55
|
+
[__hostRoot]: __hostRoot,
|
|
48
56
|
},
|
|
49
|
-
})
|
|
57
|
+
})
|
|
50
58
|
|
|
51
59
|
return instantiateNapiModuleSync(wasmModule, {
|
|
52
60
|
childThread: true,
|
|
@@ -62,16 +70,16 @@ const handler = new MessageHandler({
|
|
|
62
70
|
...importObject.env,
|
|
63
71
|
...importObject.napi,
|
|
64
72
|
...importObject.emnapi,
|
|
65
|
-
memory: wasmMemory
|
|
66
|
-
}
|
|
73
|
+
memory: wasmMemory,
|
|
74
|
+
}
|
|
67
75
|
},
|
|
68
|
-
})
|
|
76
|
+
})
|
|
69
77
|
},
|
|
70
|
-
})
|
|
78
|
+
})
|
|
71
79
|
|
|
72
80
|
globalThis.onmessage = function (e) {
|
|
73
|
-
handler.handle(e)
|
|
74
|
-
}
|
|
81
|
+
handler.handle(e)
|
|
82
|
+
}
|
|
75
83
|
`
|
|
76
84
|
|
|
77
85
|
export const createWasiBrowserWorkerBinding = (
|
|
@@ -110,10 +118,9 @@ const fs = createFsProxy(__memfsExported)`
|
|
|
110
118
|
// eslint-disable-next-line no-console
|
|
111
119
|
console.log.apply(console, arguments)
|
|
112
120
|
},
|
|
113
|
-
printErr: function() {
|
|
121
|
+
printErr: function () {
|
|
114
122
|
// eslint-disable-next-line no-console
|
|
115
|
-
console.error.apply(console, arguments)
|
|
116
|
-
${errorOutputsAppend}
|
|
123
|
+
console.error.apply(console, arguments)${errorOutputsAppend}
|
|
117
124
|
},
|
|
118
125
|
})`
|
|
119
126
|
: `const wasi = new WASI({
|
|
@@ -121,10 +128,9 @@ const fs = createFsProxy(__memfsExported)`
|
|
|
121
128
|
// eslint-disable-next-line no-console
|
|
122
129
|
console.log.apply(console, arguments)
|
|
123
130
|
},
|
|
124
|
-
printErr: function() {
|
|
131
|
+
printErr: function () {
|
|
125
132
|
// eslint-disable-next-line no-console
|
|
126
|
-
console.error.apply(console, arguments)
|
|
127
|
-
${errorOutputsAppend}
|
|
133
|
+
console.error.apply(console, arguments)${errorOutputsAppend}
|
|
128
134
|
},
|
|
129
135
|
})`
|
|
130
136
|
const errorHandler = errorEvent
|
|
@@ -156,8 +162,7 @@ const handler = new MessageHandler({
|
|
|
156
162
|
}
|
|
157
163
|
},
|
|
158
164
|
})
|
|
159
|
-
}
|
|
160
|
-
${errorHandler}
|
|
165
|
+
},${errorHandler ? `\n ${errorHandler}` : ''}
|
|
161
166
|
})
|
|
162
167
|
|
|
163
168
|
globalThis.onmessage = function (e) {
|
package/src/commands/build.ts
CHANGED
|
@@ -11,7 +11,7 @@ const debug = debugFactory('build')
|
|
|
11
11
|
export class BuildCommand extends BaseBuildCommand {
|
|
12
12
|
pipe = Option.String('--pipe', {
|
|
13
13
|
description:
|
|
14
|
-
'Pipe all outputs file to given command. e.g. `napi build --pipe "npx
|
|
14
|
+
'Pipe all outputs file to given command. e.g. `napi build --pipe "npx oxfmt"`',
|
|
15
15
|
})
|
|
16
16
|
|
|
17
17
|
cargoOptions = Option.Rest()
|
|
@@ -142,9 +142,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
142
142
|
}␊
|
|
143
143
|
export type Blake2bHasher = Blake2BHasher␊
|
|
144
144
|
␊
|
|
145
|
-
export declare class Blake2BKey {␊
|
|
146
|
-
␊
|
|
147
|
-
}␊
|
|
145
|
+
export declare class Blake2BKey {}␊
|
|
148
146
|
export type Blake2bKey = Blake2BKey␊
|
|
149
147
|
␊
|
|
150
148
|
export declare class ClassWithFactory {␊
|
|
@@ -257,7 +255,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
257
255
|
␊
|
|
258
256
|
export declare const enum ALIAS {␊
|
|
259
257
|
A = 0,␊
|
|
260
|
-
B = 1
|
|
258
|
+
B = 1,␊
|
|
261
259
|
}␊
|
|
262
260
|
␊
|
|
263
261
|
export interface AliasedStruct {␊
|
|
@@ -345,7 +343,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
345
343
|
Six = 6,␊
|
|
346
344
|
Eight = 8,␊
|
|
347
345
|
Nine = 9,␊
|
|
348
|
-
Ten = 10
|
|
346
|
+
Ten = 10,␊
|
|
349
347
|
}␊
|
|
350
348
|
␊
|
|
351
349
|
export declare function customStatusCode(): void␊
|
|
@@ -358,7 +356,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
358
356
|
export declare function dateToNumber(input: Date): number␊
|
|
359
357
|
␊
|
|
360
358
|
/** This is a const */␊
|
|
361
|
-
export const DEFAULT_COST: number␊
|
|
359
|
+
export declare const DEFAULT_COST: number␊
|
|
362
360
|
␊
|
|
363
361
|
export declare function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊
|
|
364
362
|
␊
|
|
@@ -374,9 +372,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
374
372
|
␊
|
|
375
373
|
export declare function eitherStringOrNumber(input: string | number): number␊
|
|
376
374
|
␊
|
|
377
|
-
export declare const enum Empty {␊
|
|
378
|
-
␊
|
|
379
|
-
}␊
|
|
375
|
+
export declare const enum Empty {}␊
|
|
380
376
|
␊
|
|
381
377
|
export declare function enumToI32(e: CustomNumEnum): number␊
|
|
382
378
|
␊
|
|
@@ -422,7 +418,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
422
418
|
/** Kills birds */␊
|
|
423
419
|
Cat = 1,␊
|
|
424
420
|
/** Tasty */␊
|
|
425
|
-
Duck = 2
|
|
421
|
+
Duck = 2,␊
|
|
426
422
|
}␊
|
|
427
423
|
␊
|
|
428
424
|
export declare function listObjKeys(obj: object): Array<string>␊
|
|
@@ -519,7 +515,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
519
515
|
export declare const enum Status {␊
|
|
520
516
|
Pristine = 'Pristine',␊
|
|
521
517
|
Loading = 'Loading',␊
|
|
522
|
-
Ready = 'Ready'
|
|
518
|
+
Ready = 'Ready',␊
|
|
523
519
|
}␊
|
|
524
520
|
␊
|
|
525
521
|
export interface StrictObject {␊
|
|
@@ -695,9 +691,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
695
691
|
}␊
|
|
696
692
|
export type Blake2bHasher = Blake2BHasher␊
|
|
697
693
|
␊
|
|
698
|
-
export declare class Blake2BKey {␊
|
|
699
|
-
␊
|
|
700
|
-
}␊
|
|
694
|
+
export declare class Blake2BKey {}␊
|
|
701
695
|
export type Blake2bKey = Blake2BKey␊
|
|
702
696
|
␊
|
|
703
697
|
export declare class ClassWithFactory {␊
|
|
@@ -810,7 +804,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
810
804
|
␊
|
|
811
805
|
export declare enum ALIAS {␊
|
|
812
806
|
A = 0,␊
|
|
813
|
-
B = 1
|
|
807
|
+
B = 1,␊
|
|
814
808
|
}␊
|
|
815
809
|
␊
|
|
816
810
|
export interface AliasedStruct {␊
|
|
@@ -898,7 +892,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
898
892
|
Six = 6,␊
|
|
899
893
|
Eight = 8,␊
|
|
900
894
|
Nine = 9,␊
|
|
901
|
-
Ten = 10
|
|
895
|
+
Ten = 10,␊
|
|
902
896
|
}␊
|
|
903
897
|
␊
|
|
904
898
|
export declare function customStatusCode(): void␊
|
|
@@ -911,7 +905,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
911
905
|
export declare function dateToNumber(input: Date): number␊
|
|
912
906
|
␊
|
|
913
907
|
/** This is a const */␊
|
|
914
|
-
export const DEFAULT_COST: number␊
|
|
908
|
+
export declare const DEFAULT_COST: number␊
|
|
915
909
|
␊
|
|
916
910
|
export declare function derefUint8Array(a: Uint8Array, b: Uint8ClampedArray): number␊
|
|
917
911
|
␊
|
|
@@ -927,9 +921,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
927
921
|
␊
|
|
928
922
|
export declare function eitherStringOrNumber(input: string | number): number␊
|
|
929
923
|
␊
|
|
930
|
-
export declare enum Empty {␊
|
|
931
|
-
␊
|
|
932
|
-
}␊
|
|
924
|
+
export declare enum Empty {}␊
|
|
933
925
|
␊
|
|
934
926
|
export declare function enumToI32(e: CustomNumEnum): number␊
|
|
935
927
|
␊
|
|
@@ -975,7 +967,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
975
967
|
/** Kills birds */␊
|
|
976
968
|
Cat = 1,␊
|
|
977
969
|
/** Tasty */␊
|
|
978
|
-
Duck = 2
|
|
970
|
+
Duck = 2,␊
|
|
979
971
|
}␊
|
|
980
972
|
␊
|
|
981
973
|
export declare function listObjKeys(obj: object): Array<string>␊
|
|
@@ -1069,9 +1061,7 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1069
1061
|
␊
|
|
1070
1062
|
export declare function setSymbolInObj(symbol: symbol): object␊
|
|
1071
1063
|
␊
|
|
1072
|
-
export type Status =
|
|
1073
|
-
'Loading'|␊
|
|
1074
|
-
'Ready';␊
|
|
1064
|
+
export type Status = 'Pristine' | 'Loading' | 'Ready'␊
|
|
1075
1065
|
␊
|
|
1076
1066
|
export interface StrictObject {␊
|
|
1077
1067
|
name: string␊
|
|
@@ -1172,12 +1162,12 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1172
1162
|
|
|
1173
1163
|
`export declare enum Priority {␊
|
|
1174
1164
|
Low = 0,␊
|
|
1175
|
-
High = 1
|
|
1165
|
+
High = 1,␊
|
|
1176
1166
|
}␊
|
|
1177
1167
|
␊
|
|
1178
1168
|
export declare enum Status {␊
|
|
1179
1169
|
Active = 'Active',␊
|
|
1180
|
-
Inactive = 'Inactive'
|
|
1170
|
+
Inactive = 'Inactive',␊
|
|
1181
1171
|
}␊
|
|
1182
1172
|
`
|
|
1183
1173
|
|
|
@@ -1187,11 +1177,11 @@ Generated by [AVA](https://avajs.dev).
|
|
|
1187
1177
|
|
|
1188
1178
|
`export declare const enum Priority {␊
|
|
1189
1179
|
Low = 0,␊
|
|
1190
|
-
High = 1
|
|
1180
|
+
High = 1,␊
|
|
1191
1181
|
}␊
|
|
1192
1182
|
␊
|
|
1193
1183
|
export declare const enum Status {␊
|
|
1194
1184
|
Active = 'Active',␊
|
|
1195
|
-
Inactive = 'Inactive'
|
|
1185
|
+
Inactive = 'Inactive',␊
|
|
1196
1186
|
}␊
|
|
1197
1187
|
`
|
|
Binary file
|
|
@@ -71,6 +71,10 @@ test('updatePackageJson merges nested objects instead of overwriting them', asyn
|
|
|
71
71
|
fsevents: '^2.3.3',
|
|
72
72
|
'@napi-rs/fixture-darwin-arm64': '1.0.1',
|
|
73
73
|
})
|
|
74
|
+
|
|
75
|
+
const written = await readFile(packageJsonPath, 'utf8')
|
|
76
|
+
t.true(written.endsWith('\n'))
|
|
77
|
+
t.false(written.endsWith('\n\n'))
|
|
74
78
|
})
|
|
75
79
|
|
|
76
80
|
test('statIdentitiesMatch distinguishes inodes that collide as lossy Numbers', (t) => {
|