unwasm 0.4.1 → 0.5.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/dist/plugin/index.d.mts +6 -0
- package/dist/plugin/index.mjs +53 -33
- package/package.json +13 -13
package/dist/plugin/index.d.mts
CHANGED
package/dist/plugin/index.mjs
CHANGED
|
@@ -5563,16 +5563,13 @@ async function getWasmImports(asset, _opts) {
|
|
|
5563
5563
|
for (const moduleName of importNames) {
|
|
5564
5564
|
const importNames$1 = asset.imports[moduleName];
|
|
5565
5565
|
const importAlias = pkg.imports?.[moduleName] || pkg.imports?.[`#${moduleName}`];
|
|
5566
|
-
const resolved$1 = importAlias && typeof importAlias === "string" ? importAlias : resolveModulePath(moduleName, {
|
|
5567
|
-
from: asset.id,
|
|
5568
|
-
try: true
|
|
5569
|
-
});
|
|
5566
|
+
const resolved$1 = importAlias && typeof importAlias === "string" ? importAlias : resolveModulePath(moduleName, { from: asset.id });
|
|
5570
5567
|
const importName = "_imports_" + genSafeVariableName(moduleName);
|
|
5571
|
-
|
|
5568
|
+
imports.push(genImport(resolved$1, {
|
|
5572
5569
|
name: "*",
|
|
5573
5570
|
as: importName
|
|
5574
5571
|
}));
|
|
5575
|
-
importsObject[moduleName] = Object.fromEntries(importNames$1.map((name) => [name,
|
|
5572
|
+
importsObject[moduleName] = Object.fromEntries(importNames$1.map((name) => [name, `${importName}[${genString(name)}]`]));
|
|
5576
5573
|
}
|
|
5577
5574
|
return {
|
|
5578
5575
|
code: `${imports.join("\n")}\n\nconst _imports = ${genObjectFromRaw(importsObject)}`,
|
|
@@ -5784,34 +5781,57 @@ function unwasm(opts) {
|
|
|
5784
5781
|
fileName: asset.name
|
|
5785
5782
|
});
|
|
5786
5783
|
},
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
|
|
5784
|
+
load: {
|
|
5785
|
+
order: "pre",
|
|
5786
|
+
async handler(id) {
|
|
5787
|
+
if (id === UMWASM_HELPERS_ID) return getPluginUtils();
|
|
5788
|
+
if (!WASM_ID_RE.test(id)) return;
|
|
5789
|
+
const idPath = id.split("?")[0];
|
|
5790
|
+
if (!existsSync(idPath)) return;
|
|
5791
|
+
this.addWatchFile(idPath);
|
|
5792
|
+
return (await promises.readFile(idPath)).toString("binary");
|
|
5793
|
+
}
|
|
5794
5794
|
},
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5795
|
+
transform: {
|
|
5796
|
+
order: "pre",
|
|
5797
|
+
async handler(code, id) {
|
|
5798
|
+
if (!WASM_ID_RE.test(id)) return;
|
|
5799
|
+
const buff = Buffer.from(code, "binary");
|
|
5800
|
+
let isModule = id.endsWith("?module");
|
|
5801
|
+
const name = `wasm/${basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
|
|
5802
|
+
let parsed = {
|
|
5803
|
+
imports: {},
|
|
5804
|
+
exports: ["default"]
|
|
5805
|
+
};
|
|
5806
|
+
if (!isModule) try {
|
|
5807
|
+
parsed = parse(name, buff);
|
|
5808
|
+
} catch (error) {
|
|
5809
|
+
if (!opts.silent) this.warn({
|
|
5810
|
+
id,
|
|
5811
|
+
cause: error,
|
|
5812
|
+
message: "Failed to parse the WebAssembly module; falling back to module mode."
|
|
5813
|
+
});
|
|
5814
|
+
isModule = true;
|
|
5815
|
+
}
|
|
5816
|
+
const asset = assets[name] = {
|
|
5817
|
+
name,
|
|
5818
|
+
id,
|
|
5819
|
+
source: buff,
|
|
5820
|
+
imports: parsed.imports,
|
|
5821
|
+
exports: parsed.exports
|
|
5822
|
+
};
|
|
5823
|
+
return {
|
|
5824
|
+
code: isModule ? await getWasmModuleBinding(asset, opts) : await getWasmESMBinding(asset, opts).catch((error) => {
|
|
5825
|
+
if (!opts.silent) this.warn({
|
|
5826
|
+
id,
|
|
5827
|
+
cause: error,
|
|
5828
|
+
message: "Failed to load the WebAssembly module; falling back to module mode: " + error.message
|
|
5829
|
+
});
|
|
5830
|
+
return getWasmModuleBinding(asset, opts);
|
|
5831
|
+
}),
|
|
5832
|
+
map: { mappings: "" }
|
|
5833
|
+
};
|
|
5834
|
+
}
|
|
5815
5835
|
},
|
|
5816
5836
|
renderChunk(code, chunk) {
|
|
5817
5837
|
if (!opts.esmImport) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unwasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "WebAssembly tools for JavaScript",
|
|
5
5
|
"repository": "unjs/unwasm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"lint": "eslint --cache . && prettier -c src test",
|
|
25
25
|
"lint:fix": "eslint --cache . --fix && prettier -c src test -w",
|
|
26
26
|
"prepack": "pnpm build",
|
|
27
|
-
"release": "pnpm test && pnpm build && changelogen --release --publish",
|
|
27
|
+
"release": "pnpm test && pnpm build && changelogen --release --push --publish",
|
|
28
28
|
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
|
|
29
29
|
"test:types": "tsc --noEmit --skipLibCheck"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"exsolve": "^1.0.
|
|
32
|
+
"exsolve": "^1.0.8",
|
|
33
33
|
"knitwork": "^1.2.0",
|
|
34
34
|
"magic-string": "^0.30.21",
|
|
35
35
|
"mlly": "^1.8.0",
|
|
@@ -37,27 +37,27 @@
|
|
|
37
37
|
"pkg-types": "^2.3.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@prisma/client": "^6.
|
|
40
|
+
"@prisma/client": "^6.19.0",
|
|
41
41
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
42
|
-
"@types/node": "^24.10.
|
|
43
|
-
"@vitest/coverage-v8": "^4.0.
|
|
42
|
+
"@types/node": "^24.10.1",
|
|
43
|
+
"@vitest/coverage-v8": "^4.0.8",
|
|
44
44
|
"@webassemblyjs/wasm-parser": "^1.14.1",
|
|
45
45
|
"assemblyscript": "^0.28.9",
|
|
46
46
|
"automd": "^0.4.2",
|
|
47
47
|
"changelogen": "^0.6.2",
|
|
48
|
-
"esbuild": "^0.
|
|
48
|
+
"esbuild": "^0.27.0",
|
|
49
49
|
"eslint": "^9.39.1",
|
|
50
50
|
"eslint-config-unjs": "^0.5.0",
|
|
51
51
|
"exsolve": "^1.0.7",
|
|
52
52
|
"jiti": "^2.6.1",
|
|
53
|
-
"miniflare": "^4.
|
|
54
|
-
"obuild": "^0.
|
|
53
|
+
"miniflare": "^4.20251109.0",
|
|
54
|
+
"obuild": "^0.4.1",
|
|
55
55
|
"prettier": "^3.6.2",
|
|
56
|
-
"rollup": "^4.
|
|
56
|
+
"rollup": "^4.53.2",
|
|
57
57
|
"typescript": "^5.9.3",
|
|
58
|
-
"vite": "^7.
|
|
59
|
-
"vitest": "^4.0.
|
|
60
|
-
"wabt": "^1.0.
|
|
58
|
+
"vite": "^7.2.2",
|
|
59
|
+
"vitest": "^4.0.8",
|
|
60
|
+
"wabt": "^1.0.39"
|
|
61
61
|
},
|
|
62
62
|
"resolutions": {
|
|
63
63
|
"@webassemblyjs/helper-wasm-bytecode": "1.14.1",
|