unwasm 0.3.1 → 0.3.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.cjs CHANGED
@@ -24,7 +24,7 @@ const js = String.raw;
24
24
  function getWasmBinding(asset, opts) {
25
25
  const envCode = opts.esmImport ? js`
26
26
  async function _instantiate(imports) {
27
- const _mod = await import("${UNWASM_EXTERNAL_PREFIX}${asset.id}").then(r => r.default || r);
27
+ const _mod = await import("${UNWASM_EXTERNAL_PREFIX}${asset.name}").then(r => r.default || r);
28
28
  return WebAssembly.instantiate(_mod, imports)
29
29
  }
30
30
  ` : js`
@@ -202,26 +202,24 @@ const unplugin = unplugin$1.createUnplugin((opts) => {
202
202
  if (!id.endsWith(".wasm") || !node_fs.existsSync(id)) {
203
203
  return;
204
204
  }
205
- const source = await node_fs.promises.readFile(id);
206
- const name = `wasm/${pathe.basename(id, ".wasm")}-${sha1(source)}.wasm`;
207
- const parsed = parse(name, source);
208
- assets[id] = {
205
+ this.addWatchFile(id);
206
+ const buff = await node_fs.promises.readFile(id);
207
+ return buff.toString("binary");
208
+ },
209
+ transform(code, id) {
210
+ if (!id.endsWith(".wasm")) {
211
+ return;
212
+ }
213
+ const buff = Buffer.from(code, "binary");
214
+ const name = `wasm/${pathe.basename(id, ".wasm")}-${sha1(buff)}.wasm`;
215
+ const parsed = parse(name, buff);
216
+ const asset = assets[name] = {
209
217
  name,
210
218
  id,
211
- source,
219
+ source: buff,
212
220
  imports: parsed.imports,
213
221
  exports: parsed.exports
214
222
  };
215
- return `export default "UNWASM DUMMY EXPORT";`;
216
- },
217
- transform(_code, id) {
218
- if (!id.endsWith(".wasm")) {
219
- return;
220
- }
221
- const asset = assets[id];
222
- if (!asset) {
223
- return;
224
- }
225
223
  return {
226
224
  code: getWasmBinding(asset, opts),
227
225
  map: { mappings: "" }
package/dist/plugin.mjs CHANGED
@@ -16,7 +16,7 @@ const js = String.raw;
16
16
  function getWasmBinding(asset, opts) {
17
17
  const envCode = opts.esmImport ? js`
18
18
  async function _instantiate(imports) {
19
- const _mod = await import("${UNWASM_EXTERNAL_PREFIX}${asset.id}").then(r => r.default || r);
19
+ const _mod = await import("${UNWASM_EXTERNAL_PREFIX}${asset.name}").then(r => r.default || r);
20
20
  return WebAssembly.instantiate(_mod, imports)
21
21
  }
22
22
  ` : js`
@@ -194,26 +194,24 @@ const unplugin = createUnplugin((opts) => {
194
194
  if (!id.endsWith(".wasm") || !existsSync(id)) {
195
195
  return;
196
196
  }
197
- const source = await promises.readFile(id);
198
- const name = `wasm/${basename(id, ".wasm")}-${sha1(source)}.wasm`;
199
- const parsed = parse(name, source);
200
- assets[id] = {
197
+ this.addWatchFile(id);
198
+ const buff = await promises.readFile(id);
199
+ return buff.toString("binary");
200
+ },
201
+ transform(code, id) {
202
+ if (!id.endsWith(".wasm")) {
203
+ return;
204
+ }
205
+ const buff = Buffer.from(code, "binary");
206
+ const name = `wasm/${basename(id, ".wasm")}-${sha1(buff)}.wasm`;
207
+ const parsed = parse(name, buff);
208
+ const asset = assets[name] = {
201
209
  name,
202
210
  id,
203
- source,
211
+ source: buff,
204
212
  imports: parsed.imports,
205
213
  exports: parsed.exports
206
214
  };
207
- return `export default "UNWASM DUMMY EXPORT";`;
208
- },
209
- transform(_code, id) {
210
- if (!id.endsWith(".wasm")) {
211
- return;
212
- }
213
- const asset = assets[id];
214
- if (!asset) {
215
- return;
216
- }
217
215
  return {
218
216
  code: getWasmBinding(asset, opts),
219
217
  map: { mappings: "" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unwasm",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "WebAssembly tools for JavaScript",
5
5
  "repository": "unjs/unwasm",
6
6
  "license": "MIT",