unwasm 0.3.4 → 0.3.6
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.cjs +16 -10
- package/dist/plugin.mjs +16 -10
- package/dist/tools.cjs +6490 -3
- package/dist/tools.d.cts +3 -1
- package/dist/tools.d.mts +3 -1
- package/dist/tools.d.ts +3 -1
- package/dist/tools.mjs +6490 -3
- package/package.json +20 -13
package/dist/plugin.cjs
CHANGED
|
@@ -9,7 +9,6 @@ const unplugin$1 = require('unplugin');
|
|
|
9
9
|
const node_crypto = require('node:crypto');
|
|
10
10
|
const pkgTypes = require('pkg-types');
|
|
11
11
|
const tools = require('./tools.cjs');
|
|
12
|
-
require('@webassemblyjs/wasm-parser');
|
|
13
12
|
|
|
14
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
14
|
|
|
@@ -139,7 +138,7 @@ export function createLazyWasmModule(_instantiator) {
|
|
|
139
138
|
}
|
|
140
139
|
`;
|
|
141
140
|
}
|
|
142
|
-
async function getWasmImports(asset,
|
|
141
|
+
async function getWasmImports(asset, _opts) {
|
|
143
142
|
const importNames = Object.keys(asset.imports || {});
|
|
144
143
|
if (importNames.length === 0) {
|
|
145
144
|
return {
|
|
@@ -184,17 +183,21 @@ const unplugin = unplugin$1.createUnplugin((opts) => {
|
|
|
184
183
|
if (_parseCache[name]) {
|
|
185
184
|
return _parseCache[name];
|
|
186
185
|
}
|
|
187
|
-
const parsed = tools.parseWasm(source);
|
|
188
186
|
const imports = /* @__PURE__ */ Object.create(null);
|
|
189
187
|
const exports = [];
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
for (const
|
|
193
|
-
|
|
194
|
-
|
|
188
|
+
try {
|
|
189
|
+
const parsed = tools.parseWasm(source, { name });
|
|
190
|
+
for (const mod of parsed.modules) {
|
|
191
|
+
exports.push(...mod.exports.map((e) => e.name));
|
|
192
|
+
for (const imp of mod.imports) {
|
|
193
|
+
if (!imports[imp.module]) {
|
|
194
|
+
imports[imp.module] = [];
|
|
195
|
+
}
|
|
196
|
+
imports[imp.module].push(imp.name);
|
|
195
197
|
}
|
|
196
|
-
imports[imp.module].push(imp.name);
|
|
197
198
|
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.warn(`[unwasm] Failed to parse WASM module ${name}:`, error);
|
|
198
201
|
}
|
|
199
202
|
_parseCache[name] = {
|
|
200
203
|
imports,
|
|
@@ -284,7 +287,10 @@ const unplugin = unplugin$1.createUnplugin((opts) => {
|
|
|
284
287
|
if (!asset) {
|
|
285
288
|
return;
|
|
286
289
|
}
|
|
287
|
-
const nestedLevel = chunk.fileName.split("/").
|
|
290
|
+
const nestedLevel = chunk.fileName.split("/").filter(
|
|
291
|
+
Boolean
|
|
292
|
+
/* handle // */
|
|
293
|
+
).length - 1;
|
|
288
294
|
const relativeId = (nestedLevel ? "../".repeat(nestedLevel) : "./") + asset.name;
|
|
289
295
|
return {
|
|
290
296
|
relativeId,
|
package/dist/plugin.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { createUnplugin } from 'unplugin';
|
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
6
|
import { readPackageJSON } from 'pkg-types';
|
|
7
7
|
import { parseWasm } from './tools.mjs';
|
|
8
|
-
import '@webassemblyjs/wasm-parser';
|
|
9
8
|
|
|
10
9
|
const UNWASM_EXTERNAL_PREFIX = "\0unwasm:external:";
|
|
11
10
|
const UNWASM_EXTERNAL_RE = /(\0|\\0)unwasm:external:([^"']+)/gu;
|
|
@@ -131,7 +130,7 @@ export function createLazyWasmModule(_instantiator) {
|
|
|
131
130
|
}
|
|
132
131
|
`;
|
|
133
132
|
}
|
|
134
|
-
async function getWasmImports(asset,
|
|
133
|
+
async function getWasmImports(asset, _opts) {
|
|
135
134
|
const importNames = Object.keys(asset.imports || {});
|
|
136
135
|
if (importNames.length === 0) {
|
|
137
136
|
return {
|
|
@@ -176,17 +175,21 @@ const unplugin = createUnplugin((opts) => {
|
|
|
176
175
|
if (_parseCache[name]) {
|
|
177
176
|
return _parseCache[name];
|
|
178
177
|
}
|
|
179
|
-
const parsed = parseWasm(source);
|
|
180
178
|
const imports = /* @__PURE__ */ Object.create(null);
|
|
181
179
|
const exports = [];
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
for (const
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
try {
|
|
181
|
+
const parsed = parseWasm(source, { name });
|
|
182
|
+
for (const mod of parsed.modules) {
|
|
183
|
+
exports.push(...mod.exports.map((e) => e.name));
|
|
184
|
+
for (const imp of mod.imports) {
|
|
185
|
+
if (!imports[imp.module]) {
|
|
186
|
+
imports[imp.module] = [];
|
|
187
|
+
}
|
|
188
|
+
imports[imp.module].push(imp.name);
|
|
187
189
|
}
|
|
188
|
-
imports[imp.module].push(imp.name);
|
|
189
190
|
}
|
|
191
|
+
} catch (error) {
|
|
192
|
+
console.warn(`[unwasm] Failed to parse WASM module ${name}:`, error);
|
|
190
193
|
}
|
|
191
194
|
_parseCache[name] = {
|
|
192
195
|
imports,
|
|
@@ -276,7 +279,10 @@ const unplugin = createUnplugin((opts) => {
|
|
|
276
279
|
if (!asset) {
|
|
277
280
|
return;
|
|
278
281
|
}
|
|
279
|
-
const nestedLevel = chunk.fileName.split("/").
|
|
282
|
+
const nestedLevel = chunk.fileName.split("/").filter(
|
|
283
|
+
Boolean
|
|
284
|
+
/* handle // */
|
|
285
|
+
).length - 1;
|
|
280
286
|
const relativeId = (nestedLevel ? "../".repeat(nestedLevel) : "./") + asset.name;
|
|
281
287
|
return {
|
|
282
288
|
relativeId,
|