@rspack-canary/binding-wasm32-wasi 1.7.0-canary-9a468043-20251230094321 → 1.7.0-canary-e04df144-20251230191636

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack-canary/binding-wasm32-wasi",
3
- "version": "1.7.0-canary-9a468043-20251230094321",
3
+ "version": "1.7.0-canary-e04df144-20251230191636",
4
4
  "license": "MIT",
5
5
  "description": "Node binding for rspack",
6
6
  "main": "rspack.wasi.cjs",
@@ -1,73 +1,73 @@
1
1
  import {
2
- createOnMessage as __wasmCreateOnMessageForFsProxy,
3
- getDefaultContext as __emnapiGetDefaultContext,
4
- instantiateNapiModule as __emnapiInstantiateNapiModule,
5
- WASI as __WASI
6
- } from "@napi-rs/wasm-runtime";
7
- import { memfs, Buffer } from "@napi-rs/wasm-runtime/fs";
2
+ createOnMessage as __wasmCreateOnMessageForFsProxy,
3
+ getDefaultContext as __emnapiGetDefaultContext,
4
+ instantiateNapiModule as __emnapiInstantiateNapiModule,
5
+ WASI as __WASI,
6
+ } from '@napi-rs/wasm-runtime';
7
+ import { memfs, Buffer } from '@napi-rs/wasm-runtime/fs';
8
8
 
9
9
  export const { fs: __fs, vol: __volume } = memfs();
10
10
 
11
11
  const __wasi = new __WASI({
12
- version: "preview1",
13
- fs: __fs,
14
- preopens: {
15
- "/": "/"
16
- }
12
+ version: 'preview1',
13
+ fs: __fs,
14
+ preopens: {
15
+ '/': '/',
16
+ },
17
17
  });
18
18
 
19
- const __wasmUrl = new URL("./rspack.wasm32-wasi.wasm", import.meta.url).href;
19
+ const __wasmUrl = new URL('./rspack.wasm32-wasi.wasm', import.meta.url).href;
20
20
  const __emnapiContext = __emnapiGetDefaultContext();
21
21
  __emnapiContext.feature.Buffer = Buffer;
22
22
 
23
23
  const __sharedMemory = new WebAssembly.Memory({
24
- initial: 16384,
25
- maximum: 65536,
26
- shared: true
24
+ initial: 16384,
25
+ maximum: 65536,
26
+ shared: true,
27
27
  });
28
28
 
29
- const __wasmFile = await fetch(__wasmUrl).then(res => res.arrayBuffer());
29
+ const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer());
30
30
 
31
31
  const {
32
- instance: __napiInstance,
33
- module: __wasiModule,
34
- napiModule: __napiModule
32
+ instance: __napiInstance,
33
+ module: __wasiModule,
34
+ napiModule: __napiModule,
35
35
  } = await __emnapiInstantiateNapiModule(__wasmFile, {
36
- context: __emnapiContext,
37
- asyncWorkPoolSize: 4,
38
- wasi: __wasi,
39
- onCreateWorker() {
40
- const worker = new Worker(
41
- new URL("./wasi-worker-browser.mjs", import.meta.url),
42
- {
43
- type: "module"
44
- }
45
- );
46
- worker.addEventListener("message", __wasmCreateOnMessageForFsProxy(__fs));
36
+ context: __emnapiContext,
37
+ asyncWorkPoolSize: 4,
38
+ wasi: __wasi,
39
+ onCreateWorker() {
40
+ const worker = new Worker(
41
+ new URL('./wasi-worker-browser.mjs', import.meta.url),
42
+ {
43
+ type: 'module',
44
+ },
45
+ );
46
+ worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs));
47
47
 
48
- return worker;
49
- },
50
- overwriteImports(importObject) {
51
- importObject.env = {
52
- ...importObject.env,
53
- ...importObject.napi,
54
- ...importObject.emnapi,
55
- memory: __sharedMemory
56
- };
57
- return importObject;
58
- },
59
- beforeInit({ instance }) {
60
- for (const name of Object.keys(instance.exports)) {
61
- if (name.startsWith("__napi_register__")) {
62
- instance.exports[name]();
63
- }
64
- }
65
- }
48
+ return worker;
49
+ },
50
+ overwriteImports(importObject) {
51
+ importObject.env = {
52
+ ...importObject.env,
53
+ ...importObject.napi,
54
+ ...importObject.emnapi,
55
+ memory: __sharedMemory,
56
+ };
57
+ return importObject;
58
+ },
59
+ beforeInit({ instance }) {
60
+ for (const name of Object.keys(instance.exports)) {
61
+ if (name.startsWith('__napi_register__')) {
62
+ instance.exports[name]();
63
+ }
64
+ }
65
+ },
66
66
  });
