@napi-rs/cli 3.0.0-alpha.9 → 3.0.0-alpha.90

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 (163) hide show
  1. package/cli.mjs +1 -1
  2. package/dist/api/__tests__/new.spec.d.ts +1 -0
  3. package/dist/api/__tests__/new.spec.js +283 -0
  4. package/dist/api/__tests__/new.spec.js.map +1 -0
  5. package/dist/api/artifacts.js +28 -7
  6. package/dist/api/artifacts.js.map +1 -1
  7. package/dist/api/build.d.ts +1 -1
  8. package/dist/api/build.js +324 -115
  9. package/dist/api/build.js.map +1 -1
  10. package/dist/api/create-npm-dirs.js +46 -9
  11. package/dist/api/create-npm-dirs.js.map +1 -1
  12. package/dist/api/new.js +312 -107
  13. package/dist/api/new.js.map +1 -1
  14. package/dist/api/pre-publish.js +9 -7
  15. package/dist/api/pre-publish.js.map +1 -1
  16. package/dist/api/rename.js +74 -12
  17. package/dist/api/rename.js.map +1 -1
  18. package/dist/api/templates/cargo.toml.js +1 -0
  19. package/dist/api/templates/cargo.toml.js.map +1 -1
  20. package/dist/api/templates/ci-template.d.ts +3 -1
  21. package/dist/api/templates/ci-template.js +140 -125
  22. package/dist/api/templates/ci-template.js.map +1 -1
  23. package/dist/api/templates/ci.yml.d.ts +3 -1
  24. package/dist/api/templates/ci.yml.js +21 -5
  25. package/dist/api/templates/ci.yml.js.map +1 -1
  26. package/dist/api/templates/js-binding.d.ts +1 -0
  27. package/dist/api/templates/js-binding.js +142 -222
  28. package/dist/api/templates/js-binding.js.map +1 -1
  29. package/dist/api/templates/load-wasi-template.d.ts +2 -0
  30. package/dist/api/templates/load-wasi-template.js +168 -0
  31. package/dist/api/templates/load-wasi-template.js.map +1 -0
  32. package/dist/api/templates/package.json.d.ts +9 -2
  33. package/dist/api/templates/package.json.js +26 -4
  34. package/dist/api/templates/package.json.js.map +1 -1
  35. package/dist/api/templates/wasi-worker-template.d.ts +2 -0
  36. package/dist/api/templates/wasi-worker-template.js +122 -0
  37. package/dist/api/templates/wasi-worker-template.js.map +1 -0
  38. package/dist/api/universalize.js +5 -5
  39. package/dist/api/universalize.js.map +1 -1
  40. package/dist/api/version.js +2 -2
  41. package/dist/api/version.js.map +1 -1
  42. package/dist/commands/artifacts.js +2 -2
  43. package/dist/commands/artifacts.js.map +1 -1
  44. package/dist/commands/build.js +1 -1
  45. package/dist/commands/build.js.map +1 -1
  46. package/dist/commands/new.js +34 -34
  47. package/dist/commands/new.js.map +1 -1
  48. package/dist/def/artifacts.d.ts +21 -1
  49. package/dist/def/artifacts.js +10 -2
  50. package/dist/def/artifacts.js.map +1 -1
  51. package/dist/def/build.d.ts +149 -4
  52. package/dist/def/build.js +26 -4
  53. package/dist/def/build.js.map +1 -1
  54. package/dist/def/create-npm-dirs.d.ts +10 -0
  55. package/dist/def/create-npm-dirs.js +4 -0
  56. package/dist/def/create-npm-dirs.js.map +1 -1
  57. package/dist/def/new.d.ts +25 -7
  58. package/dist/def/new.js +11 -1
  59. package/dist/def/new.js.map +1 -1
  60. package/dist/def/pre-publish.d.ts +12 -2
  61. package/dist/def/pre-publish.js +7 -3
  62. package/dist/def/pre-publish.js.map +1 -1
  63. package/dist/def/rename.d.ts +16 -6
  64. package/dist/def/rename.js +5 -1
  65. package/dist/def/rename.js.map +1 -1
  66. package/dist/def/universalize.d.ts +10 -0
  67. package/dist/def/universalize.js +4 -0
  68. package/dist/def/universalize.js.map +1 -1
  69. package/dist/def/version.d.ts +10 -0
  70. package/dist/def/version.js +4 -0
  71. package/dist/def/version.js.map +1 -1
  72. package/dist/index.cjs +8743 -14849
  73. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  74. package/dist/utils/__tests__/config.spec.js +63 -0
  75. package/dist/utils/__tests__/config.spec.js.map +1 -0
  76. package/dist/utils/cargo.js +2 -2
  77. package/dist/utils/cargo.js.map +1 -1
  78. package/dist/utils/config.d.ts +48 -4
  79. package/dist/utils/config.js +36 -4
  80. package/dist/utils/config.js.map +1 -1
  81. package/dist/utils/index.d.ts +1 -1
  82. package/dist/utils/index.js +1 -1
  83. package/dist/utils/index.js.map +1 -1
  84. package/dist/utils/log.js +1 -1
  85. package/dist/utils/log.js.map +1 -1
  86. package/dist/utils/metadata.d.ts +13 -1
  87. package/dist/utils/metadata.js +31 -11
  88. package/dist/utils/metadata.js.map +1 -1
  89. package/dist/utils/misc.d.ts +3 -3
  90. package/dist/utils/misc.js +13 -11
  91. package/dist/utils/misc.js.map +1 -1
  92. package/dist/utils/read-config.d.ts +7 -0
  93. package/dist/utils/read-config.js +8 -0
  94. package/dist/utils/read-config.js.map +1 -0
  95. package/dist/utils/target.d.ts +7 -5
  96. package/dist/utils/target.js +17 -3
  97. package/dist/utils/target.js.map +1 -1
  98. package/dist/utils/typegen.d.ts +1 -1
  99. package/dist/utils/typegen.js +63 -32
  100. package/dist/utils/typegen.js.map +1 -1
  101. package/dist/utils/version.d.ts +2 -1
  102. package/dist/utils/version.js +10 -8
  103. package/dist/utils/version.js.map +1 -1
  104. package/package.json +34 -32
  105. package/src/api/__tests__/new.spec.ts +429 -0
  106. package/src/api/artifacts.ts +81 -9
  107. package/src/api/build.ts +498 -149
  108. package/src/api/create-npm-dirs.ts +57 -9
  109. package/src/api/new.ts +389 -122
  110. package/src/api/pre-publish.ts +13 -7
  111. package/src/api/rename.ts +103 -17
  112. package/src/api/templates/cargo.toml.ts +1 -0
  113. package/src/api/templates/ci-template.ts +150 -125
  114. package/src/api/templates/ci.yml.ts +27 -6
  115. package/src/api/templates/js-binding.ts +148 -220
  116. package/src/api/templates/load-wasi-template.ts +182 -0
  117. package/src/api/templates/package.json.ts +47 -5
  118. package/src/api/templates/wasi-worker-template.ts +122 -0
  119. package/src/api/universalize.ts +13 -8
  120. package/src/api/version.ts +5 -2
  121. package/src/commands/artifacts.ts +2 -2
  122. package/src/commands/build.ts +1 -1
  123. package/src/commands/new.ts +46 -45
  124. package/src/def/artifacts.ts +22 -3
  125. package/src/def/build.ts +55 -8
  126. package/src/def/create-npm-dirs.ts +9 -0
  127. package/src/def/new.ts +28 -3
  128. package/src/def/pre-publish.ts +12 -3
  129. package/src/def/rename.ts +11 -2
  130. package/src/def/universalize.ts +9 -0
  131. package/src/def/version.ts +9 -0
  132. package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
  133. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  134. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  135. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +28 -0
  136. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  137. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +316 -332
  138. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  139. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +8 -7
  140. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  141. package/src/utils/__tests__/config.spec.ts +81 -0
  142. package/src/utils/cargo.ts +2 -2
  143. package/src/utils/config.ts +110 -9
  144. package/src/utils/index.ts +1 -1
  145. package/src/utils/log.ts +1 -1
  146. package/src/utils/metadata.ts +52 -14
  147. package/src/utils/misc.ts +21 -12
  148. package/src/utils/read-config.ts +20 -0
  149. package/src/utils/target.ts +22 -4
  150. package/src/utils/typegen.ts +87 -52
  151. package/src/utils/version.ts +10 -8
  152. package/dist/api/load-wasi-template.d.ts +0 -1
  153. package/dist/api/load-wasi-template.js +0 -64
  154. package/dist/api/load-wasi-template.js.map +0 -1
  155. package/dist/api/wasi-worker-template.d.ts +0 -1
  156. package/dist/api/wasi-worker-template.js +0 -53
  157. package/dist/api/wasi-worker-template.js.map +0 -1
  158. package/dist/utils/ci.d.ts +0 -11
  159. package/dist/utils/ci.js +0 -96
  160. package/dist/utils/ci.js.map +0 -1
  161. package/src/api/load-wasi-template.ts +0 -66
  162. package/src/api/wasi-worker-template.ts +0 -52
  163. package/src/utils/ci.ts +0 -111
