@rspack-canary/binding-wasm32-wasi 1.7.0-canary-c8f933e3-20251224124051 → 1.7.0-canary-8fb5a12e-20251225173433
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 +1 -1
- package/rspack.wasi-browser.js +54 -54
- package/rspack.wasi.cjs +97 -96
- package/rspack.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +35 -35
- package/wasi-worker.mjs +46 -46
package/package.json
CHANGED
package/rspack.wasi-browser.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import { memfs, Buffer } from
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
version: 'preview1',
|
|
13
|
+
fs: __fs,
|
|
14
|
+
preopens: {
|
|
15
|
+
'/': '/',
|
|
16
|
+
},
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
const __wasmUrl = new URL(
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
instance: __napiInstance,
|
|
33
|
+
module: __wasiModule,
|
|
34
|
+
napiModule: __napiModule,
|
|
35
35
|
} = await __emnapiInstantiateNapiModule(__wasmFile, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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,9 +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
|
-
|
|
90
|
+
__napiModule.exports.JsContextModuleFactoryAfterResolveData;
|
|
91
91
|
export const JsContextModuleFactoryBeforeResolveData =
|
|
92
|
-
|
|
92
|
+
__napiModule.exports.JsContextModuleFactoryBeforeResolveData;
|
|
93
93
|
export const JsDependencies = __napiModule.exports.JsDependencies;
|
|
94
94
|
export const JsEntries = __napiModule.exports.JsEntries;
|
|
95
95
|
export const JsExportsInfo = __napiModule.exports.JsExportsInfo;
|
|
@@ -114,7 +114,7 @@ export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
|
|
|
114
114
|
export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
|
|
115
115
|
export const EnforceExtension = __napiModule.exports.EnforceExtension;
|
|
116
116
|
export const EXPECTED_RSPACK_CORE_VERSION =
|
|
117
|
-
|
|
117
|
+
__napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
|
|
118
118
|
export const formatDiagnostic = __napiModule.exports.formatDiagnostic;
|
|
119
119
|
export const JsLoaderState = __napiModule.exports.JsLoaderState;
|
|
120
120
|
export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
|
|
@@ -122,9 +122,9 @@ export const loadBrowserslist = __napiModule.exports.loadBrowserslist;
|
|
|
122
122
|
export const minify = __napiModule.exports.minify;
|
|
123
123
|
export const minifySync = __napiModule.exports.minifySync;
|
|
124
124
|
export const RawJavascriptParserCommonjsExports =
|
|
125
|
-
|
|
125
|
+
__napiModule.exports.RawJavascriptParserCommonjsExports;
|
|
126
126
|
export const RawRuleSetConditionType =
|
|
127
|
-
|
|
127
|
+
__napiModule.exports.RawRuleSetConditionType;
|
|
128
128
|
export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
|
|
129
129
|
export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
|
|
130
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(
|
|
8
|
-
const { WASI: __nodeWASI } = require(
|
|
9
|
-
const { Worker } = require(
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = require(
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
initial: 16384,
|
|
31
|
+
maximum: 65536,
|
|
32
|
+
shared: true,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
let __wasmFilePath = __nodePath.join(__dirname,
|
|
35
|
+
let __wasmFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.wasm');
|
|
36
36
|
const __wasmDebugFilePath = __nodePath.join(
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
__dirname,
|
|
38
|
+
'rspack.wasm32-wasi.debug.wasm',
|
|
39
39
|
);
|
|
40
40
|
|
|
41
41
|
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
42
|
-
|
|
42
|
+
__wasmFilePath = __wasmDebugFilePath;
|
|
43
43
|
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
instance: __napiInstance,
|
|
55
|
+
module: __wasiModule,
|
|
56
|
+
napiModule: __napiModule,
|
|
57
57
|
} = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,9 +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
|
-
|
|
146
|
+
__napiModule.exports.JsContextModuleFactoryAfterResolveData;
|
|
146
147
|
module.exports.JsContextModuleFactoryBeforeResolveData =
|
|
147
|
-
|
|
148
|
+
__napiModule.exports.JsContextModuleFactoryBeforeResolveData;
|
|
148
149
|
module.exports.JsDependencies = __napiModule.exports.JsDependencies;
|
|
149
150
|
module.exports.JsEntries = __napiModule.exports.JsEntries;
|
|
150
151
|
module.exports.JsExportsInfo = __napiModule.exports.JsExportsInfo;
|
|
@@ -155,7 +156,7 @@ module.exports.JsStats = __napiModule.exports.JsStats;
|
|
|
155
156
|
module.exports.KnownBuildInfo = __napiModule.exports.KnownBuildInfo;
|
|
156
157
|
module.exports.Module = __napiModule.exports.Module;
|
|
157
158
|
module.exports.ModuleGraphConnection =
|
|
158
|
-
|
|
159
|
+
__napiModule.exports.ModuleGraphConnection;
|
|
159
160
|
module.exports.NativeWatcher = __napiModule.exports.NativeWatcher;
|
|
160
161
|
module.exports.NativeWatchResult = __napiModule.exports.NativeWatchResult;
|
|
161
162
|
module.exports.NormalModule = __napiModule.exports.NormalModule;
|
|
@@ -170,7 +171,7 @@ module.exports.BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
|
|
|
170
171
|
module.exports.cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
|
|
171
172
|
module.exports.EnforceExtension = __napiModule.exports.EnforceExtension;
|
|
172
173
|
module.exports.EXPECTED_RSPACK_CORE_VERSION =
|
|
173
|
-
|
|
174
|
+
__napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
|
|
174
175
|
module.exports.formatDiagnostic = __napiModule.exports.formatDiagnostic;
|
|
175
176
|
module.exports.JsLoaderState = __napiModule.exports.JsLoaderState;
|
|
176
177
|
module.exports.JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
|
|
@@ -178,9 +179,9 @@ module.exports.loadBrowserslist = __napiModule.exports.loadBrowserslist;
|
|
|
178
179
|
module.exports.minify = __napiModule.exports.minify;
|
|
179
180
|
module.exports.minifySync = __napiModule.exports.minifySync;
|
|
180
181
|
module.exports.RawJavascriptParserCommonjsExports =
|
|
181
|
-
|
|
182
|
+
__napiModule.exports.RawJavascriptParserCommonjsExports;
|
|
182
183
|
module.exports.RawRuleSetConditionType =
|
|
183
|
-
|
|
184
|
+
__napiModule.exports.RawRuleSetConditionType;
|
|
184
185
|
module.exports.registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
|
|
185
186
|
module.exports.RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
|
|
186
187
|
module.exports.sync = __napiModule.exports.sync;
|
package/rspack.wasm32-wasi.wasm
CHANGED
|
Binary file
|
package/wasi-worker-browser.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import { memfsExported as __memfsExported } from
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
43
|
+
handler.handle(e);
|
|
44
44
|
};
|
package/wasi-worker.mjs
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import { parse } from
|
|
4
|
-
import { WASI } from
|
|
5
|
-
import { parentPort, Worker } from
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} = require(
|
|
10
|
+
instantiateNapiModuleSync,
|
|
11
|
+
MessageHandler,
|
|
12
|
+
getDefaultContext,
|
|
13
|
+
} = require('@napi-rs/wasm-runtime');
|
|
14
14
|
|
|
15
15
|
if (parentPort) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
parentPort.on('message', (data) => {
|
|
17
|
+
globalThis.onmessage({ data });
|
|
18
|
+
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
Object.assign(globalThis, {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
66
|
+
handler.handle(e);
|
|
67
67
|
};
|