67
67
  export default __napiModule.exports;
68
68
  export const Assets = __napiModule.exports.Assets;
69
69
  export const AsyncDependenciesBlock =
70
- __napiModule.exports.AsyncDependenciesBlock;
70
+ __napiModule.exports.AsyncDependenciesBlock;
71
71
  export const Chunk = __napiModule.exports.Chunk;
72
72
  export const ChunkGraph = __napiModule.exports.ChunkGraph;
73
73
  export const ChunkGroup = __napiModule.exports.ChunkGroup;
@@ -87,10 +87,9 @@ export const ExternalModule = __napiModule.exports.ExternalModule;
87
87
  export const JsCompilation = __napiModule.exports.JsCompilation;
88
88
  export const JsCompiler = __napiModule.exports.JsCompiler;
89
89
  export const JsContextModuleFactoryAfterResolveData =
90
- __napiModule.exports.JsContextModuleFactoryAfterResolveData;
90
+ __napiModule.exports.JsContextModuleFactoryAfterResolveData;
91
91
  export const JsContextModuleFactoryBeforeResolveData =
92
- __napiModule.exports.JsContextModuleFactoryBeforeResolveData;
93
- export const JsCoordinator = __napiModule.exports.JsCoordinator;
92
+ __napiModule.exports.JsContextModuleFactoryBeforeResolveData;
94
93
  export const JsDependencies = __napiModule.exports.JsDependencies;
95
94
  export const JsEntries = __napiModule.exports.JsEntries;
96
95
  export const JsExportsInfo = __napiModule.exports.JsExportsInfo;
@@ -115,7 +114,7 @@ export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
115
114
  export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
116
115
  export const EnforceExtension = __napiModule.exports.EnforceExtension;
117
116
  export const EXPECTED_RSPACK_CORE_VERSION =
118
- __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
117
+ __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
119
118
  export const formatDiagnostic = __napiModule.exports.formatDiagnostic;
120
119
  export const JsLoaderState = __napiModule.exports.JsLoaderState;
121
120
  export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
@@ -123,9 +122,9 @@ export const loadBrowserslist = __napiModule.exports.loadBrowserslist;
123
122
  export const minify = __napiModule.exports.minify;
124
123
  export const minifySync = __napiModule.exports.minifySync;
125
124
  export const RawJavascriptParserCommonjsExports =
126
- __napiModule.exports.RawJavascriptParserCommonjsExports;
125
+ __napiModule.exports.RawJavascriptParserCommonjsExports;
127
126
  export const RawRuleSetConditionType =
128
- __napiModule.exports.RawRuleSetConditionType;
127
+ __napiModule.exports.RawRuleSetConditionType;
129
128
  export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
130
129
  export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
131
130
  export const sync = __napiModule.exports.sync;
package/rspack.wasi.cjs CHANGED
@@ -4,131 +4,132 @@
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
- createOnMessage: __wasmCreateOnMessageForFsProxy,
13
- getDefaultContext: __emnapiGetDefaultContext,
14
- instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync
15
- } = require("@napi-rs/wasm-runtime");
12
+ createOnMessage: __wasmCreateOnMessageForFsProxy,
13
+ getDefaultContext: __emnapiGetDefaultContext,
14
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
15
+ } = require('@napi-rs/wasm-runtime');
16
16
 
17
17
  const __rootDir = __nodePath.parse(process.cwd()).root;
18
18
 
19
19
  const __wasi = new __nodeWASI({
20
- version: "preview1",
21
- env: process.env,
22
- preopens: {
23
- [__rootDir]: __rootDir
24
- }
20
+ version: 'preview1',
21
+ env: process.env,
22
+ preopens: {
23
+ [__rootDir]: __rootDir,
24
+ },
25
25
  });
