denoland / dnt

Deno to npm package build tool.
MIT License
1.21k stars 38 forks source link

WASM file not included in dependencies #365

Open dotellie opened 7 months ago

dotellie commented 7 months ago

I'm using a Deno module that has some WASM code included (https://github.com/unyt-org/typescript-transpiler) and after running dnt, transpiler_bg.wasm is missing in the deps folder.

Working around this issue with

  async postBuild() {
    const res = await fetch(
      "https://deno.land/x/ts_transpiler@v0.0.2/js/transpiler_bg.wasm",
    );
    await Deno.writeFile(
      "npm/esm/deps/deno.land/x/ts_transpiler@v0.0.2/js/transpiler_bg.wasm",
      new Uint8Array(await res.arrayBuffer()),
    );
  }

works just fine, so I'm assuming that this could be a bug in dnt 😅

dsherret commented 7 months ago

It's unfortunately not feasible/easy for dnt to analyze this and realize that it needs to include the Wasm file:

https://github.com/unyt-org/typescript-transpiler/blob/3b41add2bc4b961b6156ae694a4852be63a91b83/js/transpiler.generated.js#L413

We're working on adding Wasm imports to Deno and that would make the .wasm file part of the module graph, in which case dnt would be able to easily include it.

For now, I'd recommend that workaround, but also check the status code to ensure it fails when it can't reach the server:

// ex. something like
if (!res.ok) {
  console.error(await res.text());
  throw new Error(`Failed downloading: ${res.statusText}`);
}
dotellie commented 7 months ago

Ah yep that makes a lot of sense. And good call on the error checking - I think I was in ugly code mode yesterday 😂 Thank you for the quick response!