Skip to content

feat: prepare the browser player's module as an npm package (D76) - #176

Merged
with-developer merged 3 commits into
mainfrom
feat/npm-package
Nov 24, 2026
Merged

with-developer merged 3 commits into
mainfrom
feat/npm-package

Conversation

@with-developer

Copy link
Copy Markdown
Owner

What changes for a user, and how to revert

  • Nothing is published. No npm account, token or name was made or taken; npm publish --dry-run without a login is as far as it went. The proposed name, emberwave-web, and the first publish are the maintainer's to decide (decision D76).
  • Web developers can build the browser player's module as an npm package, with TypeScript declarations, with scripts/build_npm.sh, and install its archive (npm pack target/npm/emberwave-web --pack-destination target/npm) until it is on npm.
  • The player's page (GitHub Pages) is built with the source paths that panic messages name remapped (/cargo/..., /emberwave/... instead of the CI runner's /home/runner/...), so that its wasm and the package's are the same bytes. Nothing else about the page changes.
  • To revert, revert the merge: the scripts, the npm README, the CI steps and the docs go; nothing outside the repository changed.

Purpose

The README's 1.0 checklist lists packages, and the browser had none: a page other than the player's own could use the module only by building emberwave or copying web/pkg/ out of a build, without TypeScript declarations. This prepares the npm package, ready to publish, and stops there.

