@oxc-node/core-wasm32-wasi 0.0.35 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,25 +3,22 @@ import {
3
3
  getDefaultContext as __emnapiGetDefaultContext,
4
4
  instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
5
5
  WASI as __WASI,
6
- } from '@napi-rs/wasm-runtime'
7
-
8
-
6
+ } from "@napi-rs/wasm-runtime";
9
7
 
10
8
  const __wasi = new __WASI({
11
- version: 'preview1',
12
- })
13
-
14
- const __wasmUrl = new URL('./oxc-node.wasm32-wasi.wasm', import.meta.url).href
15
- const __emnapiContext = __emnapiGetDefaultContext()
9
+ version: "preview1",
10
+ });
16
11
 
12
+ const __wasmUrl = new URL("./oxc-node.wasm32-wasi.wasm", import.meta.url).href;
13
+ const __emnapiContext = __emnapiGetDefaultContext();
17
14
 
18
15
  const __sharedMemory = new WebAssembly.Memory({
19
16
  initial: 16384,
20
17
  maximum: 65536,
21
18
  shared: true,
22
- })
19
+ });
23
20
 
24
- const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
21
+ const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer());
25
22
 
26
23
  const {
27
24
  instance: __napiInstance,
@@ -32,11 +29,11 @@ const {
32
29
  asyncWorkPoolSize: 4,
33
30
  wasi: __wasi,
34
31
  onCreateWorker() {
35
- const worker = new Worker(new URL('@oxc-node/core-wasm32-wasi/wasi-worker-browser.mjs', import.meta.url), {
36
- type: 'module',
37
- })
32
+ const worker = new Worker(new URL("./wasi-worker-browser.mjs", import.meta.url), {
33
+ type: "module",
34
+ });
38
35
 
39
- return worker
36
+ return worker;
40
37
  },
41
38
  overwriteImports(importObject) {
42
39
  importObject.env = {
@@ -44,22 +41,22 @@ const {
44
41
  ...importObject.napi,
45
42
  ...importObject.emnapi,
46
43
  memory: __sharedMemory,
47
- }
48
- return importObject
44
+ };
45
+ return importObject;
49
46
  },
50
47
  beforeInit({ instance }) {
51
48
  for (const name of Object.keys(instance.exports)) {
52
- if (name.startsWith('__napi_register__')) {
53
- instance.exports[name]()
49
+ if (name.startsWith("__napi_register__")) {
50
+ instance.exports[name]();
54
51
  }
55
52
  }
56
53
  },
57
- })
58
- export default __napiModule.exports
59
- export const Output = __napiModule.exports.Output
60
- export const OxcTransformer = __napiModule.exports.OxcTransformer
61
- export const createResolve = __napiModule.exports.createResolve
62
- export const initTracing = __napiModule.exports.initTracing
63
- export const load = __napiModule.exports.load
64
- export const transform = __napiModule.exports.transform
65
- export const transformAsync = __napiModule.exports.transformAsync
54
+ });
55
+ export default __napiModule.exports;
56
+ export const Output = __napiModule.exports.Output;
57
+ export const OxcTransformer = __napiModule.exports.OxcTransformer;
58
+ export const createResolve = __napiModule.exports.createResolve;
59
+ export const initTracing = __napiModule.exports.initTracing;
60
+ export const load = __napiModule.exports.load;
61
+ export const transform = __napiModule.exports.transform;
62
+ export const transformAsync = __napiModule.exports.transformAsync;
package/oxc-node.wasi.cjs CHANGED
@@ -4,67 +4,75 @@
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
6
  const __nodeFs = require('node:fs')
7
- const __nodePath = require('node:path')
8
- const { WASI: __nodeWASI } = require('node:wasi')
9
- const { Worker } = require('node:worker_threads')
7
+ const __nodePath = require("node:path");
8
+ const { WASI: __nodeWASI } = require("node:wasi");
9
+ const { Worker } = require("node:worker_threads");
10
10
 
11
11
  const {
12
12
  createOnMessage: __wasmCreateOnMessageForFsProxy,
13
13
  getDefaultContext: __emnapiGetDefaultContext,
14
14
  instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
15
- } = require('@napi-rs/wasm-runtime')
15
+ } = require("@napi-rs/wasm-runtime");
16
16
 
17
- const __rootDir = __nodePath.parse(process.cwd()).root
17
+ const __rootDir = __nodePath.parse(process.cwd()).root;
18
18
 
19
19
  const __wasi = new __nodeWASI({
20
- version: 'preview1',
20
+ version: "preview1",
21
21
  env: process.env,
22
22
  preopens: {
23
23
  [__rootDir]: __rootDir,
24
- }
25
- })
24
+ },
25
+ });
26
26
 