26
26
 
27
27
  const __emnapiContext = __emnapiGetDefaultContext();
28
28
 
29
29
  const __sharedMemory = new WebAssembly.Memory({
30
- initial: 16384,
31
- maximum: 65536,
32
- shared: true
30
+ initial: 16384,
31
+ maximum: 65536,
32
+ shared: true,
33
33
  });
34
34
 
35
- let __wasmFilePath = __nodePath.join(__dirname, "rspack.wasm32-wasi.wasm");
35
+ let __wasmFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.wasm');
36
36
  const __wasmDebugFilePath = __nodePath.join(
37
- __dirname,
38
- "rspack.wasm32-wasi.debug.wasm"
37
+ __dirname,
38
+ 'rspack.wasm32-wasi.debug.wasm',
39
39
  );
40
40
 
41
41
  if (__nodeFs.existsSync(__wasmDebugFilePath)) {
42
- __wasmFilePath = __wasmDebugFilePath;
42
+ __wasmFilePath = __wasmDebugFilePath;
43
43
  } else if (!__nodeFs.existsSync(__wasmFilePath)) {
44
- try {
45
- __wasmFilePath = __nodePath.resolve("@rspack/binding-wasm32-wasi");
46
- } catch {
47
- throw new Error(
48
- "Cannot find rspack.wasm32-wasi.wasm file, and @rspack/binding-wasm32-wasi package is not installed."
49
- );
50
- }
44
+ try {
45
+ __wasmFilePath = __nodePath.resolve('@rspack/binding-wasm32-wasi');
46
+ } catch {
47
+ throw new Error(
48
+ 'Cannot find rspack.wasm32-wasi.wasm file, and @rspack/binding-wasm32-wasi package is not installed.',
49
+ );
50
+ }
51
51
  }
52
52
 
53
53
  const {
54
- instance: __napiInstance,
55
- module: __wasiModule,
56
- napiModule: __napiModule
54
+ instance: __napiInstance,
55
+ module: __wasiModule,
56
+ napiModule: __napiModule,
57
57
  } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
58
- context: __emnapiContext,
59
- asyncWorkPoolSize: (function () {
60
- const threadsSizeFromEnv = Number(
61
- process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE
62
- );
63
- // NaN > 0 is false
64
- if (threadsSizeFromEnv > 0) {
65
- return threadsSizeFromEnv;
66
- } else {
67
- return 4;
68
- }
69
- })(),
70
- reuseWorker: true,
71
- wasi: __wasi,
72
- onCreateWorker() {
73
- const worker = new Worker(__nodePath.join(__dirname, "wasi-worker.mjs"), {
74
- env: process.env
75
- });
76
- worker.onmessage = ({ data }) => {
77
- __wasmCreateOnMessageForFsProxy(__nodeFs)(data);
78
- };
58
+ context: __emnapiContext,
59
+ asyncWorkPoolSize: (function () {
60
+ const threadsSizeFromEnv = Number(
61
+ process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ??
62
+ process.env.UV_THREADPOOL_SIZE,
63
+ );
64
+ // NaN > 0 is false
65
+ if (threadsSizeFromEnv > 0) {
66
+ return threadsSizeFromEnv;
67
+ } else {
68
+ return 4;
69
+ }
70
+ })(),
71
+ reuseWorker: true,
72
+ wasi: __wasi,
73
+ onCreateWorker() {
74
+ const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
75
+ env: process.env,
76
+ });
77
+ worker.onmessage = ({ data }) => {
78
+ __wasmCreateOnMessageForFsProxy(__nodeFs)(data);
79
+ };
79
80
 
