unwasm 0.4.2 → 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.
@@ -16,6 +16,12 @@ interface UnwasmPluginOptions {
16
16
  * @default false
17
17
  */
18
18
  lazy?: boolean;
19
+ /**
20
+ * Suppress all warnings from the plugin.
21
+ *
22
+ * @default false
23
+ */
24
+ silent?: boolean;
19
25
  }
20
26
  //#endregion
21
27
  //#region src/plugin/index.d.ts
@@ -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
- if (resolved$1) imports.push(genImport(resolved$1, {
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, resolved$1 ? `${importName}[${genString(name)}]` : `() => { throw new Error(${genString(moduleName + "." + importName)} + " is not provided!")}`]));
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)}`,
@@ -5800,12 +5797,22 @@ function unwasm(opts) {
5800
5797
  async handler(code, id) {
5801
5798
  if (!WASM_ID_RE.test(id)) return;
5802
5799
  const buff = Buffer.from(code, "binary");
5803
- const isModule = id.endsWith("?module");
5800
+ let isModule = id.endsWith("?module");
5804
5801
  const name = `wasm/${basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
5805
- const parsed = isModule ? {
5806
- imports: [],
5802
+ let parsed = {
5803
+ imports: {},
5807
5804
  exports: ["default"]
5808
- } : parse(name, buff);
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
+ }
5809
5816
  const asset = assets[name] = {
5810
5817
  name,
5811
5818
  id,
@@ -5814,7 +5821,14 @@ function unwasm(opts) {
5814
5821
  exports: parsed.exports
5815
5822
  };
5816
5823
  return {
5817
- code: isModule ? await getWasmModuleBinding(asset, opts) : await getWasmESMBinding(asset, opts),
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
+ }),
5818
5832
  map: { mappings: "" }
5819
5833
  };
5820
5834
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unwasm",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "WebAssembly tools for JavaScript",
5
5
  "repository": "unjs/unwasm",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "test:types": "tsc --noEmit --skipLibCheck"
30
30
  },
31
31
  "dependencies": {
32
- "exsolve": "^1.0.7",
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.18.0",
40
+ "@prisma/client": "^6.19.0",
41
41
  "@rollup/plugin-node-resolve": "^16.0.3",
42
- "@types/node": "^24.10.0",
43
- "@vitest/coverage-v8": "^4.0.6",
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.25.12",
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.20251011.1",
54
- "obuild": "^0.3.2",
53
+ "miniflare": "^4.20251109.0",
54
+ "obuild": "^0.4.1",
55
55
  "prettier": "^3.6.2",
56
- "rollup": "^4.52.5",
56
+ "rollup": "^4.53.2",
57
57
  "typescript": "^5.9.3",
58
- "vite": "^7.1.12",
59
- "vitest": "^4.0.6",
60
- "wabt": "^1.0.38"
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",