@napi-rs/cli 3.0.0-alpha.8 → 3.0.0-alpha.81
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/cli.mjs +1 -1
- package/dist/api/artifacts.js +28 -7
- package/dist/api/artifacts.js.map +1 -1
- package/dist/api/build.js +310 -65
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +46 -9
- package/dist/api/create-npm-dirs.js.map +1 -1
- package/dist/api/new.js +57 -20
- package/dist/api/new.js.map +1 -1
- package/dist/api/pre-publish.js +9 -7
- package/dist/api/pre-publish.js.map +1 -1
- package/dist/api/rename.js +9 -1
- package/dist/api/rename.js.map +1 -1
- package/dist/api/templates/cargo.toml.js +1 -0
- package/dist/api/templates/cargo.toml.js.map +1 -1
- package/dist/api/templates/ci-template.d.ts +3 -1
- package/dist/api/templates/ci-template.js +140 -125
- package/dist/api/templates/ci-template.js.map +1 -1
- package/dist/api/templates/ci.yml.d.ts +3 -1
- package/dist/api/templates/ci.yml.js +21 -5
- package/dist/api/templates/ci.yml.js.map +1 -1
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/js-binding.js +141 -222
- package/dist/api/templates/js-binding.js.map +1 -1
- package/dist/api/templates/lib.rs.js +1 -4
- package/dist/api/templates/lib.rs.js.map +1 -1
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/load-wasi-template.js +168 -0
- package/dist/api/templates/load-wasi-template.js.map +1 -0
- package/dist/api/templates/package.json.d.ts +9 -2
- package/dist/api/templates/package.json.js +26 -4
- package/dist/api/templates/package.json.js.map +1 -1
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.js +122 -0
- package/dist/api/templates/wasi-worker-template.js.map +1 -0
- package/dist/api/universalize.js +5 -5
- package/dist/api/universalize.js.map +1 -1
- package/dist/api/version.js +2 -2
- package/dist/api/version.js.map +1 -1
- package/dist/commands/artifacts.js +2 -2
- package/dist/commands/artifacts.js.map +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/new.js +34 -34
- package/dist/commands/new.js.map +1 -1
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/artifacts.js +10 -2
- package/dist/def/artifacts.js.map +1 -1
- package/dist/def/build.d.ts +155 -4
- package/dist/def/build.js +30 -4
- package/dist/def/build.js.map +1 -1
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/create-npm-dirs.js +4 -0
- package/dist/def/create-npm-dirs.js.map +1 -1
- package/dist/def/new.d.ts +25 -7
- package/dist/def/new.js +11 -1
- package/dist/def/new.js.map +1 -1
- package/dist/def/pre-publish.d.ts +12 -2
- package/dist/def/pre-publish.js +7 -3
- package/dist/def/pre-publish.js.map +1 -1
- package/dist/def/rename.d.ts +16 -6
- package/dist/def/rename.js +5 -1
- package/dist/def/rename.js.map +1 -1
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/universalize.js +4 -0
- package/dist/def/universalize.js.map +1 -1
- package/dist/def/version.d.ts +10 -0
- package/dist/def/version.js +4 -0
- package/dist/def/version.js.map +1 -1
- package/dist/index.cjs +7596 -13754
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/__tests__/config.spec.d.ts +1 -0
- package/dist/utils/__tests__/config.spec.js +63 -0
- package/dist/utils/__tests__/config.spec.js.map +1 -0
- package/dist/utils/__tests__/typegen.spec.js +8 -4
- package/dist/utils/__tests__/typegen.spec.js.map +1 -1
- package/dist/utils/cargo.js +2 -2
- package/dist/utils/cargo.js.map +1 -1
- package/dist/utils/config.d.ts +52 -4
- package/dist/utils/config.js +37 -5
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/metadata.d.ts +13 -1
- package/dist/utils/metadata.js +31 -11
- package/dist/utils/metadata.js.map +1 -1
- package/dist/utils/misc.d.ts +1 -2
- package/dist/utils/misc.js +3 -3
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/target.d.ts +7 -5
- package/dist/utils/target.js +17 -3
- package/dist/utils/target.js.map +1 -1
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +55 -20
- package/dist/utils/typegen.js.map +1 -1
- package/dist/utils/version.d.ts +2 -1
- package/dist/utils/version.js +10 -8
- package/dist/utils/version.js.map +1 -1
- package/package.json +27 -26
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +468 -88
- package/src/api/create-npm-dirs.ts +57 -9
- package/src/api/new.ts +89 -31
- package/src/api/pre-publish.ts +13 -7
- package/src/api/rename.ts +10 -1
- package/src/api/templates/cargo.toml.ts +1 -0
- package/src/api/templates/ci-template.ts +150 -125
- package/src/api/templates/ci.yml.ts +27 -6
- package/src/api/templates/js-binding.ts +147 -220
- package/src/api/templates/lib.rs.ts +1 -4
- package/src/api/templates/load-wasi-template.ts +182 -0
- package/src/api/templates/package.json.ts +47 -5
- package/src/api/templates/wasi-worker-template.ts +122 -0
- package/src/api/universalize.ts +13 -8
- package/src/api/version.ts +5 -2
- package/src/commands/artifacts.ts +2 -2
- package/src/commands/build.ts +1 -1
- package/src/commands/new.ts +46 -45
- package/src/def/artifacts.ts +22 -3
- package/src/def/build.ts +64 -8
- package/src/def/create-npm-dirs.ts +9 -0
- package/src/def/new.ts +28 -3
- package/src/def/pre-publish.ts +12 -3
- package/src/def/rename.ts +11 -2
- package/src/def/universalize.ts +9 -0
- package/src/def/version.ts +9 -0
- package/src/index.ts +2 -0
- package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
- package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +28 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +711 -158
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +8 -7
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/config.spec.ts +81 -0
- package/src/utils/__tests__/typegen.spec.ts +18 -3
- package/src/utils/cargo.ts +2 -2
- package/src/utils/config.ts +116 -10
- package/src/utils/index.ts +0 -1
- package/src/utils/metadata.ts +52 -14
- package/src/utils/misc.ts +11 -3
- package/src/utils/target.ts +22 -4
- package/src/utils/typegen.ts +98 -49
- package/src/utils/version.ts +10 -8
- package/dist/api/load-wasi-template.d.ts +0 -1
- package/dist/api/load-wasi-template.js +0 -64
- package/dist/api/load-wasi-template.js.map +0 -1
- package/dist/api/wasi-worker-template.d.ts +0 -1
- package/dist/api/wasi-worker-template.js +0 -53
- package/dist/api/wasi-worker-template.js.map +0 -1
- package/dist/utils/ci.d.ts +0 -11
- package/dist/utils/ci.js +0 -96
- package/dist/utils/ci.js.map +0 -1
- package/src/api/load-wasi-template.ts +0 -66
- package/src/api/wasi-worker-template.ts +0 -52
- package/src/utils/ci.ts +0 -111
package/src/utils/typegen.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sortBy } from 'lodash-es'
|
|
1
|
+
import { sortBy, unionWith, isEqual } from 'lodash-es'
|
|
2
2
|
|
|
3
3
|
import { readFileAsync } from './misc.js'
|
|
4
4
|
|
|
@@ -10,7 +10,9 @@ export const DEFAULT_TYPE_DEF_HEADER = `/* auto-generated by NAPI-RS */
|
|
|
10
10
|
enum TypeDefKind {
|
|
11
11
|
Const = 'const',
|
|
12
12
|
Enum = 'enum',
|
|
13
|
+
StringEnum = 'string_enum',
|
|
13
14
|
Interface = 'interface',
|
|
15
|
+
Type = 'type',
|
|
14
16
|
Fn = 'fn',
|
|
15
17
|
Struct = 'struct',
|
|
16
18
|
Impl = 'impl',
|
|
@@ -25,24 +27,46 @@ interface TypeDefLine {
|
|
|
25
27
|
js_mod?: string
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
function prettyPrint(
|
|
30
|
+
function prettyPrint(
|
|
31
|
+
line: TypeDefLine,
|
|
32
|
+
constEnum: boolean,
|
|
33
|
+
ident: number,
|
|
34
|
+
ambient = false,
|
|
35
|
+
): string {
|
|
29
36
|
let s = line.js_doc ?? ''
|
|
30
37
|
switch (line.kind) {
|
|
31
38
|
case TypeDefKind.Interface:
|
|
32
39
|
s += `export interface ${line.name} {\n${line.def}\n}`
|
|
33
40
|
break
|
|
34
41
|
|
|
42
|
+
case TypeDefKind.Type:
|
|
43
|
+
s += `export type ${line.name} = \n${line.def}`
|
|
44
|
+
break
|
|
45
|
+
|
|
35
46
|
case TypeDefKind.Enum:
|
|
36
|
-
|
|
47
|
+
const enumName = constEnum ? 'const enum' : 'enum'
|
|
48
|
+
s += `${exportDeclare(ambient)} ${enumName} ${line.name} {\n${line.def}\n}`
|
|
49
|
+
break
|
|
50
|
+
|
|
51
|
+
case TypeDefKind.StringEnum:
|
|
52
|
+
if (constEnum) {
|
|
53
|
+
s += `${exportDeclare(ambient)} const enum ${line.name} {\n${line.def}\n}`
|
|
54
|
+
} else {
|
|
55
|
+
s += `export type ${line.name} = ${line.def.replaceAll(/.*=/g, '').replaceAll(',', '|')};`
|
|
56
|
+
}
|
|
37
57
|
break
|
|
38
58
|
|
|
39
59
|
case TypeDefKind.Struct:
|
|
40
|
-
s +=
|
|
60
|
+
s += `${exportDeclare(ambient)} class ${line.name} {\n${line.def}\n}`
|
|
41
61
|
if (line.original_name && line.original_name !== line.name) {
|
|
42
62
|
s += `\nexport type ${line.original_name} = ${line.name}`
|
|
43
63
|
}
|
|
44
64
|
break
|
|
45
65
|
|
|
66
|
+
case TypeDefKind.Fn:
|
|
67
|
+
s += `${exportDeclare(ambient)} ${line.def}`
|
|
68
|
+
break
|
|
69
|
+
|
|
46
70
|
default:
|
|
47
71
|
s += line.def
|
|
48
72
|
}
|
|
@@ -50,51 +74,65 @@ function prettyPrint(line: TypeDefLine, ident: number): string {
|
|
|
50
74
|
return correctStringIdent(s, ident)
|
|
51
75
|
}
|
|
52
76
|
|
|
77
|
+
function exportDeclare(ambient: boolean): string {
|
|
78
|
+
if (ambient) {
|
|
79
|
+
return 'export'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return 'export declare'
|
|
83
|
+
}
|
|
84
|
+
|
|
53
85
|
export async function processTypeDef(
|
|
54
86
|
intermediateTypeFile: string,
|
|
87
|
+
constEnum: boolean,
|
|
55
88
|
header?: string,
|
|
56
89
|
) {
|
|
57
90
|
const exports: string[] = []
|
|
58
91
|
const defs = await readIntermediateTypeFile(intermediateTypeFile)
|
|
59
92
|
const groupedDefs = preprocessTypeDef(defs)
|
|
60
93
|
|
|
61
|
-
header = header
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
94
|
+
header = header ?? ''
|
|
95
|
+
|
|
96
|
+
const dts =
|
|
97
|
+
sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
|
|
98
|
+
.map(([namespace, defs]) => {
|
|
99
|
+
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
100
|
+
return defs
|
|
101
|
+
.map((def) => {
|
|
102
|
+
switch (def.kind) {
|
|
103
|
+
case TypeDefKind.Const:
|
|
104
|
+
case TypeDefKind.Enum:
|
|
105
|
+
case TypeDefKind.StringEnum:
|
|
106
|
+
case TypeDefKind.Fn:
|
|
107
|
+
case TypeDefKind.Struct: {
|
|
108
|
+
exports.push(def.name)
|
|
109
|
+
if (def.original_name && def.original_name !== def.name) {
|
|
110
|
+
exports.push(def.original_name)
|
|
111
|
+
}
|
|
112
|
+
break
|
|
113
|
+
}
|
|
114
|
+
default:
|
|
115
|
+
break
|
|
77
116
|
}
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
117
|
+
return prettyPrint(def, constEnum, 0)
|
|
118
|
+
})
|
|
119
|
+
.join('\n\n')
|
|
120
|
+
} else {
|
|
121
|
+
exports.push(namespace)
|
|
122
|
+
let declaration = ''
|
|
123
|
+
declaration += `export declare namespace ${namespace} {\n`
|
|
124
|
+
for (const def of defs) {
|
|
125
|
+
declaration += prettyPrint(def, constEnum, 2, true) + '\n'
|
|
82
126
|
}
|
|
127
|
+
declaration += '}'
|
|
128
|
+
return declaration
|
|
83
129
|
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
dts += `export namespace ${namespace} {\n`
|
|
87
|
-
for (const def of defs) {
|
|
88
|
-
dts += prettyPrint(def, 2) + '\n'
|
|
89
|
-
}
|
|
90
|
-
dts += '}\n\n'
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
)
|
|
130
|
+
})
|
|
131
|
+
.join('\n\n') + '\n'
|
|
94
132
|
|
|
95
133
|
if (dts.indexOf('ExternalObject<') > -1) {
|
|
96
134
|
header += `
|
|
97
|
-
export class ExternalObject<T> {
|
|
135
|
+
export declare class ExternalObject<T> {
|
|
98
136
|
readonly '': {
|
|
99
137
|
readonly '': unique symbol
|
|
100
138
|
[K: symbol]: T
|
|
@@ -111,18 +149,22 @@ export class ExternalObject<T> {
|
|
|
111
149
|
|
|
112
150
|
async function readIntermediateTypeFile(file: string) {
|
|
113
151
|
const content = await readFileAsync(file, 'utf8')
|
|
114
|
-
const defs =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
line
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
152
|
+
const defs = unionWith(
|
|
153
|
+
content
|
|
154
|
+
.split('\n')
|
|
155
|
+
.filter(Boolean)
|
|
156
|
+
.map((line) => {
|
|
157
|
+
line = line.trim()
|
|
158
|
+
if (!line.startsWith('{')) {
|
|
159
|
+
// crateName:{ "def": "", ... }
|
|
160
|
+
const start = line.indexOf(':') + 1
|
|
161
|
+
line = line.slice(start)
|
|
162
|
+
}
|
|
163
|
+
return JSON.parse(line) as TypeDefLine
|
|
164
|
+
})
|
|
165
|
+
.filter((def) => !!def.kind),
|
|
166
|
+
(a, b) => isEqual(a, b),
|
|
167
|
+
)
|
|
126
168
|
|
|
127
169
|
// move all `struct` def to the very top
|
|
128
170
|
// and order the rest alphabetically.
|
|
@@ -186,13 +228,20 @@ export function correctStringIdent(src: string, ident: number): string {
|
|
|
186
228
|
const isInMultilineComment = line.startsWith('*')
|
|
187
229
|
const isClosingBracket = line.endsWith('}')
|
|
188
230
|
const isOpeningBracket = line.endsWith('{')
|
|
231
|
+
const isTypeDeclaration = line.endsWith('=')
|
|
232
|
+
const isTypeVariant = line.startsWith('|')
|
|
189
233
|
|
|
190
234
|
let rightIndent = ident
|
|
191
|
-
if (isOpeningBracket && !isInMultilineComment) {
|
|
235
|
+
if ((isOpeningBracket || isTypeDeclaration) && !isInMultilineComment) {
|
|
192
236
|
bracketDepth += 1
|
|
193
237
|
rightIndent += (bracketDepth - 1) * 2
|
|
194
238
|
} else {
|
|
195
|
-
if (
|
|
239
|
+
if (
|
|
240
|
+
isClosingBracket &&
|
|
241
|
+
bracketDepth > 0 &&
|
|
242
|
+
!isInMultilineComment &&
|
|
243
|
+
!isTypeVariant
|
|
244
|
+
) {
|
|
196
245
|
bracketDepth -= 1
|
|
197
246
|
}
|
|
198
247
|
rightIndent += bracketDepth * 2
|
package/src/utils/version.ts
CHANGED
|
@@ -7,20 +7,22 @@ export enum NapiVersion {
|
|
|
7
7
|
Napi6,
|
|
8
8
|
Napi7,
|
|
9
9
|
Napi8,
|
|
10
|
+
Napi9,
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/// because node support new napi version in some minor version updates, so we might meet such situation:
|
|
13
14
|
/// `node v10.20.0` supports `napi5` and `napi6`, but `node v12.0.0` only support `napi4`,
|
|
14
|
-
/// by which, we can not tell directly napi version
|
|
15
|
+
/// by which, we can not tell directly napi version supportless from node version directly.
|
|
15
16
|
const NAPI_VERSION_MATRIX = new Map<NapiVersion, string>([
|
|
16
|
-
[NapiVersion.Napi1, '8.6.0'],
|
|
17
|
-
[NapiVersion.Napi2, '8.10.0 | 9.3.0'],
|
|
18
|
-
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0'],
|
|
19
|
-
[NapiVersion.Napi4, '10.16.0 | 11.8.0'],
|
|
20
|
-
[NapiVersion.Napi5, '10.17.0 | 12.11.0'],
|
|
17
|
+
[NapiVersion.Napi1, '8.6.0 | 9.0.0 | 10.0.0'],
|
|
18
|
+
[NapiVersion.Napi2, '8.10.0 | 9.3.0 | 10.0.0'],
|
|
19
|
+
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0 | 10.0.0'],
|
|
20
|
+
[NapiVersion.Napi4, '10.16.0 | 11.8.0 | 12.0.0'],
|
|
21
|
+
[NapiVersion.Napi5, '10.17.0 | 12.11.0 | 13.0.0'],
|
|
21
22
|
[NapiVersion.Napi6, '10.20.0 | 12.17.0 | 14.0.0'],
|
|
22
|
-
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0'],
|
|
23
|
-
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0'],
|
|
23
|
+
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0 | 15.0.0'],
|
|
24
|
+
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0 | 16.0.0'],
|
|
25
|
+
[NapiVersion.Napi9, '18.17.0 | 20.3.0 | 21.1.0'],
|
|
24
26
|
])
|
|
25
27
|
|
|
26
28
|
interface NodeVersion {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createWasiBinding: (wasmFileName: string, wasiRegisterFunctions: string[]) => string;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export const createWasiBinding = (wasmFileName, wasiRegisterFunctions) => `/* eslint-disable */
|
|
2
|
-
/* prettier-ignore */
|
|
3
|
-
|
|
4
|
-
/* auto-generated by NAPI-RS */
|
|
5
|
-
|
|
6
|
-
import * as __nodeFsPromises from 'node:fs/promises'
|
|
7
|
-
import * as __nodePath from 'node:path'
|
|
8
|
-
import { WASI as __nodeWASI } from 'node:wasi'
|
|
9
|
-
import { Worker } from 'node:worker_threads'
|
|
10
|
-
import * as __nodeURL from 'node:url'
|
|
11
|
-
|
|
12
|
-
import { instantiateNapiModule as __emnapiInstantiateNapiModule } from '@emnapi/core'
|
|
13
|
-
import { getDefaultContext as __emnapiGetDefaultContext } from '@emnapi/runtime'
|
|
14
|
-
|
|
15
|
-
const __wasi = new __nodeWASI({
|
|
16
|
-
version: 'preview1',
|
|
17
|
-
env: process.env,
|
|
18
|
-
preopens: {
|
|
19
|
-
'/': __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..'),
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const __dirname = __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..')
|
|
24
|
-
|
|
25
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
26
|
-
|
|
27
|
-
const __sharedMemory = new WebAssembly.Memory({
|
|
28
|
-
initial: 1024,
|
|
29
|
-
maximum: 10240,
|
|
30
|
-
shared: true,
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = await __emnapiInstantiateNapiModule(__nodeFsPromises.readFile(__nodePath.join(__dirname, '${wasmFileName}.wasm')), {
|
|
34
|
-
context: __emnapiContext,
|
|
35
|
-
asyncWorkPoolSize: 4,
|
|
36
|
-
wasi: __wasi,
|
|
37
|
-
onCreateWorker() {
|
|
38
|
-
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
39
|
-
env: process.env,
|
|
40
|
-
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
41
|
-
})
|
|
42
|
-
},
|
|
43
|
-
overwriteImports(importObject) {
|
|
44
|
-
importObject.env = {
|
|
45
|
-
...importObject.env,
|
|
46
|
-
...importObject.napi,
|
|
47
|
-
...importObject.emnapi,
|
|
48
|
-
memory: __sharedMemory,
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
beforeInit({ instance }) {
|
|
52
|
-
__napi_rs_initialize_modules(instance)
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
57
|
-
${wasiRegisterFunctions
|
|
58
|
-
.map((name) => ` __napiInstance.exports['${name}']()`)
|
|
59
|
-
.join('\n')}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const binding = __napiModule.exports
|
|
63
|
-
`;
|
|
64
|
-
//# sourceMappingURL=load-wasi-template.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"load-wasi-template.js","sourceRoot":"","sources":["../../src/api/load-wasi-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,YAAoB,EACpB,qBAA+B,EAC/B,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iLAgC4K,YAAY;;;;;;;;;;;;;;;;;;;;;;;;EAwB3L,qBAAqB;KACpB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,6BAA6B,IAAI,MAAM,CAAC;KACtD,IAAI,CAAC,IAAI,CAAC;;;;CAIZ,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const WASI_WORKER_TEMPLATE = "import fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { parentPort, Worker } from \"node:worker_threads\";\n\nimport { instantiateNapiModuleSync, MessageHandler } from \"@emnapi/core\";\nimport { WASI } from \"@tybys/wasm-util\";\n\nconst require = createRequire(import.meta.url);\n\nif (parentPort) {\n parentPort.on(\"message\", (data) => {\n globalThis.onmessage({ data });\n });\n}\n\nObject.assign(globalThis, {\n self: globalThis,\n require,\n Worker,\n importScripts: function (f) {\n ;(0, eval)(fs.readFileSync(f, \"utf8\") + \"//# sourceURL=\" + f);\n },\n postMessage: function (msg) {\n if (parentPort) {\n parentPort.postMessage(msg);\n }\n },\n});\n\nconst handler = new MessageHandler({\n onLoad({ wasmModule, wasmMemory }) {\n const wasi = new WASI({ fs });\n\n return instantiateNapiModuleSync(wasmModule, {\n childThread: true,\n wasi,\n overwriteImports(importObject) {\n importObject.env = {\n ...importObject.env,\n ...importObject.napi,\n ...importObject.emnapi,\n memory: wasmMemory\n };\n },\n });\n },\n});\n\nglobalThis.onmessage = function (e) {\n handler.handle(e);\n};\n";
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { parentPort, Worker } from "node:worker_threads";
|
|
4
|
-
|
|
5
|
-
import { instantiateNapiModuleSync, MessageHandler } from "@emnapi/core";
|
|
6
|
-
import { WASI } from "@tybys/wasm-util";
|
|
7
|
-
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
|
|
10
|
-
if (parentPort) {
|
|
11
|
-
parentPort.on("message", (data) => {
|
|
12
|
-
globalThis.onmessage({ data });
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Object.assign(globalThis, {
|
|
17
|
-
self: globalThis,
|
|
18
|
-
require,
|
|
19
|
-
Worker,
|
|
20
|
-
importScripts: function (f) {
|
|
21
|
-
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
22
|
-
},
|
|
23
|
-
postMessage: function (msg) {
|
|
24
|
-
if (parentPort) {
|
|
25
|
-
parentPort.postMessage(msg);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const handler = new MessageHandler({
|
|
31
|
-
onLoad({ wasmModule, wasmMemory }) {
|
|
32
|
-
const wasi = new WASI({ fs });
|
|
33
|
-
|
|
34
|
-
return instantiateNapiModuleSync(wasmModule, {
|
|
35
|
-
childThread: true,
|
|
36
|
-
wasi,
|
|
37
|
-
overwriteImports(importObject) {
|
|
38
|
-
importObject.env = {
|
|
39
|
-
...importObject.env,
|
|
40
|
-
...importObject.napi,
|
|
41
|
-
...importObject.emnapi,
|
|
42
|
-
memory: wasmMemory
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
globalThis.onmessage = function (e) {
|
|
50
|
-
handler.handle(e);
|
|
51
|
-
};
|
|
52
|
-
`;
|
|
53
|
-
//# sourceMappingURL=wasi-worker-template.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wasi-worker-template.js","sourceRoot":"","sources":["../../src/api/wasi-worker-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDnC,CAAA"}
|
package/dist/utils/ci.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TargetTriple } from './target.js';
|
|
2
|
-
export declare const CIConfig: Partial<Record<TargetTriple, {
|
|
3
|
-
host: string;
|
|
4
|
-
build_image?: string;
|
|
5
|
-
build_setup?: string[];
|
|
6
|
-
test?: boolean;
|
|
7
|
-
test_image?: string;
|
|
8
|
-
test_setup?: string[];
|
|
9
|
-
yarn_cpu?: string;
|
|
10
|
-
yarn_libc?: string;
|
|
11
|
-
}>>;
|
package/dist/utils/ci.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
export const CIConfig = {
|
|
2
|
-
'x86_64-apple-darwin': {
|
|
3
|
-
host: 'macos-latest',
|
|
4
|
-
},
|
|
5
|
-
'x86_64-pc-windows-msvc': {
|
|
6
|
-
host: 'windows-latest',
|
|
7
|
-
},
|
|
8
|
-
'i686-pc-windows-msvc': {
|
|
9
|
-
host: 'windows-latest',
|
|
10
|
-
test: false,
|
|
11
|
-
},
|
|
12
|
-
'x86_64-unknown-linux-gnu': {
|
|
13
|
-
host: 'ubuntu-latest',
|
|
14
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian',
|
|
15
|
-
},
|
|
16
|
-
'x86_64-unknown-linux-musl': {
|
|
17
|
-
host: 'ubuntu-latest',
|
|
18
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
19
|
-
test_image: 'node:${{ matrix.node }}-alpine',
|
|
20
|
-
yarn_libc: 'musl',
|
|
21
|
-
},
|
|
22
|
-
'aarch64-apple-darwin': {
|
|
23
|
-
host: 'macos-latest',
|
|
24
|
-
build_setup: [
|
|
25
|
-
'sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*',
|
|
26
|
-
'export CC=$(xcrun -f clang)',
|
|
27
|
-
'export CXX=$(xcrun -f clang++)',
|
|
28
|
-
'export SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)',
|
|
29
|
-
'export CFLAGS="-isysroot $SDK_ROOT -isystem $SDK_ROOT"',
|
|
30
|
-
],
|
|
31
|
-
test: false,
|
|
32
|
-
},
|
|
33
|
-
'aarch64-unknown-linux-gnu': {
|
|
34
|
-
host: 'ubuntu-latest',
|
|
35
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64',
|
|
36
|
-
build_setup: [
|
|
37
|
-
'sudo apt-get update',
|
|
38
|
-
'sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y',
|
|
39
|
-
'export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu',
|
|
40
|
-
],
|
|
41
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}',
|
|
42
|
-
yarn_cpu: 'arm64',
|
|
43
|
-
},
|
|
44
|
-
'aarch64-unknown-linux-musl': {
|
|
45
|
-
host: 'ubuntu-latest',
|
|
46
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
47
|
-
build_setup: ['rustup target add aarch64-unknown-linux-musl'],
|
|
48
|
-
test_image: 'multiarch/alpine:aarch64-latest-stable',
|
|
49
|
-
test_setup: ['apk add nodejs npm yarn'],
|
|
50
|
-
yarn_cpu: 'arm64',
|
|
51
|
-
yarn_libc: 'musl',
|
|
52
|
-
},
|
|
53
|
-
'aarch64-pc-windows-msvc': {
|
|
54
|
-
host: 'windows-latest',
|
|
55
|
-
test: false,
|
|
56
|
-
},
|
|
57
|
-
'armv7-unknown-linux-gnueabihf': {
|
|
58
|
-
host: 'ubuntu-latest',
|
|
59
|
-
build_setup: [
|
|
60
|
-
'sudo apt-get update',
|
|
61
|
-
'sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y',
|
|
62
|
-
],
|
|
63
|
-
yarn_cpu: 'arm',
|
|
64
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}',
|
|
65
|
-
},
|
|
66
|
-
'aarch64-linux-android': {
|
|
67
|
-
host: 'ubuntu-latest',
|
|
68
|
-
build_setup: [
|
|
69
|
-
'export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
70
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
71
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"',
|
|
72
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
73
|
-
],
|
|
74
|
-
test: false,
|
|
75
|
-
},
|
|
76
|
-
'armv7-linux-androideabi': {
|
|
77
|
-
host: 'ubuntu-latest',
|
|
78
|
-
build_setup: [
|
|
79
|
-
'export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
80
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
81
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"',
|
|
82
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
83
|
-
],
|
|
84
|
-
test: false,
|
|
85
|
-
},
|
|
86
|
-
'riscv64gc-unknown-linux-gnu': {
|
|
87
|
-
host: 'ubuntu-latest',
|
|
88
|
-
build_setup: [
|
|
89
|
-
'sudo apt-get update',
|
|
90
|
-
'sudo apt-get install g++-riscv64-linux-gnu gcc-riscv64-linux-gnu -y',
|
|
91
|
-
],
|
|
92
|
-
// No official nodejs docker image for riscv64
|
|
93
|
-
test: false,
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
//# sourceMappingURL=ci.js.map
|
package/dist/utils/ci.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ci.js","sourceRoot":"","sources":["../../src/utils/ci.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,QAAQ,GAcjB;IACF,qBAAqB,EAAE;QACrB,IAAI,EAAE,cAAc;KACrB;IACD,wBAAwB,EAAE;QACxB,IAAI,EAAE,gBAAgB;KACvB;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,KAAK;KACZ;IACD,0BAA0B,EAAE;QAC1B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,gDAAgD;KAC9D;IACD,2BAA2B,EAAE;QAC3B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,gDAAgD;QAC7D,UAAU,EAAE,gCAAgC;QAC5C,SAAS,EAAE,MAAM;KAClB;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,cAAc;QACpB,WAAW,EAAE;YACX,wDAAwD;YACxD,6BAA6B;YAC7B,gCAAgC;YAChC,uDAAuD;YACvD,wDAAwD;SACzD;QACD,IAAI,EAAE,KAAK;KACZ;IACD,2BAA2B,EAAE;QAC3B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,wDAAwD;QACrE,WAAW,EAAE;YACX,qBAAqB;YACrB,qEAAqE;YACrE,oDAAoD;SACrD;QACD,UAAU,EAAE,2DAA2D;QACvE,QAAQ,EAAE,OAAO;KAClB;IACD,4BAA4B,EAAE;QAC5B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,gDAAgD;QAC7D,WAAW,EAAE,CAAC,8CAA8C,CAAC;QAC7D,UAAU,EAAE,wCAAwC;QACpD,UAAU,EAAE,CAAC,yBAAyB,CAAC;QACvC,QAAQ,EAAE,OAAO;QACjB,SAAS,EAAE,MAAM;KAClB;IACD,yBAAyB,EAAE;QACzB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,KAAK;KACZ;IACD,+BAA+B,EAAE;QAC/B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE;YACX,qBAAqB;YACrB,yEAAyE;SAC1E;QACD,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,yDAAyD;KACtE;IACD,uBAAuB,EAAE;QACvB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE;YACX,gJAAgJ;YAChJ,yGAAyG;YACzG,4GAA4G;YAC5G,qFAAqF;SACtF;QACD,IAAI,EAAE,KAAK;KACZ;IACD,yBAAyB,EAAE;QACzB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE;YACX,qJAAqJ;YACrJ,4GAA4G;YAC5G,+GAA+G;YAC/G,qFAAqF;SACtF;QACD,IAAI,EAAE,KAAK;KACZ;IACD,6BAA6B,EAAE;QAC7B,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE;YACX,qBAAqB;YACrB,qEAAqE;SACtE;QACD,8CAA8C;QAC9C,IAAI,EAAE,KAAK;KACZ;CACF,CAAA"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export const createWasiBinding = (
|
|
2
|
-
wasmFileName: string,
|
|
3
|
-
wasiRegisterFunctions: string[],
|
|
4
|
-
) => `/* eslint-disable */
|
|
5
|
-
/* prettier-ignore */
|
|
6
|
-
|
|
7
|
-
/* auto-generated by NAPI-RS */
|
|
8
|
-
|
|
9
|
-
import * as __nodeFsPromises from 'node:fs/promises'
|
|
10
|
-
import * as __nodePath from 'node:path'
|
|
11
|
-
import { WASI as __nodeWASI } from 'node:wasi'
|
|
12
|
-
import { Worker } from 'node:worker_threads'
|
|
13
|
-
import * as __nodeURL from 'node:url'
|
|
14
|
-
|
|
15
|
-
import { instantiateNapiModule as __emnapiInstantiateNapiModule } from '@emnapi/core'
|
|
16
|
-
import { getDefaultContext as __emnapiGetDefaultContext } from '@emnapi/runtime'
|
|
17
|
-
|
|
18
|
-
const __wasi = new __nodeWASI({
|
|
19
|
-
version: 'preview1',
|
|
20
|
-
env: process.env,
|
|
21
|
-
preopens: {
|
|
22
|
-
'/': __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..'),
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const __dirname = __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..')
|
|
27
|
-
|
|
28
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
29
|
-
|
|
30
|
-
const __sharedMemory = new WebAssembly.Memory({
|
|
31
|
-
initial: 1024,
|
|
32
|
-
maximum: 10240,
|
|
33
|
-
shared: true,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = await __emnapiInstantiateNapiModule(__nodeFsPromises.readFile(__nodePath.join(__dirname, '${wasmFileName}.wasm')), {
|
|
37
|
-
context: __emnapiContext,
|
|
38
|
-
asyncWorkPoolSize: 4,
|
|
39
|
-
wasi: __wasi,
|
|
40
|
-
onCreateWorker() {
|
|
41
|
-
return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
42
|
-
env: process.env,
|
|
43
|
-
execArgv: ['--experimental-wasi-unstable-preview1'],
|
|
44
|
-
})
|
|
45
|
-
},
|
|
46
|
-
overwriteImports(importObject) {
|
|
47
|
-
importObject.env = {
|
|
48
|
-
...importObject.env,
|
|
49
|
-
...importObject.napi,
|
|
50
|
-
...importObject.emnapi,
|
|
51
|
-
memory: __sharedMemory,
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
beforeInit({ instance }) {
|
|
55
|
-
__napi_rs_initialize_modules(instance)
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
function __napi_rs_initialize_modules(__napiInstance) {
|
|
60
|
-
${wasiRegisterFunctions
|
|
61
|
-
.map((name) => ` __napiInstance.exports['${name}']()`)
|
|
62
|
-
.join('\n')}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const binding = __napiModule.exports
|
|
66
|
-
`
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { parentPort, Worker } from "node:worker_threads";
|
|
4
|
-
|
|
5
|
-
import { instantiateNapiModuleSync, MessageHandler } from "@emnapi/core";
|
|
6
|
-
import { WASI } from "@tybys/wasm-util";
|
|
7
|
-
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
|
-
|
|
10
|
-
if (parentPort) {
|
|
11
|
-
parentPort.on("message", (data) => {
|
|
12
|
-
globalThis.onmessage({ data });
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
Object.assign(globalThis, {
|
|
17
|
-
self: globalThis,
|
|
18
|
-
require,
|
|
19
|
-
Worker,
|
|
20
|
-
importScripts: function (f) {
|
|
21
|
-
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
22
|
-
},
|
|
23
|
-
postMessage: function (msg) {
|
|
24
|
-
if (parentPort) {
|
|
25
|
-
parentPort.postMessage(msg);
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const handler = new MessageHandler({
|
|
31
|
-
onLoad({ wasmModule, wasmMemory }) {
|
|
32
|
-
const wasi = new WASI({ fs });
|
|
33
|
-
|
|
34
|
-
return instantiateNapiModuleSync(wasmModule, {
|
|
35
|
-
childThread: true,
|
|
36
|
-
wasi,
|
|
37
|
-
overwriteImports(importObject) {
|
|
38
|
-
importObject.env = {
|
|
39
|
-
...importObject.env,
|
|
40
|
-
...importObject.napi,
|
|
41
|
-
...importObject.emnapi,
|
|
42
|
-
memory: wasmMemory
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
globalThis.onmessage = function (e) {
|
|
50
|
-
handler.handle(e);
|
|
51
|
-
};
|
|
52
|
-
`
|