27
- const __emnapiContext = __emnapiGetDefaultContext()
27
+ const __emnapiContext = __emnapiGetDefaultContext();
28
28
 
29
29
  const __sharedMemory = new WebAssembly.Memory({
30
30
  initial: 16384,
31
31
  maximum: 65536,
32
32
  shared: true,
33
- })
33
+ });
34
34
 
35
- let __wasmFilePath = __nodePath.join(__dirname, 'oxc-node.wasm32-wasi.wasm')
36
- const __wasmDebugFilePath = __nodePath.join(__dirname, 'oxc-node.wasm32-wasi.debug.wasm')
35
+ let __wasmFilePath = __nodePath.join(__dirname, "oxc-node.wasm32-wasi.wasm");
36
+ const __wasmDebugFilePath = __nodePath.join(__dirname, "oxc-node.wasm32-wasi.debug.wasm");
37
37
 
38
38
  if (__nodeFs.existsSync(__wasmDebugFilePath)) {
39
- __wasmFilePath = __wasmDebugFilePath
39
+ __wasmFilePath = __wasmDebugFilePath;
40
40
  } else if (!__nodeFs.existsSync(__wasmFilePath)) {
41
41
  try {
42
- __wasmFilePath = __nodePath.resolve('@oxc-node/core-wasm32-wasi')
42
+ __wasmFilePath = require.resolve("@oxc-node/core-wasm32-wasi/oxc-node.wasm32-wasi.wasm");
43
43
  } catch {
44
- throw new Error('Cannot find oxc-node.wasm32-wasi.wasm file, and @oxc-node/core-wasm32-wasi package is not installed.')
44
+ throw new Error(
45
+ "Cannot find oxc-node.wasm32-wasi.wasm file, and @oxc-node/core-wasm32-wasi package is not installed.",
46
+ );
45
47
  }
46
48
  }
47
49
 
48
- const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
50
+ const {
51
+ instance: __napiInstance,
52
+ module: __wasiModule,
53
+ napiModule: __napiModule,
54
+ } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
49
55
  context: __emnapiContext,
50
- asyncWorkPoolSize: (function() {
51
- const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
56
+ asyncWorkPoolSize: (function () {
57
+ const threadsSizeFromEnv = Number(
58
+ process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE,
59
+ );
52
60
  // NaN > 0 is false
53
61
  if (threadsSizeFromEnv > 0) {
54
- return threadsSizeFromEnv
62
+ return threadsSizeFromEnv;
55
63
  } else {
56
- return 4
64
+ return 4;
57
65
  }
58
66
  })(),
59
67
  reuseWorker: true,
60
68
  wasi: __wasi,
61
69
  onCreateWorker() {
62
- const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
70
+ const worker = new Worker(__nodePath.join(__dirname, "wasi-worker.mjs"), {
63
71
  env: process.env,
64
- })
72
+ });
65
73
  worker.onmessage = ({ data }) => {
66
- __wasmCreateOnMessageForFsProxy(__nodeFs)(data)
67
- }
74
+ __wasmCreateOnMessageForFsProxy(__nodeFs)(data);
75
+ };
68
76
 
69
77
  // The main thread of Node.js waits for all the active handles before exiting.
70
78
  // But Rust threads are never waited without `thread::join`.
@@ -72,15 +80,15 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
72
80
  // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
73
81
  // a worker is consist of two handles: kPublicPort and kHandle.
74
82
  {
75
- const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
76
- s.toString().includes("kPublicPort")
83
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
84
+ s.toString().includes("kPublicPort"),
77
85
  );
78
86
  if (kPublicPort) {
79
87
  worker[kPublicPort].ref = () => {};
80
88
  }
81
89
 
82
- const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
83
- s.toString().includes("kHandle")
90
+ const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
91
+ s.toString().includes("kHandle"),
84
92
  );
85
93
  if (kHandle) {
86
94
  worker[kHandle].ref = () => {};
@@ -88,7 +96,7 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
88
96
 
89
97
  worker.unref();
90
98
  }
91
- return worker
99
+ return worker;
92
100
  },
93
101
  overwriteImports(importObject) {
94
102
  importObject.env = {
@@ -96,22 +104,22 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
96
104
  ...importObject.napi,
97
105
  ...importObject.emnapi,
98
106
  memory: __sharedMemory,
99
- }
100
- return importObject
107
+ };
108
+ return importObject;
101
109
  },