@@ -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',
@@ -29,6 +31,7 @@ function prettyPrint(
29
31
  line: TypeDefLine,
30
32
  constEnum: boolean,
31
33
  ident: number,
34
+ ambient = false,
32
35
  ): string {
33
36
  let s = line.js_doc ?? ''
34
37
  switch (line.kind) {
@@ -36,18 +39,34 @@ function prettyPrint(
36
39
  s += `export interface ${line.name} {\n${line.def}\n}`
37
40
  break
38
41
 
42
+ case TypeDefKind.Type:
43
+ s += `export type ${line.name} = \n${line.def}`
44
+ break
45
+
39
46
  case TypeDefKind.Enum:
40
47
  const enumName = constEnum ? 'const enum' : 'enum'
41
- s += `export ${enumName} ${line.name} {\n${line.def}\n}`
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
+ }
42
57
  break
43
58
 
44
59
  case TypeDefKind.Struct:
45
- s += `export class ${line.name} {\n${line.def}\n}`
60
+ s += `${exportDeclare(ambient)} class ${line.name} {\n${line.def}\n}`
46
61
  if (line.original_name && line.original_name !== line.name) {
47
62
  s += `\nexport type ${line.original_name} = ${line.name}`
48
63
  }
49
64
  break
50
65
 
66
+ case TypeDefKind.Fn:
67
+ s += `${exportDeclare(ambient)} ${line.def}`
68
+ break
69
+
51
70
  default:
52
71
  s += line.def
53
72
  }
@@ -55,79 +74,84 @@ function prettyPrint(
55
74
  return correctStringIdent(s, ident)
56
75
  }
57
76
 
77
+ function exportDeclare(ambient: boolean): string {
78
+ if (ambient) {
79
+ return 'export'
80
+ }
81
+
82
+ return 'export declare'
83
+ }
84
+
58
85
  export async function processTypeDef(
59
86
  intermediateTypeFile: string,
60
87
  constEnum: boolean,
61
- header?: string,
62
88
  ) {
63
89
  const exports: string[] = []
64
90
  const defs = await readIntermediateTypeFile(intermediateTypeFile)
65
91
  const groupedDefs = preprocessTypeDef(defs)
66
92
 
67
- header = header ? header + '\n' : ''
68
- let dts = ''
69
-
70
- sortBy(Array.from(groupedDefs), ([namespace]) => namespace).forEach(
71
- ([namespace, defs]) => {
72
- if (namespace === TOP_LEVEL_NAMESPACE) {
73
- for (const def of defs) {
74
- dts += prettyPrint(def, constEnum, 0) + '\n\n'
75
- switch (def.kind) {
76
- case TypeDefKind.Const:
77
- case TypeDefKind.Enum:
78
- case TypeDefKind.Fn:
79
- case TypeDefKind.Struct: {
80
- exports.push(def.name)
81
- if (def.original_name && def.original_name !== def.name) {
82
- exports.push(def.original_name)
93
+ const dts =
94
+ sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
95
+ .map(([namespace, defs]) => {
96
+ if (namespace === TOP_LEVEL_NAMESPACE) {
97
+ return defs
98
+ .map((def) => {
99
+ switch (def.kind) {
100
+ case TypeDefKind.Const:
101
+ case TypeDefKind.Enum:
102
+ case TypeDefKind.StringEnum:
103
+ case TypeDefKind.Fn:
104
+ case TypeDefKind.Struct: {
105
+ exports.push(def.name)
106
+ if (def.original_name && def.original_name !== def.name) {
107
+ exports.push(def.original_name)
108
+ }
109
+ break
110
+ }
111
+ default:
112
+ break
83
113
  }
84
- break
85
- }
86
- default:
87
- break
114
+ return prettyPrint(def, constEnum, 0)
115
+ })
116
+ .join('\n\n')
117
+ } else {
118
+ exports.push(namespace)
119
+ let declaration = ''
120
+ declaration += `export declare namespace ${namespace} {\n`
121
+ for (const def of defs) {
122
+ declaration += prettyPrint(def, constEnum, 2, true) + '\n'
88
123
  }
124
+ declaration += '}'
125
+ return declaration
89
126
  }
90
- } else {
91
- exports.push(namespace)
92
- dts += `export namespace ${namespace} {\n`
93
- for (const def of defs) {
94
- dts += prettyPrint(def, constEnum, 2) + '\n'
95
- }
96
- dts += '}\n\n'
97
- }
98
- },
99
- )
100
-
101
- if (dts.indexOf('ExternalObject<') > -1) {
102
- header += `
103
- export class ExternalObject<T> {
104
- readonly '': {
105
- readonly '': unique symbol
106
- [K: symbol]: T
107
- }
108
- }
109
- `
110
- }
127
+ })
128
+ .join('\n\n') + '\n'
111
129
 
112
130
  return {
113
- dts: header + dts,
131
+ dts,
114
132
  exports,
115
133
  }
116
134
  }
117
135
 
118
136
  async function readIntermediateTypeFile(file: string) {
119
137
  const content = await readFileAsync(file, 'utf8')
138
+
120
139
  const defs = content
121
140
  .split('\n')
122
141
  .filter(Boolean)
123
142
  .map((line) => {
124
143
  line = line.trim()
125
- if (!line.startsWith('{')) {
126
- // crateName:{ "def": "", ... }
127
- const start = line.indexOf(':') + 1
128
- line = line.slice(start)
144
+ const parsed = JSON.parse(line) as TypeDefLine
145
+ // Convert escaped newlines back to actual newlines in js_doc fields
146
+ if (parsed.js_doc) {
147
+ parsed.js_doc = parsed.js_doc.replace(/\\n/g, '\n')
148
+ }
149
+ // Convert escaped newlines to actual newlines in def fields for struct/class/interface/type types
150
+ // where \n represents method/field separators that should be actual newlines
151
+ if (parsed.def) {
152
+ parsed.def = parsed.def.replace(/\\n/g, '\n')
129
153
  }
130
- return JSON.parse(line) as TypeDefLine
154
+ return parsed
131
155
  })
132
156
 
133
157
  // move all `struct` def to the very top
@@ -170,6 +194,10 @@ function preprocessTypeDef(defs: TypeDefLine[]): Map<string, TypeDefLine[]> {
170
194
  }
171
195
 
172
196
  classDef.def += def.def
197
+ // Convert any remaining \n sequences in the merged def to actual newlines
198
+ if (classDef.def) {
199
+ classDef.def = classDef.def.replace(/\\n/g, '\n')
200
+ }
173
201
  }
174
202
  } else {
175
203
  group.push(def)
@@ -192,13 +220,20 @@ export function correctStringIdent(src: string, ident: number): string {
192
220
  const isInMultilineComment = line.startsWith('*')
193
221
  const isClosingBracket = line.endsWith('}')
194
222
  const isOpeningBracket = line.endsWith('{')
223
+ const isTypeDeclaration = line.endsWith('=')
224
+ const isTypeVariant = line.startsWith('|')
195
225
 
196
226
  let rightIndent = ident
197
- if (isOpeningBracket && !isInMultilineComment) {
227
+ if ((isOpeningBracket || isTypeDeclaration) && !isInMultilineComment) {
198
228
  bracketDepth += 1
199
229
  rightIndent += (bracketDepth - 1) * 2
200
230
  } else {
201
- if (isClosingBracket && bracketDepth > 0 && !isInMultilineComment) {
231
+ if (
232
+ isClosingBracket &&
233
+ bracketDepth > 0 &&
234
+ !isInMultilineComment &&
235
+ !isTypeVariant
236
+ ) {
202
237
  bracketDepth -= 1
203
238
  }
204
239
  rightIndent += bracketDepth * 2
@@ -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 supportness from node version directly.
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"}
@@ -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
@@ -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
- `