Skip to content

Publish a package which contains Emscripten generated WASM #1086

@peterhirn

Description

@peterhirn

Hi,

I'd like to dual publish (NPM, JSR) this project: https://github.com/phi-ag/argon2

Using npm compatibility this already works in Deno:

import initialize from "npm:@phi-ag/argon2@0.4.5/node";

const argon2 = await initialize();
console.log(argon2.hash("my secret password"));

I'm trying to publish using the following jsr.json

{
  "name": "@phi-ag/argon2",
  "version": "0.0.1",
  "exports": {
    ".": "./src/index.ts",
    "./node": "./src/node.ts",
    "./fetch": "./src/fetch.ts",
    "./argon2.wasm": "./src/argon2.wasm"
  },
  "publish": {
    "include": ["LICENSE", "README.md", "src/*.ts", "src/argon2.wasm"],
    "exclude": ["src/*.test.ts", "src/*.bench.ts"]
  }
}

Unfortunately this doesn't work as jsr tries to process the wasm file

$ pnpm dlx jsr publish --dry-run --allow-dirty
error: Relative import path "env" not prefixed with / or ./ or ../ and not in import map from "file:///home/peter/Projects/phi-ag/argon2/src/argon2.wasm"
    at file:///home/peter/Projects/phi-ag/argon2/src/argon2.wasm:1:77

Where env needs to be provided as import, see https://github.com/phi-ag/argon2/blob/main/src/index.ts#L156

I read the documentation on Overriding import specifiers but it's unclear if this is what I should be doing?

If I understand correctly the preferred way in Deno would be to use WebAssembly.instantiateStreaming, but how can I generate a URL which points to the wasm file on JSR?

Additionally this all needs to still work in Node.js/Bun/Workerd/etc. when using pnpm i jsr:@phi-ag/argon2 😬

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Needs Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions