@napi-rs/cli 3.0.0-alpha.44 → 3.0.0-alpha.45

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.
@@ -1,2 +1,2 @@
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, WASI } from \"@napi-rs/wasm-runtime\";\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
+ export declare const WASI_WORKER_TEMPLATE = "import fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { WASI } from \"node:wasi\";\nimport { parentPort, Worker } from \"node:worker_threads\";\n\nconst require = createRequire(import.meta.url);\n\nconst { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require(\"@napi-rs/wasm-runtime\");\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 emnapiContext = getDefaultContext()\n\nconst handler = new MessageHandler({\n onLoad({ wasmModule, wasmMemory }) {\n const wasi = new WASI({\n version: 'preview1',\n env: process.env,\n preopens: {\n '/': '/',\n },\n });\n\n return instantiateNapiModuleSync(wasmModule, {\n childThread: true,\n wasi,\n context: emnapiContext,\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";
2
2
  export declare const WASI_WORKER_BROWSER_TEMPLATE = "import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'\nimport { Volume, createFsFromVolume } from '@napi-rs/wasm-runtime/fs'\n\nconst fs = createFsFromVolume(\n Volume.fromJSON({\n '/': null,\n }),\n)\n\nconst handler = new MessageHandler({\n onLoad({ wasmModule, wasmMemory }) {\n const wasi = new WASI({\n fs,\n print: function () {\n // eslint-disable-next-line no-console\n console.log.apply(console, arguments)\n },\n printErr: function() {\n // eslint-disable-next-line no-console\n console.error.apply(console, arguments)\n },\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,11 +1,12 @@
1
1
  export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
2
2
  import { createRequire } from "node:module";
3
+ import { WASI } from "node:wasi";
3
4
  import { parentPort, Worker } from "node:worker_threads";
4
5
 
5
- import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
6
-
7
6
  const require = createRequire(import.meta.url);
8
7
 
8
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9
+
9
10
  if (parentPort) {
10
11
  parentPort.on("message", (data) => {
11
12
  globalThis.onmessage({ data });
@@ -26,13 +27,22 @@ Object.assign(globalThis, {
26
27
  },
27
28
  });
28
29
 
30
+ const emnapiContext = getDefaultContext()
31
+
29
32
  const handler = new MessageHandler({
30
33
  onLoad({ wasmModule, wasmMemory }) {
31
- const wasi = new WASI({ fs });
34
+ const wasi = new WASI({
35
+ version: 'preview1',
36
+ env: process.env,
37
+ preopens: {
38
+ '/': '/',
39
+ },
40
+ });
32
41
 
33
42
  return instantiateNapiModuleSync(wasmModule, {
34
43
  childThread: true,
35
44
  wasi,
45
+ context: emnapiContext,
36
46
  overwriteImports(importObject) {
37
47
  importObject.env = {
38
48
  ...importObject.env,
@@ -1 +1 @@
1
- {"version":3,"file":"wasi-worker-template.js","sourceRoot":"","sources":["../../../src/api/templates/wasi-worker-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDnC,CAAA;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC3C,CAAA"}
1
+ {"version":3,"file":"wasi-worker-template.js","sourceRoot":"","sources":["../../../src/api/templates/wasi-worker-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DnC,CAAA;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwC3C,CAAA"}
package/dist/index.cjs CHANGED
@@ -17219,12 +17219,13 @@ ${wasiRegisterFunctions.map((name) => ` __napiInstance.exports['${name}']?.()`)
17219
17219
  // dist/api/templates/wasi-worker-template.js
17220
17220
  var WASI_WORKER_TEMPLATE = `import fs from "node:fs";
17221
17221
  import { createRequire } from "node:module";
17222
+ import { WASI } from "node:wasi";
17222
17223
  import { parentPort, Worker } from "node:worker_threads";
17223
17224
 
17224
- import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
17225
-
17226
17225
  const require = createRequire(import.meta.url);
17227
17226
 
17227
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
17228
+
17228
17229
  if (parentPort) {
17229
17230
  parentPort.on("message", (data) => {
17230
17231
  globalThis.onmessage({ data });
@@ -17245,13 +17246,22 @@ Object.assign(globalThis, {
17245
17246
  },
17246
17247
  });
17247
17248
 
17249
+ const emnapiContext = getDefaultContext()
17250
+
17248
17251
  const handler = new MessageHandler({
17249
17252
  onLoad({ wasmModule, wasmMemory }) {
17250
- const wasi = new WASI({ fs });
17253
+ const wasi = new WASI({
17254
+ version: 'preview1',
17255
+ env: process.env,
17256
+ preopens: {
17257
+ '/': '/',
17258
+ },
17259
+ });
17251
17260
 
17252
17261
  return instantiateNapiModuleSync(wasmModule, {
17253
17262
  childThread: true,
17254
17263
  wasi,
17264
+ context: emnapiContext,
17255
17265
  overwriteImports(importObject) {
17256
17266
  importObject.env = {
17257
17267
  ...importObject.env,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/cli",
3
- "version": "3.0.0-alpha.44",
3
+ "version": "3.0.0-alpha.45",
4
4
  "description": "Cli tools for napi-rs",
5
5
  "author": "LongYinan <lynweklm@gmail.com>",
6
6
  "homepage": "https://github.com/napi-rs/napi-rs",
@@ -127,5 +127,5 @@
127
127
  "**/__tests__/**/*.spec.ts"
128
128
  ]
129
129
  },
130
- "gitHead": "35b9637151a91471976d04937bbaa49a9690130b"
130
+ "gitHead": "f5b685473117903f448888a7deda9fe5d7435aeb"
131
131
  }
@@ -1,11 +1,12 @@
1
1
  export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
2
2
  import { createRequire } from "node:module";
3
+ import { WASI } from "node:wasi";
3
4
  import { parentPort, Worker } from "node:worker_threads";
4
5
 
5
- import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
6
-
7
6
  const require = createRequire(import.meta.url);
8
7
 
8
+ const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9
+
9
10
  if (parentPort) {
10
11
  parentPort.on("message", (data) => {
11
12
  globalThis.onmessage({ data });
@@ -26,13 +27,22 @@ Object.assign(globalThis, {
26
27
  },
27
28
  });
28
29
 
30
+ const emnapiContext = getDefaultContext()
31
+
29
32
  const handler = new MessageHandler({
30
33
  onLoad({ wasmModule, wasmMemory }) {
31
- const wasi = new WASI({ fs });
34
+ const wasi = new WASI({
35
+ version: 'preview1',
36
+ env: process.env,
37
+ preopens: {
38
+ '/': '/',
39
+ },
40
+ });
32
41
 
33
42
  return instantiateNapiModuleSync(wasmModule, {
34
43
  childThread: true,
35
44
  wasi,
45
+ context: emnapiContext,
36
46
  overwriteImports(importObject) {
37
47
  importObject.env = {
38
48
  ...importObject.env,