102
110
  beforeInit({ instance }) {
103
111
  for (const name of Object.keys(instance.exports)) {
104
- if (name.startsWith('__napi_register__')) {
105
- instance.exports[name]()
112
+ if (name.startsWith("__napi_register__")) {
113
+ instance.exports[name]();
106
114
  }
107
115
  }
108
116
  },
109
- })
110
- module.exports = __napiModule.exports
111
- module.exports.Output = __napiModule.exports.Output
112
- module.exports.OxcTransformer = __napiModule.exports.OxcTransformer
113
- module.exports.createResolve = __napiModule.exports.createResolve
114
- module.exports.initTracing = __napiModule.exports.initTracing
115
- module.exports.load = __napiModule.exports.load
116
- module.exports.transform = __napiModule.exports.transform
117
- module.exports.transformAsync = __napiModule.exports.transformAsync
117
+ });
118
+ module.exports = __napiModule.exports;
119
+ module.exports.Output = __napiModule.exports.Output;
120
+ module.exports.OxcTransformer = __napiModule.exports.OxcTransformer;
121
+ module.exports.createResolve = __napiModule.exports.createResolve;
122
+ module.exports.initTracing = __napiModule.exports.initTracing;
123
+ module.exports.load = __napiModule.exports.load;
124
+ module.exports.transform = __napiModule.exports.transform;
125
+ module.exports.transformAsync = __napiModule.exports.transformAsync;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxc-node/core-wasm32-wasi",
3
- "version": "0.0.35",
3
+ "version": "0.1.0",
4
4
  "cpu": [
5
5
  "wasm32"
6
6
  ],
@@ -26,6 +26,8 @@
26
26
  },
27
27
  "browser": "oxc-node.wasi-browser.js",
28
28
  "dependencies": {
29
- "@napi-rs/wasm-runtime": "^1.0.7"
29
+ "@napi-rs/wasm-runtime": "^1.1.2",
30
+ "@emnapi/core": "1.9.1",
31
+ "@emnapi/runtime": "1.9.1"
30
32
  }
31
33
  }
@@ -1,17 +1,17 @@
1
- import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
1
+ import { instantiateNapiModuleSync, MessageHandler, WASI } from "@napi-rs/wasm-runtime";
2
2
 
3
3
  const handler = new MessageHandler({
4
4
  onLoad({ wasmModule, wasmMemory }) {
5
5
  const wasi = new WASI({
6
6
  print: function () {
7
7
  // eslint-disable-next-line no-console
8
- console.log.apply(console, arguments)
8
+ console.log.apply(console, arguments);
9
9
  },
10
- printErr: function() {
10
+ printErr: function () {
11
11
  // eslint-disable-next-line no-console
12
- console.error.apply(console, arguments)
12
+ console.error.apply(console, arguments);
13
13
  },
14
- })
14
+ });
15
15
  return instantiateNapiModuleSync(wasmModule, {
16
16
  childThread: true,
17
17
  wasi,
@@ -21,12 +21,12 @@ const handler = new MessageHandler({
21
21
  ...importObject.napi,
22
22
  ...importObject.emnapi,
23
23
  memory: wasmMemory,
24
- }
24
+ };
25
25
  },
26
- })
26
+ });
27
27
  },
28
- })
28
+ });
29
29
 
30
30
  globalThis.onmessage = function (e) {
31
- handler.handle(e)
32
- }
31
+ handler.handle(e);
32
+ };
package/wasi-worker.mjs CHANGED
@@ -6,7 +6,11 @@ import { parentPort, Worker } from "node:worker_threads";
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
8
 
9
- const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
9
+ const {
10
+ instantiateNapiModuleSync,
11
+ MessageHandler,
12
+ getDefaultContext,
13
+ } = require("@napi-rs/wasm-runtime");
10
14
 
11
15
  if (parentPort) {
12
16
  parentPort.on("message", (data) => {
@@ -19,7 +23,7 @@ Object.assign(globalThis, {
19
23
  require,
20
24
  Worker,
21
25
  importScripts: function (f) {
22
- ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
26
+ (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
23
27
  },
24
28
  postMessage: function (msg) {
25
29
  if (parentPort) {
@@ -35,7 +39,7 @@ const __rootDir = parse(process.cwd()).root;
35
39
  const handler = new MessageHandler({
36
40
  onLoad({ wasmModule, wasmMemory }) {
37
41
  const wasi = new WASI({
38
- version: 'preview1',
42
+ version: "preview1",
39
43
  env: process.env,
40
44
  preopens: {
41
45
  [__rootDir]: __rootDir,
@@ -51,7 +55,7 @@ const handler = new MessageHandler({
51
55
  ...importObject.env,
52
56
  ...importObject.napi,
53
57
  ...importObject.emnapi,
54
- memory: wasmMemory
58
+ memory: wasmMemory,
55
59
  };
56
60
  },
57
61
  });