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.
@@ -19,9 +19,8 @@ interface UnwasmPluginOptions {
19
19
  }
20
20
  //#endregion
21
21
  //#region src/plugin/index.d.ts
22
- declare const rollup: (opts: UnwasmPluginOptions) => Plugin;
23
- declare const _default: {
24
- rollup: (opts: UnwasmPluginOptions) => Plugin;
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, _default as default, rollup };
26
+ export { type UnwasmPluginOptions, rollup, unwasm };
@@ -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
- const unplugin = createUnplugin((opts) => {
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
- rollup: {
5764
- async resolveId(id, importer) {
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
- async load(id) {
5788
- if (id === UMWASM_HELPERS_ID) return getPluginUtils();
5789
- if (!WASM_ID_RE.test(id)) return;
5790
- const idPath = id.split("?")[0];
5791
- if (!existsSync(idPath)) return;
5792
- this.addWatchFile(idPath);
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
- async transform(code, id) {
5796
- if (!WASM_ID_RE.test(id)) return;
5797
- const buff = Buffer.from(code, "binary");
5798
- const isModule = id.endsWith("?module");
5799
- const name = `wasm/${basename(id.split("?")[0], ".wasm")}-${sha1(buff)}.wasm`;
5800
- const parsed = isModule ? {
5801
- imports: [],
5802
- exports: ["default"]
5803
- } : parse(name, buff);
5804
- const asset = assets[name] = {
5805
- name,
5806
- id,
5807
- source: buff,
5808
- imports: parsed.imports,
5809
- exports: parsed.exports
5810
- };
5811
- return {
5812
- code: isModule ? await getWasmModuleBinding(asset, opts) : await getWasmESMBinding(asset, opts),
5813
- map: { mappings: "" }
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
- const rollup = unplugin.rollup;
5848
- var plugin_default = { rollup };
5852
+ }
5853
+ /** @deprecated use unwasm export */
5854
+ const rollup = unwasm;
5849
5855
 
5850
5856
  //#endregion
5851
- export { plugin_default as default, rollup };
5857
+ export { rollup, unwasm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unwasm",
3
- "version": "0.4.0",
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 && changelogen --release && npm publish && git push --follow-tags",
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
  },