@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.
Files changed (161) hide show
  1. package/cli.mjs +1 -1
  2. package/dist/api/artifacts.js +28 -7
  3. package/dist/api/artifacts.js.map +1 -1
  4. package/dist/api/build.js +310 -65
  5. package/dist/api/build.js.map +1 -1
  6. package/dist/api/create-npm-dirs.js +46 -9
  7. package/dist/api/create-npm-dirs.js.map +1 -1
  8. package/dist/api/new.js +57 -20
  9. package/dist/api/new.js.map +1 -1
  10. package/dist/api/pre-publish.js +9 -7
  11. package/dist/api/pre-publish.js.map +1 -1
  12. package/dist/api/rename.js +9 -1
  13. package/dist/api/rename.js.map +1 -1
  14. package/dist/api/templates/cargo.toml.js +1 -0
  15. package/dist/api/templates/cargo.toml.js.map +1 -1
  16. package/dist/api/templates/ci-template.d.ts +3 -1
  17. package/dist/api/templates/ci-template.js +140 -125
  18. package/dist/api/templates/ci-template.js.map +1 -1
  19. package/dist/api/templates/ci.yml.d.ts +3 -1
  20. package/dist/api/templates/ci.yml.js +21 -5
  21. package/dist/api/templates/ci.yml.js.map +1 -1
  22. package/dist/api/templates/js-binding.d.ts +1 -0
  23. package/dist/api/templates/js-binding.js +141 -222
  24. package/dist/api/templates/js-binding.js.map +1 -1
  25. package/dist/api/templates/lib.rs.js +1 -4
  26. package/dist/api/templates/lib.rs.js.map +1 -1
  27. package/dist/api/templates/load-wasi-template.d.ts +2 -0
  28. package/dist/api/templates/load-wasi-template.js +168 -0
  29. package/dist/api/templates/load-wasi-template.js.map +1 -0
  30. package/dist/api/templates/package.json.d.ts +9 -2
  31. package/dist/api/templates/package.json.js +26 -4
  32. package/dist/api/templates/package.json.js.map +1 -1
  33. package/dist/api/templates/wasi-worker-template.d.ts +2 -0
  34. package/dist/api/templates/wasi-worker-template.js +122 -0
  35. package/dist/api/templates/wasi-worker-template.js.map +1 -0
  36. package/dist/api/universalize.js +5 -5
  37. package/dist/api/universalize.js.map +1 -1
  38. package/dist/api/version.js +2 -2
  39. package/dist/api/version.js.map +1 -1
  40. package/dist/commands/artifacts.js +2 -2
  41. package/dist/commands/artifacts.js.map +1 -1
  42. package/dist/commands/build.js +1 -1
  43. package/dist/commands/build.js.map +1 -1
  44. package/dist/commands/new.js +34 -34
  45. package/dist/commands/new.js.map +1 -1
  46. package/dist/def/artifacts.d.ts +21 -1
  47. package/dist/def/artifacts.js +10 -2
  48. package/dist/def/artifacts.js.map +1 -1
  49. package/dist/def/build.d.ts +155 -4
  50. package/dist/def/build.js +30 -4
  51. package/dist/def/build.js.map +1 -1
  52. package/dist/def/create-npm-dirs.d.ts +10 -0
  53. package/dist/def/create-npm-dirs.js +4 -0
  54. package/dist/def/create-npm-dirs.js.map +1 -1
  55. package/dist/def/new.d.ts +25 -7
  56. package/dist/def/new.js +11 -1
  57. package/dist/def/new.js.map +1 -1
  58. package/dist/def/pre-publish.d.ts +12 -2
  59. package/dist/def/pre-publish.js +7 -3
  60. package/dist/def/pre-publish.js.map +1 -1
  61. package/dist/def/rename.d.ts +16 -6
  62. package/dist/def/rename.js +5 -1
  63. package/dist/def/rename.js.map +1 -1
  64. package/dist/def/universalize.d.ts +10 -0
  65. package/dist/def/universalize.js +4 -0
  66. package/dist/def/universalize.js.map +1 -1
  67. package/dist/def/version.d.ts +10 -0
  68. package/dist/def/version.js +4 -0
  69. package/dist/def/version.js.map +1 -1
  70. package/dist/index.cjs +7596 -13754
  71. package/dist/index.d.ts +1 -0
  72. package/dist/index.js +1 -0
  73. package/dist/index.js.map +1 -1
  74. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  75. package/dist/utils/__tests__/config.spec.js +63 -0
  76. package/dist/utils/__tests__/config.spec.js.map +1 -0
  77. package/dist/utils/__tests__/typegen.spec.js +8 -4
  78. package/dist/utils/__tests__/typegen.spec.js.map +1 -1
  79. package/dist/utils/cargo.js +2 -2
  80. package/dist/utils/cargo.js.map +1 -1
  81. package/dist/utils/config.d.ts +52 -4
  82. package/dist/utils/config.js +37 -5
  83. package/dist/utils/config.js.map +1 -1
  84. package/dist/utils/index.d.ts +0 -1
  85. package/dist/utils/index.js +0 -1
  86. package/dist/utils/index.js.map +1 -1
  87. package/dist/utils/metadata.d.ts +13 -1
  88. package/dist/utils/metadata.js +31 -11
  89. package/dist/utils/metadata.js.map +1 -1
  90. package/dist/utils/misc.d.ts +1 -2
  91. package/dist/utils/misc.js +3 -3
  92. package/dist/utils/misc.js.map +1 -1
  93. package/dist/utils/target.d.ts +7 -5
  94. package/dist/utils/target.js +17 -3
  95. package/dist/utils/target.js.map +1 -1
  96. package/dist/utils/typegen.d.ts +1 -1
  97. package/dist/utils/typegen.js +55 -20
  98. package/dist/utils/typegen.js.map +1 -1
  99. package/dist/utils/version.d.ts +2 -1
  100. package/dist/utils/version.js +10 -8
  101. package/dist/utils/version.js.map +1 -1
  102. package/package.json +27 -26
  103. package/src/api/artifacts.ts +81 -9
  104. package/src/api/build.ts +468 -88
  105. package/src/api/create-npm-dirs.ts +57 -9
  106. package/src/api/new.ts +89 -31
  107. package/src/api/pre-publish.ts +13 -7
  108. package/src/api/rename.ts +10 -1
  109. package/src/api/templates/cargo.toml.ts +1 -0
  110. package/src/api/templates/ci-template.ts +150 -125
  111. package/src/api/templates/ci.yml.ts +27 -6
  112. package/src/api/templates/js-binding.ts +147 -220
  113. package/src/api/templates/lib.rs.ts +1 -4
  114. package/src/api/templates/load-wasi-template.ts +182 -0
  115. package/src/api/templates/package.json.ts +47 -5
  116. package/src/api/templates/wasi-worker-template.ts +122 -0
  117. package/src/api/universalize.ts +13 -8
  118. package/src/api/version.ts +5 -2
  119. package/src/commands/artifacts.ts +2 -2
  120. package/src/commands/build.ts +1 -1
  121. package/src/commands/new.ts +46 -45
  122. package/src/def/artifacts.ts +22 -3
  123. package/src/def/build.ts +64 -8
  124. package/src/def/create-npm-dirs.ts +9 -0
  125. package/src/def/new.ts +28 -3
  126. package/src/def/pre-publish.ts +12 -3
  127. package/src/def/rename.ts +11 -2
  128. package/src/def/universalize.ts +9 -0
  129. package/src/def/version.ts +9 -0
  130. package/src/index.ts +2 -0
  131. package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
  132. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  133. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  134. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +28 -0
  135. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  136. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +711 -158
  137. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  138. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +8 -7
  139. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  140. package/src/utils/__tests__/config.spec.ts +81 -0
  141. package/src/utils/__tests__/typegen.spec.ts +18 -3
  142. package/src/utils/cargo.ts +2 -2
  143. package/src/utils/config.ts +116 -10
  144. package/src/utils/index.ts +0 -1
  145. package/src/utils/metadata.ts +52 -14
  146. package/src/utils/misc.ts +11 -3
  147. package/src/utils/target.ts +22 -4
  148. package/src/utils/typegen.ts +98 -49
  149. package/src/utils/version.ts +10 -8
  150. package/dist/api/load-wasi-template.d.ts +0 -1
  151. package/dist/api/load-wasi-template.js +0 -64
  152. package/dist/api/load-wasi-template.js.map +0 -1
  153. package/dist/api/wasi-worker-template.d.ts +0 -1
  154. package/dist/api/wasi-worker-template.js +0 -53
  155. package/dist/api/wasi-worker-template.js.map +0 -1
  156. package/dist/utils/ci.d.ts +0 -11
  157. package/dist/utils/ci.js +0 -96
  158. package/dist/utils/ci.js.map +0 -1
  159. package/src/api/load-wasi-template.ts +0 -66
  160. package/src/api/wasi-worker-template.ts +0 -52
  161. package/src/utils/ci.ts +0 -111