80
- // The main thread of Node.js waits for all the active handles before exiting.
81
- // But Rust threads are never waited without `thread::join`.
82
- // So here we hack the code of Node.js to prevent the workers from being referenced (active).
83
- // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
84
- // a worker is consist of two handles: kPublicPort and kHandle.
85
- {
86
- const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
87
- s.toString().includes("kPublicPort")
88
- );
89
- if (kPublicPort) {
90
- worker[kPublicPort].ref = () => {};
91
- }
81
+ // The main thread of Node.js waits for all the active handles before exiting.
82
+ // But Rust threads are never waited without `thread::join`.
83
+ // So here we hack the code of Node.js to prevent the workers from being referenced (active).
84
+ // According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
85
+ // a worker is consist of two handles: kPublicPort and kHandle.
86
+ {
87
+ const kPublicPort = Object.getOwnPropertySymbols(worker).find((s) =>
88
+ s.toString().includes('kPublicPort'),
89
+ );
90
+ if (kPublicPort) {
91
+ worker[kPublicPort].ref = () => {};
92
+ }
92
93
 
93
- const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
94
- s.toString().includes("kHandle")
95
- );
96
- if (kHandle) {
97
- worker[kHandle].ref = () => {};
98
- }
94
+ const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
95
+ s.toString().includes('kHandle'),
96
+ );
97
+ if (kHandle) {
98
+ worker[kHandle].ref = () => {};
99
+ }
99
100
 
100
- worker.unref();
101
- }
102
- return worker;
103
- },
104
- overwriteImports(importObject) {
105
- importObject.env = {
106
- ...importObject.env,
107
- ...importObject.napi,
108
- ...importObject.emnapi,
109
- memory: __sharedMemory
110
- };
111
- return importObject;
112
- },
113
- beforeInit({ instance }) {
114
- for (const name of Object.keys(instance.exports)) {
115
- if (name.startsWith("__napi_register__")) {
116
- instance.exports[name]();
117
- }
118
- }
119
- }
101
+ worker.unref();
102
+ }
103
+ return worker;
104
+ },
105
+ overwriteImports(importObject) {
106
+ importObject.env = {
107
+ ...importObject.env,
108
+ ...importObject.napi,
109
+ ...importObject.emnapi,
110
+ memory: __sharedMemory,
111
+ };
112
+ return importObject;
113
+ },
114
+ beforeInit({ instance }) {
115
+ for (const name of Object.keys(instance.exports)) {
116
+ if (name.startsWith('__napi_register__')) {
117
+ instance.exports[name]();
118
+ }
119
+ }
120
+ },
120
121
  });
121
122
  module.exports = __napiModule.exports;
122
123
  module.exports.Assets = __napiModule.exports.Assets;
123
124
  module.exports.AsyncDependenciesBlock =
124
- __napiModule.exports.AsyncDependenciesBlock;
125
+ __napiModule.exports.AsyncDependenciesBlock;
125
126
  module.exports.Chunk = __napiModule.exports.Chunk;
126
127
  module.exports.ChunkGraph = __napiModule.exports.ChunkGraph;
127
128
  module.exports.ChunkGroup = __napiModule.exports.ChunkGroup;
128
129
  module.exports.Chunks = __napiModule.exports.Chunks;
129
130
  module.exports.CodeGenerationResult = __napiModule.exports.CodeGenerationResult;
130
131
  module.exports.CodeGenerationResults =
131
- __napiModule.exports.CodeGenerationResults;
132
+ __napiModule.exports.CodeGenerationResults;
132
133
  module.exports.ConcatenatedModule = __napiModule.exports.ConcatenatedModule;
133
134
  module.exports.ContextModule = __napiModule.exports.ContextModule;
134
135
  module.exports.Dependency = __napiModule.exports.Dependency;
@@ -142,10 +143,9 @@ module.exports.ExternalModule = __napiModule.exports.ExternalModule;
142
143
  module.exports.JsCompilation = __napiModule.exports.JsCompilation;
143
144
  module.exports.JsCompiler = __napiModule.exports.JsCompiler;
144
145
  module.exports.JsContextModuleFactoryAfterResolveData =
145
- __napiModule.exports.JsContextModuleFactoryAfterResolveData;
146
+ __napiModule.exports.JsContextModuleFactoryAfterResolveData;
146
147
  module.exports.JsContextModuleFactoryBeforeResolveData =
147
- __napiModule.exports.JsContextModuleFactoryBeforeResolveData;
148
- module.exports.JsCoordinator = __napiModule.exports.JsCoordinator;
148
+ __napiModule.exports.JsContextModuleFactoryBeforeResolveData;
149
149
  module.exports.JsDependencies = __napiModule.exports.JsDependencies;
150
150
  module.exports.JsEntries = __napiModule.exports.JsEntries;