Changes

  • scripts/build_npm.sh builds the module as the pages do (wasm-bindgen --target web, now with declarations) into target/npm/emberwave-web/, with a package.json (the crate's version, "type": "module", main/module/types/exports, files, "sideEffects": false, MIT, repository, keywords; no dependencies), the package's README (crates/emberwave-web/npm/README.md) and LICENSE and THIRD_PARTY_NOTICES.md copied at build time. The package's name is NAME in the script; the script checks that the README's examples use it.
  • The wasm of a local build held 16 paths under the builder's home directory (panic messages name source files). Both build scripts now remap the home directory, cargo's sources and the repository, and build_npm.sh fails if the wasm still names one of them or the target directory. The pages' wasm and the package's are the same bytes, so cargo builds once.
  • scripts/check_npm.sh prints npm pack --dry-run, packs, installs the archive into a scratch project offline and runs scripts/check_web.mjs PROJECT_DIR, a new mode that checks the installed files are exactly the seven that ship, that type is module, that every path in main, module, types and exports exists, that exports gives the declarations first, that they declare the module's exports, and then imports the package by its name through Node's ES module resolution and runs the pages' checks on it. The pages mode is unchanged.
  • CI's wasm job runs both scripts after the pages' build. The documentation-only filter no longer counts the npm README, which ships in the package, as documentation.
  • Docs: README.md and README.ko.md (a section "In a web page" and the Packages item of the 1.0 checklist), CONTRIBUTING.md (building, checking, and the publish step after the maintainer's approval), CHANGELOG.md, ARCHITECTURE.md (the browser player section and decision D76).

npm pack --dry-run

1.1kB   LICENSE
3.4kB   README.md
1.8kB   THIRD_PARTY_NOTICES.md
551.8kB emberwave_web_bg.wasm
15.1kB  emberwave_web.d.ts
85.3kB  emberwave_web.js
1.1kB   package.json
package size: 200.4 kB, unpacked size: 659.6 kB, total files: 7

Testing

On an Apple M3 Max with rustup's stable (1.93), wasm-bindgen 0.2.129 and Node 20.19.4:

  • From a clean target/: scripts/build_npm.sh, then scripts/check_npm.sh (also with an empty npm cache), then scripts/build_web.sh and node scripts/check_web.mjs. The two wasm files are identical; the second cargo build takes 0.04 s.
  • After the pages' build, build_npm.sh takes 0.2 s and check_npm.sh about 1 s.
  • check_npm.sh fails, as it should, for packages broken by hand: without the wasm in files, without "type": "module", with a wrong main, module, exports["."].default or exports["."].types, and with exports["."] giving default before types. build_npm.sh stops with a message when Node is missing, before it builds or deletes the old package, and the guard fires on a wasm built without the remapping.
  • npm publish --dry-run without a login: no warnings about package.json.
  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, and the wasm clippy of CI.
  • Not tried: a TypeScript compiler on the declarations, a bundler (Vite, webpack), and the package in a browser.

Benchmark impact

None: no Rust or shader code changes. The remapping changes only strings in the wasm (551.8 kB against 552.1 kB). CI's wasm job gains two steps of a few seconds; until a change to Cargo.lock or the toolchain gives the cache a new key, its cache holds the wasm's dependencies built without the remapping, so the pages' build compiles them again, as it did in the last run on main (37 s).

Review

Two passes by a reviewer agent (Claude, Sonnet), each reading the commits in a separate worktree.

  • First pass, fixed in 667c201:
    • A build on a personal machine put the builder's home paths into the wasm. Fixed by remapping the paths in both scripts.
    • The check missed a missing "type": "module" (Node 20.19 forgives it), wrong main, module and exports types, and did not use Node's ES module resolution. All fixed.
    • build_npm.sh went on building when Node was missing. Fixed.
    • A pull request changing only the npm README skipped the wasm job. Fixed.
    • Docs: an archive packed into the repository's root; the 1.0 promise, which covers the C and Rust APIs, was extended to this API; "works without a bundler", which needs an import map for the bare name. All fixed.
  • First pass, withdrawn on checking: the README's packet example never sizes the canvas. wgpu's Surface::configure sets the canvas's width and height (wgpu 30.0.2, src/backend/webgpu.rs), and load and open_stream configure it. Both examples now rely on that, as the methods' docs say.
  • Second pass, fixed in 002fac1: the guard missed cargo's sources and the target directory, and would fire for a repository mounted at /emberwave; the check did not require exports to give the declarations first; D76's sizes and its note on the documentation filter.
  • Left as they are:
    • The npm README's "Install" says npm install emberwave-web without "not published yet". It is the package's page on npm, the root READMEs say the package is not published, and such a line would have to be removed by hand at the first publish.
    • The declarations carry rustdoc links such as [Player::load](crate::Player::load) from the crate's doc comments, which are right in rustdoc.
    • The cache cost noted under Benchmark impact.

Related issue

None. The README's checklist "What 1.0.0 needs", item Packages.

A web page other than the player's own could take the WebAssembly module
only by building emberwave or copying web/pkg/ out of a build, without
TypeScript declarations. scripts/build_npm.sh now builds the same module,
with the pages' wasm-bindgen target and declarations this time, into
target/npm/emberwave-web/ with a package.json at the crate's version, a
README for npm whose examples use the module's real API, and LICENSE and
THIRD_PARTY_NOTICES.md copied at build time.

scripts/check_npm.sh lists what npm pack would ship, installs the archive
into a scratch project offline and runs scripts/check_web.mjs on it there:
given a project, the check resolves the package by its name through its
exports, checks its files and declarations, and puts the module through
the same checks as the pages' module. CI's wasm job runs both after the
pages' build, which leaves cargo nothing to do.

Nothing is published and no name is taken on npm: the proposed name,
emberwave-web, and the first publish are the maintainer's (decision D76).

Claude-Session: https://claude.ai/code/session_019fJGoCTvP5e7n599q3ZQ42
A review of the npm package found that a build on a personal machine
writes the user's home directory into the wasm, through the source paths
that panic messages name: 16 of them in a local build. The package would
then publish them for good. build_npm.sh now remaps the home directory,
cargo's sources and the repository, and fails if the wasm still names the
home directory or the repository. build_web.sh uses the same flags, so
that the pages' wasm and the package's stay the same bytes and cargo
builds them once in CI.

The check now also fails for a package without "type": "module" (which
Node 20.19 forgives), for any path of main, module, types or exports
that the package does not hold, and imports the package by its name
through Node's ES module resolution. A pull request that changes only
the npm README, which ships in the package, runs the wasm job.

build_npm.sh stops with a message when it cannot read cargo's metadata
(Node missing), before it builds or deletes the old package. The READMEs
pack into target/npm, the docs no longer extend emberwave's 1.0 promise
to this API, and the npm README's examples rely on load and open_stream
sizing the canvas, as wgpu's surface configuration does.

Claude-Session: https://claude.ai/code/session_019fJGoCTvP5e7n599q3ZQ42
A second review pass found that the guard after the build greps only the
home directory and the repository, and fires on a builder whose
repository is mounted at a replacement path such as /emberwave. It now
also checks cargo's sources and the target directory, and skips a path
that is a replacement itself. The package check also requires
exports["."] to give the declarations first, as TypeScript reads the
first condition that applies, and to give the same file as "types".
D76 has the sizes of the remapped build and says that a change to the
package's README alone runs all the code jobs.

Claude-Session: https://claude.ai/code/session_019fJGoCTvP5e7n599q3ZQ42
@with-developer
with-developer merged commit a80349f into main Nov 24, 2026
15 of 16 checks passed
@with-developer
with-developer deleted the feat/npm-package branch November 24, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant