unwasm 0.4.0 → 0.4.2
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 +4 -5
- package/dist/plugin/index.mjs +48 -42
- package/package.json +2 -2
package/dist/plugin/index.d.mts
CHANGED
|
@@ -19,9 +19,8 @@ interface UnwasmPluginOptions {
|
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/plugin/index.d.ts
|
|
22
|
-
declare
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
22
|
+
declare function unwasm(opts: UnwasmPluginOptions): Plugin;
|
|
23
|
+
/** @deprecated use unwasm export */
|
|
24
|
+
declare const rollup: typeof unwasm;
|
|
26
25
|
//#endregion
|
|
27
|
-
export { type UnwasmPluginOptions,
|
|
26
|
+
export { type UnwasmPluginOptions, rollup, unwasm };
|
package/dist/plugin/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync, promises } from "node:fs";
|
|
2
2
|
import { basename } from "pathe";
|
|
3
3
|
import MagicString from "magic-string";
|
|
4
|
-
import { createUnplugin } from "unplugin";
|
|
5
4
|
import { createHash } from "node:crypto";
|
|
6
5
|
import { genImport, genObjectFromRaw, genSafeVariableName, genString } from "knitwork";
|
|
7
6
|
import { resolveModulePath } from "exsolve";
|
|
@@ -5733,7 +5732,7 @@ export function createLazyWasmModule(_instantiator) {
|
|
|
5733
5732
|
//#endregion
|
|
5734
5733
|
//#region src/plugin/index.ts
|
|
5735
5734
|
const WASM_ID_RE = /\.wasm\??.*$/i;
|
|
5736
|
-
|
|
5735
|
+
function unwasm(opts) {
|
|
5737
5736
|
const assets = Object.create(null);
|
|
5738
5737
|
const _parseCache = Object.create(null);
|
|
5739
5738
|
function parse(name, source) {
|
|
@@ -5760,8 +5759,9 @@ const unplugin = createUnplugin((opts) => {
|
|
|
5760
5759
|
}
|
|
5761
5760
|
return {
|
|
5762
5761
|
name: "unwasm",
|
|
5763
|
-
|
|
5764
|
-
|
|
5762
|
+
resolveId: {
|
|
5763
|
+
order: "pre",
|
|
5764
|
+
async handler(id, importer) {
|
|
5765
5765
|
if (id === UMWASM_HELPERS_ID) return id;
|
|
5766
5766
|
if (id.startsWith(UNWASM_EXTERNAL_PREFIX)) return {
|
|
5767
5767
|
id,
|
|
@@ -5775,43 +5775,49 @@ const unplugin = createUnplugin((opts) => {
|
|
|
5775
5775
|
moduleSideEffects: false
|
|
5776
5776
|
};
|
|
5777
5777
|
}
|
|
5778
|
-
},
|
|
5779
|
-
generateBundle() {
|
|
5780
|
-
if (opts.esmImport) for (const asset of Object.values(assets)) this.emitFile({
|
|
5781
|
-
type: "asset",
|
|
5782
|
-
source: asset.source,
|
|
5783
|
-
fileName: asset.name
|
|
5784
|
-
});
|
|
5785
5778
|
}
|
|
5786
5779
|
},
|
|
5787
|
-
|
|
5788
|
-
if (
|
|
5789
|
-
|
|
5790
|
-
|
|
5791
|
-
|
|
5792
|
-
|
|
5793
|
-
return (await promises.readFile(idPath)).toString("binary");
|
|
5780
|
+
generateBundle() {
|
|
5781
|
+
if (opts.esmImport) for (const asset of Object.values(assets)) this.emitFile({
|
|
5782
|
+
type: "asset",
|
|
5783
|
+
source: asset.source,
|
|
5784
|
+
fileName: asset.name
|
|
5785
|
+
});
|
|
5794
5786
|
},
|
|
5795
|
-
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5787
|
+
load: {
|
|
5788
|
+
order: "pre",
|
|
5789
|
+
async handler(id) {
|
|
5790
|
+
if (id === UMWASM_HELPERS_ID) return getPluginUtils();
|
|
5791
|
+
if (!WASM_ID_RE.test(id)) return;
|
|
5792
|
+
const idPath = id.split("?")[0];
|
|
5793
|
+
if (!existsSync(idPath)) return;
|
|
5794
|
+
this.addWatchFile(idPath);
|
|
5795
|
+
return (await promises.readFile(idPath)).toString("binary");
|
|
5796
|
+
}
|
|
5797
|
+
},
|
|
5798
|
+
transform: {
|
|
5799
|
+
order: "pre",
|
|
5800
|
+
async handler(code, id) {
|
|
5801
|
+
if (!WASM_ID_RE.test(id)) return;
|
|
5802
|
+
const buff = Buffer.from(code, "binary");
|
|
5803
|
+
const isModule = id.endsWith("?module");
|
|
5804
|
+
const name = `wasm/${basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
|
|
5805
|
+
const parsed = isModule ? {
|
|
5806
|
+
imports: [],
|
|
5807
|
+
exports: ["default"]
|
|
5808
|
+
} : parse(name, buff);
|
|
5809
|
+
const asset = assets[name] = {
|
|
5810
|
+
name,
|
|
5811
|
+
id,
|
|
5812
|
+
source: buff,
|
|
5813
|
+
imports: parsed.imports,
|
|
5814
|
+
exports: parsed.exports
|
|
5815
|
+
};
|
|
5816
|
+
return {
|
|
5817
|
+
code: isModule ? await getWasmModuleBinding(asset, opts) : await getWasmESMBinding(asset, opts),
|
|
5818
|
+
map: { mappings: "" }
|
|
5819
|
+
};
|
|
5820
|
+
}
|
|
5815
5821
|
},
|
|
5816
5822
|
renderChunk(code, chunk) {
|
|
5817
5823
|
if (!opts.esmImport) return;
|
|
@@ -5843,9 +5849,9 @@ const unplugin = createUnplugin((opts) => {
|
|
|
5843
5849
|
};
|
|
5844
5850
|
}
|
|
5845
5851
|
};
|
|
5846
|
-
}
|
|
5847
|
-
|
|
5848
|
-
|
|
5852
|
+
}
|
|
5853
|
+
/** @deprecated use unwasm export */
|
|
5854
|
+
const rollup = unwasm;
|
|
5849
5855
|
|
|
5850
5856
|
//#endregion
|
|
5851
|
-
export {
|
|
5857
|
+
export { rollup, unwasm };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unwasm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "WebAssembly tools for JavaScript",
|
|
5
5
|
"repository": "unjs/unwasm",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
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 &&
|
|
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
|
},
|