@@ -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(line: TypeDefLine, ident: number): string {
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
- s += `export const enum ${line.name} {\n${line.def}\n}`
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 += `export class ${line.name} {\n${line.def}\n}`
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 ? header + '\n' : ''
62
- let dts = ''
63
-
64
- sortBy(Array.from(groupedDefs), ([namespace]) => namespace).forEach(
65
- ([namespace, defs]) => {
66
- if (namespace === TOP_LEVEL_NAMESPACE) {
67
- for (const def of defs) {
68
- dts += prettyPrint(def, 0) + '\n\n'
69
- switch (def.kind) {
70
- case TypeDefKind.Const:
71
- case TypeDefKind.Enum:
72
- case TypeDefKind.Fn:
73
- case TypeDefKind.Struct: {
74
- exports.push(def.name)
75
- if (def.original_name && def.original_name !== def.name) {
76
- exports.push(def.original_name)
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
- break
79
- }
80
- default:
81
- break
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
- } else {
85
- exports.push(namespace)
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 = content
115
- .split('\n')
116
- .filter(Boolean)
117
- .map((line) => {
118
- line = line.trim()
119
- if (!line.startsWith('{')) {
120
- // crateName:{ "def": "", ... }
121
- const start = line.indexOf(':') + 1
122
- line = line.slice(start)
123
- }
124
- return JSON.parse(line) as TypeDefLine
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 (isClosingBracket && bracketDepth > 0 && !isInMultilineComment) {
239
+ if (
240
+ isClosingBracket &&
241
+ bracketDepth > 0 &&
242
+ !isInMultilineComment &&
243
+ !isTypeVariant
244
+ ) {
196
245
  bracketDepth -= 1
197
246
  }
198
247
  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
- `