unwasm 0.3.11 → 0.4.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.
- package/README.md +21 -3
- package/dist/plugin/index.d.mts +27 -0
- package/dist/plugin/index.mjs +5851 -0
- package/dist/tools/index.d.mts +28 -0
- package/dist/tools/index.mjs +5535 -0
- package/examples/add-esmi-deps.mjs +3 -0
- package/examples/add-esmi.wasm +0 -0
- package/examples/build.mjs +14 -0
- package/package.json +25 -43
- package/dist/plugin.cjs +0 -377
- package/dist/plugin.d.cts +0 -28
- package/dist/plugin.d.mts +0 -26
- package/dist/plugin.d.ts +0 -28
- package/dist/plugin.mjs +0 -368
- package/dist/tools.cjs +0 -6598
- package/dist/tools.d.cts +0 -28
- package/dist/tools.d.mts +0 -28
- package/dist/tools.d.ts +0 -28
- package/dist/tools.mjs +0 -6596
- package/plugin.d.ts +0 -3
|
Binary file
|
package/examples/build.mjs
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import Module from "node:module";
|
|
2
4
|
import { main as asc } from "assemblyscript/asc";
|
|
3
5
|
|
|
6
|
+
const require = Module.createRequire(import.meta.url);
|
|
7
|
+
const wabt = await require("wabt")();
|
|
8
|
+
|
|
4
9
|
async function compile(name) {
|
|
5
10
|
// https://www.assemblyscript.org/compiler.html#programmatic-usage
|
|
6
11
|
const res = await asc([`${name}.asc.ts`, "-o", `${name}.wasm`], {});
|
|
@@ -14,7 +19,16 @@ async function compile(name) {
|
|
|
14
19
|
}
|
|
15
20
|
}
|
|
16
21
|
|
|
22
|
+
async function compileWat(name) {
|
|
23
|
+
const module = wabt.parseWat(`${name}.wat`, await fs.readFile(`${name}.wat`));
|
|
24
|
+
module.resolveNames();
|
|
25
|
+
const binaryOutput = module.toBinary({write_debug_names:true});
|
|
26
|
+
const binaryBuffer = binaryOutput.buffer;
|
|
27
|
+
await fs.writeFile(`${name}.wasm`, binaryBuffer);
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
process.chdir(fileURLToPath(new URL(".", import.meta.url)));
|
|
18
31
|
|
|
19
32
|
await compile("sum");
|
|
20
33
|
await compile("rand");
|
|
34
|
+
await compileWat("add-esmi");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unwasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "WebAssembly tools for JavaScript",
|
|
5
5
|
"repository": "unjs/unwasm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,36 +8,17 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
"./examples/*": "./examples/*",
|
|
11
|
-
"./plugin":
|
|
12
|
-
|
|
13
|
-
"types": "./dist/plugin.d.mts",
|
|
14
|
-
"default": "./dist/plugin.mjs"
|
|
15
|
-
},
|
|
16
|
-
"require": {
|
|
17
|
-
"types": "./dist/plugin.d.ts",
|
|
18
|
-
"default": "./dist/plugin.cjs"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"./tools": {
|
|
22
|
-
"import": {
|
|
23
|
-
"types": "./dist/tools.d.mts",
|
|
24
|
-
"default": "./dist/tools.mjs"
|
|
25
|
-
},
|
|
26
|
-
"require": {
|
|
27
|
-
"types": "./dist/tools.d.ts",
|
|
28
|
-
"default": "./dist/tools.cjs"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
11
|
+
"./plugin": "./dist/plugin/index.mjs",
|
|
12
|
+
"./tools": "./dist/tools/index.mjs"
|
|
31
13
|
},
|
|
32
14
|
"files": [
|
|
33
15
|
"dist",
|
|
34
|
-
"*.d.ts",
|
|
35
16
|
"examples/*.wasm",
|
|
36
17
|
"examples/package.json",
|
|
37
18
|
"examples/*.mjs"
|
|
38
19
|
],
|
|
39
20
|
"scripts": {
|
|
40
|
-
"build": "
|
|
21
|
+
"build": "obuild && pnpm build:examples",
|
|
41
22
|
"build:examples": "node ./examples/build.mjs",
|
|
42
23
|
"dev": "vitest dev",
|
|
43
24
|
"lint": "eslint --cache . && prettier -c src test",
|
|
@@ -48,34 +29,35 @@
|
|
|
48
29
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
49
30
|
},
|
|
50
31
|
"dependencies": {
|
|
32
|
+
"exsolve": "^1.0.7",
|
|
51
33
|
"knitwork": "^1.2.0",
|
|
52
|
-
"magic-string": "^0.30.
|
|
53
|
-
"mlly": "^1.
|
|
34
|
+
"magic-string": "^0.30.21",
|
|
35
|
+
"mlly": "^1.8.0",
|
|
54
36
|
"pathe": "^2.0.3",
|
|
55
|
-
"pkg-types": "^2.
|
|
56
|
-
"unplugin": "^2.3.6"
|
|
37
|
+
"pkg-types": "^2.3.0"
|
|
57
38
|
},
|
|
58
39
|
"devDependencies": {
|
|
59
|
-
"@prisma/client": "^6.
|
|
60
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
61
|
-
"@types/node": "^24.
|
|
62
|
-
"@vitest/coverage-v8": "^
|
|
40
|
+
"@prisma/client": "^6.18.0",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
42
|
+
"@types/node": "^24.10.0",
|
|
43
|
+
"@vitest/coverage-v8": "^4.0.6",
|
|
63
44
|
"@webassemblyjs/wasm-parser": "^1.14.1",
|
|
64
|
-
"assemblyscript": "^0.28.
|
|
65
|
-
"automd": "^0.4.
|
|
45
|
+
"assemblyscript": "^0.28.9",
|
|
46
|
+
"automd": "^0.4.2",
|
|
66
47
|
"changelogen": "^0.6.2",
|
|
67
|
-
"esbuild": "^0.25.
|
|
68
|
-
"eslint": "^9.
|
|
48
|
+
"esbuild": "^0.25.12",
|
|
49
|
+
"eslint": "^9.39.1",
|
|
69
50
|
"eslint-config-unjs": "^0.5.0",
|
|
70
51
|
"exsolve": "^1.0.7",
|
|
71
|
-
"jiti": "^2.
|
|
72
|
-
"miniflare": "^4.
|
|
52
|
+
"jiti": "^2.6.1",
|
|
53
|
+
"miniflare": "^4.20251011.1",
|
|
54
|
+
"obuild": "^0.3.2",
|
|
73
55
|
"prettier": "^3.6.2",
|
|
74
|
-
"rollup": "^4.
|
|
75
|
-
"typescript": "^5.9.
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
56
|
+
"rollup": "^4.52.5",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vite": "^7.1.12",
|
|
59
|
+
"vitest": "^4.0.6",
|
|
60
|
+
"wabt": "^1.0.38"
|
|
79
61
|
},
|
|
80
62
|
"resolutions": {
|
|
81
63
|
"@webassemblyjs/helper-wasm-bytecode": "1.14.1",
|
|
@@ -83,5 +65,5 @@
|
|
|
83
65
|
"@webassemblyjs/leb128": "1.14.1",
|
|
84
66
|
"@webassemblyjs/utf8": "1.14.1"
|
|
85
67
|
},
|
|
86
|
-
"packageManager": "pnpm@10.
|
|
68
|
+
"packageManager": "pnpm@10.20.0"
|
|
87
69
|
}
|
package/dist/plugin.cjs
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const node_fs = require('node:fs');
|
|
6
|
-
const pathe = require('pathe');
|
|
7
|
-
const MagicString = require('magic-string');
|
|
8
|
-
const unplugin$1 = require('unplugin');
|
|
9
|
-
const node_crypto = require('node:crypto');
|
|
10
|
-
const knitwork = require('knitwork');
|
|
11
|
-
const tools = require('./tools.cjs');
|
|
12
|
-
|
|
13
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
14
|
-
|
|
15
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
16
|
-
|
|
17
|
-
const UNWASM_EXTERNAL_PREFIX = "\0unwasm:external:";
|
|
18
|
-
const UNWASM_EXTERNAL_RE = /(\0|\\0)unwasm:external:([^"']+)/gu;
|
|
19
|
-
const UMWASM_HELPERS_ID = "\0unwasm:helpers";
|
|
20
|
-
function sha1(source) {
|
|
21
|
-
return node_crypto.createHash("sha1").update(source).digest("hex").slice(0, 16);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function getWasmImports(asset, _opts) {
|
|
25
|
-
const importNames = Object.keys(asset.imports || {});
|
|
26
|
-
if (importNames.length === 0) {
|
|
27
|
-
return {
|
|
28
|
-
code: "const _imports = { /* no imports */ }",
|
|
29
|
-
resolved: true
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const { readPackageJSON } = await import('pkg-types');
|
|
33
|
-
const pkgJSON = await readPackageJSON(asset.id);
|
|
34
|
-
let resolved = true;
|
|
35
|
-
const imports = [];
|
|
36
|
-
const importsObject = {};
|
|
37
|
-
for (const moduleName of importNames) {
|
|
38
|
-
const importNames2 = asset.imports[moduleName];
|
|
39
|
-
const pkgImport = pkgJSON.imports?.[moduleName] || pkgJSON.imports?.[`#${moduleName}`];
|
|
40
|
-
const importName = "_imports_" + knitwork.genSafeVariableName(moduleName);
|
|
41
|
-
if (pkgImport && typeof pkgImport === "string") {
|
|
42
|
-
imports.push(knitwork.genImport(pkgImport, { name: "*", as: importName }));
|
|
43
|
-
} else {
|
|
44
|
-
resolved = false;
|
|
45
|
-
}
|
|
46
|
-
importsObject[moduleName] = Object.fromEntries(
|
|
47
|
-
importNames2.map((name) => [
|
|
48
|
-
name,
|
|
49
|
-
pkgImport ? `${importName}[${knitwork.genString(name)}]` : `() => { throw new Error(${knitwork.genString(moduleName + "." + importName)} + " is not provided!")}`
|
|
50
|
-
])
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
const code = `${imports.join("\n")}
|
|
54
|
-
|
|
55
|
-
const _imports = ${knitwork.genObjectFromRaw(importsObject)}`;
|
|
56
|
-
return {
|
|
57
|
-
code,
|
|
58
|
-
resolved
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function getWasmESMBinding(asset, opts) {
|
|
63
|
-
const autoImports = await getWasmImports(asset);
|
|
64
|
-
const instantiateCode = opts.esmImport ? getESMImportInstantiate(asset, autoImports.code) : getBase64Instantiate(asset, autoImports.code);
|
|
65
|
-
return opts.lazy !== true && autoImports.resolved ? getExports(asset, instantiateCode) : getLazyExports(asset, instantiateCode);
|
|
66
|
-
}
|
|
67
|
-
function getWasmModuleBinding(asset, opts) {
|
|
68
|
-
return opts.esmImport ? (
|
|
69
|
-
/* js */
|
|
70
|
-
`
|
|
71
|
-
const _mod = ${opts.lazy === true ? "" : `await`} import("${UNWASM_EXTERNAL_PREFIX}${asset.name}").then(r => r.default || r);
|
|
72
|
-
export default _mod;
|
|
73
|
-
`
|
|
74
|
-
) : (
|
|
75
|
-
/* js */
|
|
76
|
-
`
|
|
77
|
-
import { base64ToUint8Array } from "${UMWASM_HELPERS_ID}";
|
|
78
|
-
const _data = base64ToUint8Array("${asset.source.toString("base64")}");
|
|
79
|
-
const _mod = new WebAssembly.Module(_data);
|
|
80
|
-
export default _mod;
|
|
81
|
-
`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
function getESMImportInstantiate(asset, importsCode) {
|
|
85
|
-
return (
|
|
86
|
-
/* js */
|
|
87
|
-
`
|
|
88
|
-
${importsCode}
|
|
89
|
-
|
|
90
|
-
async function _instantiate(imports = _imports) {
|
|
91
|
-
const _mod = await import("${UNWASM_EXTERNAL_PREFIX}${asset.name}").then(r => r.default || r);
|
|
92
|
-
return WebAssembly.instantiate(_mod, imports)
|
|
93
|
-
}
|
|
94
|
-
`
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
function getBase64Instantiate(asset, importsCode) {
|
|
98
|
-
return (
|
|
99
|
-
/* js */
|
|
100
|
-
`
|
|
101
|
-
import { base64ToUint8Array } from "${UMWASM_HELPERS_ID}";
|
|
102
|
-
|
|
103
|
-
${importsCode}
|
|
104
|
-
|
|
105
|
-
function _instantiate(imports = _imports) {
|
|
106
|
-
const _data = base64ToUint8Array("${asset.source.toString("base64")}")
|
|
107
|
-
return WebAssembly.instantiate(_data, imports) }
|
|
108
|
-
`
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
function getExports(asset, instantiateCode) {
|
|
112
|
-
return (
|
|
113
|
-
/* js */
|
|
114
|
-
`
|
|
115
|
-
import { getExports } from "${UMWASM_HELPERS_ID}";
|
|
116
|
-
|
|
117
|
-
${instantiateCode}
|
|
118
|
-
|
|
119
|
-
const $exports = getExports(await _instantiate());
|
|
120
|
-
|
|
121
|
-
${asset.exports.map((name) => `export const ${name} = $exports.${name};`).join("\n")}
|
|
122
|
-
|
|
123
|
-
const defaultExport = () => $exports;
|
|
124
|
-
${asset.exports.map((name) => `defaultExport["${name}"] = $exports.${name};`).join("\n")}
|
|
125
|
-
export default defaultExport;
|
|
126
|
-
`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
function getLazyExports(asset, instantiateCode) {
|
|
130
|
-
return (
|
|
131
|
-
/* js */
|
|
132
|
-
`
|
|
133
|
-
import { createLazyWasmModule } from "${UMWASM_HELPERS_ID}";
|
|
134
|
-
|
|
135
|
-
${instantiateCode}
|
|
136
|
-
|
|
137
|
-
const _mod = createLazyWasmModule(_instantiate);
|
|
138
|
-
|
|
139
|
-
${asset.exports.map((name) => `export const ${name} = _mod.${name};`).join("\n")}
|
|
140
|
-
|
|
141
|
-
export default _mod;
|
|
142
|
-
`
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function getPluginUtils() {
|
|
147
|
-
return (
|
|
148
|
-
/* js */
|
|
149
|
-
`
|
|
150
|
-
export function debug(...args) {
|
|
151
|
-
console.log('[unwasm] [debug]', ...args);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function getExports(input) {
|
|
155
|
-
return input?.instance?.exports || input?.exports || input;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function base64ToUint8Array(str) {
|
|
159
|
-
const data = atob(str);
|
|
160
|
-
const size = data.length;
|
|
161
|
-
const bytes = new Uint8Array(size);
|
|
162
|
-
for (let i = 0; i < size; i++) {
|
|
163
|
-
bytes[i] = data.charCodeAt(i);
|
|
164
|
-
}
|
|
165
|
-
return bytes;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function createLazyWasmModule(_instantiator) {
|
|
169
|
-
const _exports = Object.create(null);
|
|
170
|
-
let _loaded;
|
|
171
|
-
let _promise;
|
|
172
|
-
|
|
173
|
-
const init = (imports) => {
|
|
174
|
-
if (_loaded) {
|
|
175
|
-
return Promise.resolve(exportsProxy);
|
|
176
|
-
}
|
|
177
|
-
if (_promise) {
|
|
178
|
-
return _promise;
|
|
179
|
-
}
|
|
180
|
-
return _promise = _instantiator(imports)
|
|
181
|
-
.then(r => {
|
|
182
|
-
Object.assign(_exports, getExports(r));
|
|
183
|
-
_loaded = true;
|
|
184
|
-
_promise = undefined;
|
|
185
|
-
return exportsProxy;
|
|
186
|
-
})
|
|
187
|
-
.catch(error => {
|
|
188
|
-
_promise = undefined;
|
|
189
|
-
console.error('[wasm] [error]', error);
|
|
190
|
-
throw error;
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const exportsProxy = new Proxy(_exports, {
|
|
195
|
-
get(_, prop) {
|
|
196
|
-
if (_loaded) {
|
|
197
|
-
return _exports[prop];
|
|
198
|
-
}
|
|
199
|
-
return (...args) => {
|
|
200
|
-
return _loaded
|
|
201
|
-
? _exports[prop]?.(...args)
|
|
202
|
-
: init().then(() => _exports[prop]?.(...args));
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const lazyProxy = new Proxy(() => {}, {
|
|
209
|
-
get(_, prop) {
|
|
210
|
-
return exportsProxy[prop];
|
|
211
|
-
},
|
|
212
|
-
apply(_, __, args) {
|
|
213
|
-
return init(args[0])
|
|
214
|
-
},
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
return lazyProxy;
|
|
218
|
-
}
|
|
219
|
-
`
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const WASM_ID_RE = /\.wasm\??.*$/i;
|
|
224
|
-
const unplugin = unplugin$1.createUnplugin((opts) => {
|
|
225
|
-
const assets = /* @__PURE__ */ Object.create(null);
|
|
226
|
-
const _parseCache = /* @__PURE__ */ Object.create(null);
|
|
227
|
-
function parse(name, source) {
|
|
228
|
-
if (_parseCache[name]) {
|
|
229
|
-
return _parseCache[name];
|
|
230
|
-
}
|
|
231
|
-
const imports = /* @__PURE__ */ Object.create(null);
|
|
232
|
-
const exports = [];
|
|
233
|
-
try {
|
|
234
|
-
const parsed = tools.parseWasm(source, { name });
|
|
235
|
-
for (const mod of parsed.modules) {
|
|
236
|
-
exports.push(...mod.exports.map((e) => e.name));
|
|
237
|
-
for (const imp of mod.imports) {
|
|
238
|
-
if (!imports[imp.module]) {
|
|
239
|
-
imports[imp.module] = [];
|
|
240
|
-
}
|
|
241
|
-
imports[imp.module].push(imp.name);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} catch (error) {
|
|
245
|
-
console.warn(`[unwasm] Failed to parse WASM module ${name}:`, error);
|
|
246
|
-
}
|
|
247
|
-
_parseCache[name] = {
|
|
248
|
-
imports,
|
|
249
|
-
exports
|
|
250
|
-
};
|
|
251
|
-
return _parseCache[name];
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
name: "unwasm",
|
|
255
|
-
rollup: {
|
|
256
|
-
async resolveId(id, importer) {
|
|
257
|
-
if (id === UMWASM_HELPERS_ID) {
|
|
258
|
-
return id;
|
|
259
|
-
}
|
|
260
|
-
if (id.startsWith(UNWASM_EXTERNAL_PREFIX)) {
|
|
261
|
-
return {
|
|
262
|
-
id,
|
|
263
|
-
external: true
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
if (WASM_ID_RE.test(id)) {
|
|
267
|
-
const r = await this.resolve(id, importer, { skipSelf: true });
|
|
268
|
-
if (r?.id && r.id !== id) {
|
|
269
|
-
return {
|
|
270
|
-
id: r.id.startsWith("file://") ? r.id.slice(7) : r.id,
|
|
271
|
-
external: false,
|
|
272
|
-
moduleSideEffects: false
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
generateBundle() {
|
|
278
|
-
if (opts.esmImport) {
|
|
279
|
-
for (const asset of Object.values(assets)) {
|
|
280
|
-
this.emitFile({
|
|
281
|
-
type: "asset",
|
|
282
|
-
source: asset.source,
|
|
283
|
-
fileName: asset.name
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
async load(id) {
|
|
290
|
-
if (id === UMWASM_HELPERS_ID) {
|
|
291
|
-
return getPluginUtils();
|
|
292
|
-
}
|
|
293
|
-
if (!WASM_ID_RE.test(id)) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const idPath = id.split("?")[0];
|
|
297
|
-
if (!node_fs.existsSync(idPath)) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
this.addWatchFile(idPath);
|
|
301
|
-
const buff = await node_fs.promises.readFile(idPath);
|
|
302
|
-
return buff.toString("binary");
|
|
303
|
-
},
|
|
304
|
-
async transform(code, id) {
|
|
305
|
-
if (!WASM_ID_RE.test(id)) {
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
const buff = Buffer.from(code, "binary");
|
|
309
|
-
const isModule = id.endsWith("?module");
|
|
310
|
-
const name = `wasm/${pathe.basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
|
|
311
|
-
const parsed = isModule ? { imports: [], exports: ["default"] } : parse(name, buff);
|
|
312
|
-
const asset = assets[name] = {
|
|
313
|
-
name,
|
|
314
|
-
id,
|
|
315
|
-
source: buff,
|
|
316
|
-
imports: parsed.imports,
|
|
317
|
-
exports: parsed.exports
|
|
318
|
-
};
|
|
319
|
-
return {
|
|
320
|
-
code: isModule ? await getWasmModuleBinding(asset, opts) : await getWasmESMBinding(asset, opts),
|
|
321
|
-
map: { mappings: "" }
|
|
322
|
-
};
|
|
323
|
-
},
|
|
324
|
-
renderChunk(code, chunk) {
|
|
325
|
-
if (!opts.esmImport) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (!(chunk.moduleIds.some((id) => WASM_ID_RE.test(id)) || chunk.imports.some((id) => WASM_ID_RE.test(id)))) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const s = new MagicString__default(code);
|
|
332
|
-
const resolveImport = (id) => {
|
|
333
|
-
if (typeof id !== "string") {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const asset = assets[id];
|
|
337
|
-
if (!asset) {
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
const nestedLevel = chunk.fileName.split("/").filter(
|
|
341
|
-
Boolean
|
|
342
|
-
/* handle // */
|
|
343
|
-
).length - 1;
|
|
344
|
-
const relativeId = (nestedLevel ? "../".repeat(nestedLevel) : "./") + asset.name;
|
|
345
|
-
return {
|
|
346
|
-
relativeId,
|
|
347
|
-
asset
|
|
348
|
-
};
|
|
349
|
-
};
|
|
350
|
-
for (const match of code.matchAll(UNWASM_EXTERNAL_RE)) {
|
|
351
|
-
const resolved = resolveImport(match[2]);
|
|
352
|
-
const index = match.index;
|
|
353
|
-
const len = match[0].length;
|
|
354
|
-
if (!resolved || !index) {
|
|
355
|
-
console.warn(
|
|
356
|
-
`Failed to resolve WASM import: ${JSON.stringify(match[1])}`
|
|
357
|
-
);
|
|
358
|
-
continue;
|
|
359
|
-
}
|
|
360
|
-
s.overwrite(index, index + len, resolved.relativeId);
|
|
361
|
-
}
|
|
362
|
-
if (s.hasChanged()) {
|
|
363
|
-
return {
|
|
364
|
-
code: s.toString(),
|
|
365
|
-
map: s.generateMap({ includeContent: true })
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
});
|
|
371
|
-
const rollup = unplugin.rollup;
|
|
372
|
-
const index = {
|
|
373
|
-
rollup
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
exports.default = index;
|
|
377
|
-
exports.rollup = rollup;
|
package/dist/plugin.d.cts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
|
|
3
|
-
interface UnwasmPluginOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Directly import the `.wasm` files instead of bundling as base64 string.
|
|
6
|
-
*
|
|
7
|
-
* @default false
|
|
8
|
-
*/
|
|
9
|
-
esmImport?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Avoid using top level await and always use a proxy.
|
|
12
|
-
*
|
|
13
|
-
* Useful for compatibility with environments that don't support top level await.
|
|
14
|
-
*
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
lazy?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare const rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
21
|
-
declare const _default: {
|
|
22
|
-
rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
export = _default;
|
|
27
|
-
export { rollup };
|
|
28
|
-
export type { UnwasmPluginOptions };
|
package/dist/plugin.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
|
|
3
|
-
interface UnwasmPluginOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Directly import the `.wasm` files instead of bundling as base64 string.
|
|
6
|
-
*
|
|
7
|
-
* @default false
|
|
8
|
-
*/
|
|
9
|
-
esmImport?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Avoid using top level await and always use a proxy.
|
|
12
|
-
*
|
|
13
|
-
* Useful for compatibility with environments that don't support top level await.
|
|
14
|
-
*
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
lazy?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare const rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
21
|
-
declare const _default: {
|
|
22
|
-
rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export { _default as default, rollup };
|
|
26
|
-
export type { UnwasmPluginOptions };
|
package/dist/plugin.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'rollup';
|
|
2
|
-
|
|
3
|
-
interface UnwasmPluginOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Directly import the `.wasm` files instead of bundling as base64 string.
|
|
6
|
-
*
|
|
7
|
-
* @default false
|
|
8
|
-
*/
|
|
9
|
-
esmImport?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Avoid using top level await and always use a proxy.
|
|
12
|
-
*
|
|
13
|
-
* Useful for compatibility with environments that don't support top level await.
|
|
14
|
-
*
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
lazy?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare const rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
21
|
-
declare const _default: {
|
|
22
|
-
rollup: (opts: UnwasmPluginOptions) => Plugin;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
export = _default;
|
|
27
|
-
export { rollup };
|
|
28
|
-
export type { UnwasmPluginOptions };
|