151
151
  module.exports.JsExportsInfo = __napiModule.exports.JsExportsInfo;
@@ -156,7 +156,7 @@ module.exports.JsStats = __napiModule.exports.JsStats;
156
156
  module.exports.KnownBuildInfo = __napiModule.exports.KnownBuildInfo;
157
157
  module.exports.Module = __napiModule.exports.Module;
158
158
  module.exports.ModuleGraphConnection =
159
- __napiModule.exports.ModuleGraphConnection;
159
+ __napiModule.exports.ModuleGraphConnection;
160
160
  module.exports.NativeWatcher = __napiModule.exports.NativeWatcher;
161
161
  module.exports.NativeWatchResult = __napiModule.exports.NativeWatchResult;
162
162
  module.exports.NormalModule = __napiModule.exports.NormalModule;
@@ -171,7 +171,7 @@ module.exports.BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
171
171
  module.exports.cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
172
172
  module.exports.EnforceExtension = __napiModule.exports.EnforceExtension;
173
173
  module.exports.EXPECTED_RSPACK_CORE_VERSION =
174
- __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
174
+ __napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
175
175
  module.exports.formatDiagnostic = __napiModule.exports.formatDiagnostic;
176
176
  module.exports.JsLoaderState = __napiModule.exports.JsLoaderState;
177
177
  module.exports.JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
@@ -179,9 +179,9 @@ module.exports.loadBrowserslist = __napiModule.exports.loadBrowserslist;
179
179
  module.exports.minify = __napiModule.exports.minify;
180
180
  module.exports.minifySync = __napiModule.exports.minifySync;
181
181
  module.exports.RawJavascriptParserCommonjsExports =
182
- __napiModule.exports.RawJavascriptParserCommonjsExports;
182
+ __napiModule.exports.RawJavascriptParserCommonjsExports;
183
183
  module.exports.RawRuleSetConditionType =
184
- __napiModule.exports.RawRuleSetConditionType;
184
+ __napiModule.exports.RawRuleSetConditionType;
185
185
  module.exports.registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
186
186
  module.exports.RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
187
187
  module.exports.sync = __napiModule.exports.sync;
Binary file
@@ -1,44 +1,44 @@
1
1
  import {
2
- instantiateNapiModuleSync,
3
- MessageHandler,
4
- WASI,
5
- createFsProxy
6
- } from "@napi-rs/wasm-runtime";
7
- import { memfsExported as __memfsExported } from "@napi-rs/wasm-runtime/fs";
2
+ instantiateNapiModuleSync,
3
+ MessageHandler,
4
+ WASI,
5
+ createFsProxy,
6
+ } from '@napi-rs/wasm-runtime';
7
+ import { memfsExported as __memfsExported } from '@napi-rs/wasm-runtime/fs';
8
8
 
9
9
  const fs = createFsProxy(__memfsExported);
10
10
 
11
11
  const handler = new MessageHandler({
12
- onLoad({ wasmModule, wasmMemory }) {
13
- const wasi = new WASI({
14
- fs,
15
- preopens: {
16
- "/": "/"
17
- },
18
- print: function () {
19
- // eslint-disable-next-line no-console
20
- console.log.apply(console, arguments);
21
- },
22
- printErr: function () {
23
- // eslint-disable-next-line no-console
24
- console.error.apply(console, arguments);
25
- }
26
- });
27
- return instantiateNapiModuleSync(wasmModule, {
28
- childThread: true,
29
- wasi,
30
- overwriteImports(importObject) {
31
- importObject.env = {
32
- ...importObject.env,
33
- ...importObject.napi,
34
- ...importObject.emnapi,
35
- memory: wasmMemory
36
- };
37
- }
38
- });
39
- }
12
+ onLoad({ wasmModule, wasmMemory }) {
13
+ const wasi = new WASI({
14
+ fs,
15
+ preopens: {
16
+ '/': '/',
17
+ },
18
+ print: function () {
19
+ // eslint-disable-next-line no-console
20
+ console.log.apply(console, arguments);
21
+ },
22
+ printErr: function () {
23
+ // eslint-disable-next-line no-console
24
+ console.error.apply(console, arguments);
25
+ },
26
+ });
27
+ return instantiateNapiModuleSync(wasmModule, {
28
+ childThread: true,
29
+ wasi,
30
+ overwriteImports(importObject) {
31
+ importObject.env = {
32
+ ...importObject.env,
33
+ ...importObject.napi,
34
+ ...importObject.emnapi,
35
+ memory: wasmMemory,
36
+ };
37
+ },
38
+ });
39
+ },
40
40
  });
