@rspack-debug/binding-wasm32-wasi 0.0.1 → 2.1.3
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/LICENSE +21 -0
- package/README.md +16 -2
- package/package.json +22 -10
- package/rspack.wasi-browser.js +147 -0
- package/rspack.wasi.cjs +191 -0
- package/rspack.wasm32-wasi.wasm +0 -0
- package/wasi-worker-browser.mjs +52 -0
- package/wasi-worker.mjs +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-present Bytedance Inc and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
<picture>
|
|
2
|
+
<img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
|
|
3
|
+
</picture>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# @rspack/binding-wasm32-wasi
|
|
6
|
+
|
|
7
|
+
Private node binding crate for rspack.
|
|
8
|
+
|
|
9
|
+
This package does _NOT_ follow [semantic versioning](https://semver.org/).
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
See [https://rspack.rs](https://rspack.rs) for details.
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
Rspack is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspack-debug/binding-wasm32-wasi",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "Node binding for rspack",
|
|
6
|
+
"main": "rspack.wasi.cjs",
|
|
7
|
+
"browser": "rspack.wasi-browser.js",
|
|
6
8
|
"homepage": "https://rspack.rs",
|
|
7
9
|
"bugs": "https://github.com/web-infra-dev/rspack/issues",
|
|
8
10
|
"repository": {
|
|
9
11
|
"type": "git",
|
|
10
|
-
"url": "
|
|
11
|
-
"directory": "npm/wasm32-wasi"
|
|
12
|
+
"url": "https://github.com/web-infra-dev/rspack"
|
|
12
13
|
},
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public",
|
|
15
|
-
"provenance": true
|
|
16
|
-
"cpu": [
|
|
17
|
-
"wasm32"
|
|
18
|
-
]
|
|
16
|
+
"provenance": true
|
|
19
17
|
},
|
|
20
|
-
"files": [
|
|
21
|
-
|
|
18
|
+
"files": [
|
|
19
|
+
"rspack.wasm32-wasi.wasm",
|
|
20
|
+
"rspack.wasi.cjs",
|
|
21
|
+
"rspack.wasi-browser.js",
|
|
22
|
+
"wasi-worker.mjs",
|
|
23
|
+
"wasi-worker-browser.mjs"
|
|
24
|
+
],
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@emnapi/core": "1.11.1",
|
|
27
|
+
"@emnapi/runtime": "1.11.1",
|
|
28
|
+
"@napi-rs/wasm-runtime": "1.1.6"
|
|
29
|
+
},
|
|
30
|
+
"cpu": [
|
|
31
|
+
"wasm32"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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';
|
|
8
|
+
|
|
9
|
+
export const { fs: __fs, vol: __volume } = memfs();
|
|
10
|
+
|
|
11
|
+
const __wasi = new __WASI({
|
|
12
|
+
version: 'preview1',
|
|
13
|
+
fs: __fs,
|
|
14
|
+
preopens: {
|
|
15
|
+
'/': '/',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const __wasmUrl = new URL('./rspack.wasm32-wasi.wasm', import.meta.url).href;
|
|
20
|
+
const __emnapiContext = __emnapiGetDefaultContext();
|
|
21
|
+
__emnapiContext.feature.Buffer = Buffer;
|
|
22
|
+
|
|
23
|
+
// Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
|
|
24
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
25
|
+
initial: 32768,
|
|
26
|
+
maximum: 32768,
|
|
27
|
+
shared: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer());
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
instance: __napiInstance,
|
|
34
|
+
module: __wasiModule,
|
|
35
|
+
napiModule: __napiModule,
|
|
36
|
+
} = await __emnapiInstantiateNapiModule(__wasmFile, {
|
|
37
|
+
context: __emnapiContext,
|
|
38
|
+
asyncWorkPoolSize: 4,
|
|
39
|
+
wasi: __wasi,
|
|
40
|
+
onCreateWorker() {
|
|
41
|
+
const worker = new Worker(
|
|
42
|
+
new URL('./wasi-worker-browser.mjs', import.meta.url),
|
|
43
|
+
{
|
|
44
|
+
type: 'module',
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
worker.addEventListener('message', __wasmCreateOnMessageForFsProxy(__fs));
|
|
48
|
+
|
|
49
|
+
worker.addEventListener('error', (event) => {
|
|
50
|
+
if (
|
|
51
|
+
event.data &&
|
|
52
|
+
typeof event.data === 'object' &&
|
|
53
|
+
event.data.type === 'error'
|
|
54
|
+
) {
|
|
55
|
+
window.dispatchEvent(
|
|
56
|
+
new CustomEvent('napi-rs-worker-error', { detail: event.data }),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return worker;
|
|
62
|
+
},
|
|
63
|
+
overwriteImports(importObject) {
|
|
64
|
+
importObject.env = {
|
|
65
|
+
...importObject.env,
|
|
66
|
+
...importObject.napi,
|
|
67
|
+
...importObject.emnapi,
|
|
68
|
+
memory: __sharedMemory,
|
|
69
|
+
};
|
|
70
|
+
return importObject;
|
|
71
|
+
},
|
|
72
|
+
beforeInit({ instance }) {
|
|
73
|
+
for (const name of Object.keys(instance.exports)) {
|
|
74
|
+
if (name.startsWith('__napi_register__')) {
|
|
75
|
+
instance.exports[name]();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
export default __napiModule.exports;
|
|
81
|
+
export const Assets = __napiModule.exports.Assets;
|
|
82
|
+
export const AsyncDependenciesBlock =
|
|
83
|
+
__napiModule.exports.AsyncDependenciesBlock;
|
|
84
|
+
export const Chunk = __napiModule.exports.Chunk;
|
|
85
|
+
export const ChunkGraph = __napiModule.exports.ChunkGraph;
|
|
86
|
+
export const ChunkGroup = __napiModule.exports.ChunkGroup;
|
|
87
|
+
export const Chunks = __napiModule.exports.Chunks;
|
|
88
|
+
export const CodeGenerationResult = __napiModule.exports.CodeGenerationResult;
|
|
89
|
+
export const CodeGenerationResults = __napiModule.exports.CodeGenerationResults;
|
|
90
|
+
export const ConcatenatedModule = __napiModule.exports.ConcatenatedModule;
|
|
91
|
+
export const ContextModule = __napiModule.exports.ContextModule;
|
|
92
|
+
export const Dependency = __napiModule.exports.Dependency;
|
|
93
|
+
export const Diagnostics = __napiModule.exports.Diagnostics;
|
|
94
|
+
export const EntryDataDto = __napiModule.exports.EntryDataDto;
|
|
95
|
+
export const EntryDataDTO = __napiModule.exports.EntryDataDTO;
|
|
96
|
+
export const EntryDependency = __napiModule.exports.EntryDependency;
|
|
97
|
+
export const EntryOptionsDto = __napiModule.exports.EntryOptionsDto;
|
|
98
|
+
export const EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO;
|
|
99
|
+
export const ExternalModule = __napiModule.exports.ExternalModule;
|
|
100
|
+
export const JsCompilation = __napiModule.exports.JsCompilation;
|
|
101
|
+
export const JsCompiler = __napiModule.exports.JsCompiler;
|
|
102
|
+
export const JsContextModuleFactoryAfterResolveData =
|
|
103
|
+
__napiModule.exports.JsContextModuleFactoryAfterResolveData;
|
|
104
|
+
export const JsContextModuleFactoryBeforeResolveData =
|
|
105
|
+
__napiModule.exports.JsContextModuleFactoryBeforeResolveData;
|
|
106
|
+
export const JsCoordinator = __napiModule.exports.JsCoordinator;
|
|
107
|
+
export const JsDependencies = __napiModule.exports.JsDependencies;
|
|
108
|
+
export const JsEntries = __napiModule.exports.JsEntries;
|
|
109
|
+
export const JsExportsInfo = __napiModule.exports.JsExportsInfo;
|
|
110
|
+
export const JsModuleGraph = __napiModule.exports.JsModuleGraph;
|
|
111
|
+
export const JsResolver = __napiModule.exports.JsResolver;
|
|
112
|
+
export const JsResolverFactory = __napiModule.exports.JsResolverFactory;
|
|
113
|
+
export const JsStats = __napiModule.exports.JsStats;
|
|
114
|
+
export const KnownBuildInfo = __napiModule.exports.KnownBuildInfo;
|
|
115
|
+
export const Module = __napiModule.exports.Module;
|
|
116
|
+
export const ModuleGraphConnection = __napiModule.exports.ModuleGraphConnection;
|
|
117
|
+
export const NativeWatcher = __napiModule.exports.NativeWatcher;
|
|
118
|
+
export const NativeWatchResult = __napiModule.exports.NativeWatchResult;
|
|
119
|
+
export const NormalModule = __napiModule.exports.NormalModule;
|
|
120
|
+
export const RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx;
|
|
121
|
+
export const ReadonlyResourceData = __napiModule.exports.ReadonlyResourceData;
|
|
122
|
+
export const ResolverFactory = __napiModule.exports.ResolverFactory;
|
|
123
|
+
export const Sources = __napiModule.exports.Sources;
|
|
124
|
+
export const VirtualFileStore = __napiModule.exports.VirtualFileStore;
|
|
125
|
+
export const JsVirtualFileStore = __napiModule.exports.JsVirtualFileStore;
|
|
126
|
+
export const async = __napiModule.exports.async;
|
|
127
|
+
export const BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
|
|
128
|
+
export const cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
|
|
129
|
+
export const EnforceExtension = __napiModule.exports.EnforceExtension;
|
|
130
|
+
export const EXPECTED_RSPACK_CORE_VERSION =
|
|
131
|
+
__napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
|
|
132
|
+
export const formatDiagnostic = __napiModule.exports.formatDiagnostic;
|
|
133
|
+
export const JsLoaderState = __napiModule.exports.JsLoaderState;
|
|
134
|
+
export const JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
|
|
135
|
+
export const loadBrowserslist = __napiModule.exports.loadBrowserslist;
|
|
136
|
+
export const minify = __napiModule.exports.minify;
|
|
137
|
+
export const minifySync = __napiModule.exports.minifySync;
|
|
138
|
+
export const RawJavascriptParserCommonjsExports =
|
|
139
|
+
__napiModule.exports.RawJavascriptParserCommonjsExports;
|
|
140
|
+
export const RawRuleSetConditionType =
|
|
141
|
+
__napiModule.exports.RawRuleSetConditionType;
|
|
142
|
+
export const registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
|
|
143
|
+
export const RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
|
|
144
|
+
export const sync = __napiModule.exports.sync;
|
|
145
|
+
export const syncTraceEvent = __napiModule.exports.syncTraceEvent;
|
|
146
|
+
export const transform = __napiModule.exports.transform;
|
|
147
|
+
export const transformSync = __napiModule.exports.transformSync;
|
package/rspack.wasi.cjs
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
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');
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
+
} = require('@napi-rs/wasm-runtime');
|
|
16
|
+
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root;
|
|
18
|
+
|
|
19
|
+
const __wasi = new __nodeWASI({
|
|
20
|
+
version: 'preview1',
|
|
21
|
+
env: process.env,
|
|
22
|
+
preopens: {
|
|
23
|
+
[__rootDir]: __rootDir,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const __emnapiContext = __emnapiGetDefaultContext();
|
|
28
|
+
|
|
29
|
+
// Allocate 2GB fixed shared memory (initial == maximum to disable memory.grow).
|
|
30
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
31
|
+
initial: 32768,
|
|
32
|
+
maximum: 32768,
|
|
33
|
+
shared: true,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const localWasmFilePath = __nodePath.join(__dirname, 'rspack.wasm32-wasi.wasm');
|
|
37
|
+
|
|
38
|
+
let __wasmFilePath;
|
|
39
|
+
|
|
40
|
+
if (__nodeFs.existsSync(localWasmFilePath)) {
|
|
41
|
+
__wasmFilePath = localWasmFilePath;
|
|
42
|
+
} else {
|
|
43
|
+
try {
|
|
44
|
+
__wasmFilePath =
|
|
45
|
+
require.resolve('@rspack/binding-wasm32-wasi/rspack.wasm32-wasi.wasm');
|
|
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
|
+
}
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
instance: __napiInstance,
|
|
55
|
+
module: __wasiModule,
|
|
56
|
+
napiModule: __napiModule,
|
|
57
|
+
} = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
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
|
+
};
|
|
80
|
+
|
|
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
|
+
}
|
|
93
|
+
|
|
94
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find((s) =>
|
|
95
|
+
s.toString().includes('kHandle'),
|
|
96
|
+
);
|
|
97
|
+
if (kHandle) {
|
|
98
|
+
worker[kHandle].ref = () => {};
|
|
99
|
+
}
|
|
100
|
+
|
|
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
|
+
},
|
|
121
|
+
});
|
|
122
|
+
module.exports = __napiModule.exports;
|
|
123
|
+
module.exports.Assets = __napiModule.exports.Assets;
|
|
124
|
+
module.exports.AsyncDependenciesBlock =
|
|
125
|
+
__napiModule.exports.AsyncDependenciesBlock;
|
|
126
|
+
module.exports.Chunk = __napiModule.exports.Chunk;
|
|
127
|
+
module.exports.ChunkGraph = __napiModule.exports.ChunkGraph;
|
|
128
|
+
module.exports.ChunkGroup = __napiModule.exports.ChunkGroup;
|
|
129
|
+
module.exports.Chunks = __napiModule.exports.Chunks;
|
|
130
|
+
module.exports.CodeGenerationResult = __napiModule.exports.CodeGenerationResult;
|
|
131
|
+
module.exports.CodeGenerationResults =
|
|
132
|
+
__napiModule.exports.CodeGenerationResults;
|
|
133
|
+
module.exports.ConcatenatedModule = __napiModule.exports.ConcatenatedModule;
|
|
134
|
+
module.exports.ContextModule = __napiModule.exports.ContextModule;
|
|
135
|
+
module.exports.Dependency = __napiModule.exports.Dependency;
|
|
136
|
+
module.exports.Diagnostics = __napiModule.exports.Diagnostics;
|
|
137
|
+
module.exports.EntryDataDto = __napiModule.exports.EntryDataDto;
|
|
138
|
+
module.exports.EntryDataDTO = __napiModule.exports.EntryDataDTO;
|
|
139
|
+
module.exports.EntryDependency = __napiModule.exports.EntryDependency;
|
|
140
|
+
module.exports.EntryOptionsDto = __napiModule.exports.EntryOptionsDto;
|
|
141
|
+
module.exports.EntryOptionsDTO = __napiModule.exports.EntryOptionsDTO;
|
|
142
|
+
module.exports.ExternalModule = __napiModule.exports.ExternalModule;
|
|
143
|
+
module.exports.JsCompilation = __napiModule.exports.JsCompilation;
|
|
144
|
+
module.exports.JsCompiler = __napiModule.exports.JsCompiler;
|
|
145
|
+
module.exports.JsContextModuleFactoryAfterResolveData =
|
|
146
|
+
__napiModule.exports.JsContextModuleFactoryAfterResolveData;
|
|
147
|
+
module.exports.JsContextModuleFactoryBeforeResolveData =
|
|
148
|
+
__napiModule.exports.JsContextModuleFactoryBeforeResolveData;
|
|
149
|
+
module.exports.JsCoordinator = __napiModule.exports.JsCoordinator;
|
|
150
|
+
module.exports.JsDependencies = __napiModule.exports.JsDependencies;
|
|
151
|
+
module.exports.JsEntries = __napiModule.exports.JsEntries;
|
|
152
|
+
module.exports.JsExportsInfo = __napiModule.exports.JsExportsInfo;
|
|
153
|
+
module.exports.JsModuleGraph = __napiModule.exports.JsModuleGraph;
|
|
154
|
+
module.exports.JsResolver = __napiModule.exports.JsResolver;
|
|
155
|
+
module.exports.JsResolverFactory = __napiModule.exports.JsResolverFactory;
|
|
156
|
+
module.exports.JsStats = __napiModule.exports.JsStats;
|
|
157
|
+
module.exports.KnownBuildInfo = __napiModule.exports.KnownBuildInfo;
|
|
158
|
+
module.exports.Module = __napiModule.exports.Module;
|
|
159
|
+
module.exports.ModuleGraphConnection =
|
|
160
|
+
__napiModule.exports.ModuleGraphConnection;
|
|
161
|
+
module.exports.NativeWatcher = __napiModule.exports.NativeWatcher;
|
|
162
|
+
module.exports.NativeWatchResult = __napiModule.exports.NativeWatchResult;
|
|
163
|
+
module.exports.NormalModule = __napiModule.exports.NormalModule;
|
|
164
|
+
module.exports.RawExternalItemFnCtx = __napiModule.exports.RawExternalItemFnCtx;
|
|
165
|
+
module.exports.ReadonlyResourceData = __napiModule.exports.ReadonlyResourceData;
|
|
166
|
+
module.exports.ResolverFactory = __napiModule.exports.ResolverFactory;
|
|
167
|
+
module.exports.Sources = __napiModule.exports.Sources;
|
|
168
|
+
module.exports.VirtualFileStore = __napiModule.exports.VirtualFileStore;
|
|
169
|
+
module.exports.JsVirtualFileStore = __napiModule.exports.JsVirtualFileStore;
|
|
170
|
+
module.exports.async = __napiModule.exports.async;
|
|
171
|
+
module.exports.BuiltinPluginName = __napiModule.exports.BuiltinPluginName;
|
|
172
|
+
module.exports.cleanupGlobalTrace = __napiModule.exports.cleanupGlobalTrace;
|
|
173
|
+
module.exports.EnforceExtension = __napiModule.exports.EnforceExtension;
|
|
174
|
+
module.exports.EXPECTED_RSPACK_CORE_VERSION =
|
|
175
|
+
__napiModule.exports.EXPECTED_RSPACK_CORE_VERSION;
|
|
176
|
+
module.exports.formatDiagnostic = __napiModule.exports.formatDiagnostic;
|
|
177
|
+
module.exports.JsLoaderState = __napiModule.exports.JsLoaderState;
|
|
178
|
+
module.exports.JsRspackSeverity = __napiModule.exports.JsRspackSeverity;
|
|
179
|
+
module.exports.loadBrowserslist = __napiModule.exports.loadBrowserslist;
|
|
180
|
+
module.exports.minify = __napiModule.exports.minify;
|
|
181
|
+
module.exports.minifySync = __napiModule.exports.minifySync;
|
|
182
|
+
module.exports.RawJavascriptParserCommonjsExports =
|
|
183
|
+
__napiModule.exports.RawJavascriptParserCommonjsExports;
|
|
184
|
+
module.exports.RawRuleSetConditionType =
|
|
185
|
+
__napiModule.exports.RawRuleSetConditionType;
|
|
186
|
+
module.exports.registerGlobalTrace = __napiModule.exports.registerGlobalTrace;
|
|
187
|
+
module.exports.RegisterJsTapKind = __napiModule.exports.RegisterJsTapKind;
|
|
188
|
+
module.exports.sync = __napiModule.exports.sync;
|
|
189
|
+
module.exports.syncTraceEvent = __napiModule.exports.syncTraceEvent;
|
|
190
|
+
module.exports.transform = __napiModule.exports.transform;
|
|
191
|
+
module.exports.transformSync = __napiModule.exports.transformSync;
|
|
Binary file
|
|
@@ -0,0 +1,52 @@
|
|
|
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';
|
|
8
|
+
|
|
9
|
+
const fs = createFsProxy(__memfsExported);
|
|
10
|
+
|
|
11
|
+
const errorOutputs = [];
|
|
12
|
+
|
|
13
|
+
const handler = new MessageHandler({
|
|
14
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
15
|
+
const wasi = new WASI({
|
|
16
|
+
fs,
|
|
17
|
+
preopens: {
|
|
18
|
+
'/': '/',
|
|
19
|
+
},
|
|
20
|
+
print: function () {
|
|
21
|
+
// eslint-disable-next-line no-console
|
|
22
|
+
console.log.apply(console, arguments);
|
|
23
|
+
},
|
|
24
|
+
printErr: function () {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.error.apply(console, arguments);
|
|
27
|
+
|
|
28
|
+
errorOutputs.push([...arguments]);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
32
|
+
childThread: true,
|
|
33
|
+
wasi,
|
|
34
|
+
overwriteImports(importObject) {
|
|
35
|
+
importObject.env = {
|
|
36
|
+
...importObject.env,
|
|
37
|
+
...importObject.napi,
|
|
38
|
+
...importObject.emnapi,
|
|
39
|
+
memory: wasmMemory,
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
onError(error) {
|
|
45
|
+
postMessage({ type: 'error', error, errorOutputs });
|
|
46
|
+
errorOutputs.length = 0;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
globalThis.onmessage = function (e) {
|
|
51
|
+
handler.handle(e);
|
|
52
|
+
};
|
package/wasi-worker.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
instantiateNapiModuleSync,
|
|
11
|
+
MessageHandler,
|
|
12
|
+
getDefaultContext,
|
|
13
|
+
} = require('@napi-rs/wasm-runtime');
|
|
14
|
+
|
|
15
|
+
if (parentPort) {
|
|
16
|
+
parentPort.on('message', (data) => {
|
|
17
|
+
globalThis.onmessage({ data });
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
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
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const emnapiContext = getDefaultContext();
|
|
36
|
+
|
|
37
|
+
const __rootDir = parse(process.cwd()).root;
|
|
38
|
+
|
|
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
|
+
});
|
|
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
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
globalThis.onmessage = function (e) {
|
|
66
|
+
handler.handle(e);
|
|
67
|
+
};
|