41
41
 
42
42
  globalThis.onmessage = function (e) {
43
- handler.handle(e);
43
+ handler.handle(e);
44
44
  };
package/wasi-worker.mjs CHANGED
@@ -1,35 +1,35 @@
1
- import fs from "node:fs";
2
- import { createRequire } from "node:module";
3
- import { parse } from "node:path";
4
- import { WASI } from "node:wasi";
5
- import { parentPort, Worker } from "node:worker_threads";
1
+ import fs from 'node:fs';
2
+ import { createRequire } from 'node:module';
3
+ import { parse } from 'node:path';
4
+ import { WASI } from 'node:wasi';
5
+ import { parentPort, Worker } from 'node:worker_threads';
6
6
 
7
7
  const require = createRequire(import.meta.url);
8
8
 
9
9
  const {
10
- instantiateNapiModuleSync,
11
- MessageHandler,
12
- getDefaultContext
13
- } = require("@napi-rs/wasm-runtime");
10
+ instantiateNapiModuleSync,
11
+ MessageHandler,
12
+ getDefaultContext,
13
+ } = require('@napi-rs/wasm-runtime');
14
14
 
15
15
  if (parentPort) {
16
- parentPort.on("message", data => {
17
- globalThis.onmessage({ data });
18
- });
16
+ parentPort.on('message', (data) => {
17
+ globalThis.onmessage({ data });
18
+ });
19
19
  }
20
20
 
21
21
  Object.assign(globalThis, {
22
- self: globalThis,
23
- require,
24
- Worker,
25
- importScripts: function (f) {
26
- (0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
27
- },
28
- postMessage: function (msg) {
29
- if (parentPort) {
30
- parentPort.postMessage(msg);
31
- }
32
- }
22
+ self: globalThis,
23
+ require,
24
+ Worker,
25
+ importScripts: function (f) {
26
+ (0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f);
27
+ },
28
+ postMessage: function (msg) {
29
+ if (parentPort) {
30
+ parentPort.postMessage(msg);
31
+ }
32
+ },
33
33
  });
34
34
 
35
35
  const emnapiContext = getDefaultContext();
@@ -37,31 +37,31 @@ const emnapiContext = getDefaultContext();
37
37
  const __rootDir = parse(process.cwd()).root;
38
38
 
39
39
  const handler = new MessageHandler({
40
- onLoad({ wasmModule, wasmMemory }) {
41
- const wasi = new WASI({
42
- version: "preview1",
43
- env: process.env,
44
- preopens: {
45
- [__rootDir]: __rootDir
46
- }
47
- });
40
+ onLoad({ wasmModule, wasmMemory }) {
41
+ const wasi = new WASI({
42
+ version: 'preview1',
43
+ env: process.env,
44
+ preopens: {
45
+ [__rootDir]: __rootDir,
46
+ },
47
+ });
48
48
 
49
- return instantiateNapiModuleSync(wasmModule, {
50
- childThread: true,
51
- wasi,
52
- context: emnapiContext,
53
- overwriteImports(importObject) {
54
- importObject.env = {
55
- ...importObject.env,
56
- ...importObject.napi,
57
- ...importObject.emnapi,
58
- memory: wasmMemory
59
- };
60
- }
61
- });
62
- }
49
+ return instantiateNapiModuleSync(wasmModule, {
50
+ childThread: true,
51
+ wasi,
52
+ context: emnapiContext,
53
+ overwriteImports(importObject) {
54
+ importObject.env = {
55
+ ...importObject.env,
56
+ ...importObject.napi,
57
+ ...importObject.emnapi,
58
+ memory: wasmMemory,
59
+ };
60
+ },
61
+ });
62
+ },
63
63
  });
64
64
 
65
65
  globalThis.onmessage = function (e) {
66
- handler.handle(e);
66
+ handler.handle(e);
67
67
  };