Repository navigation
feat: prepare the browser player's module as an npm package (D76) - #176
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes for a user, and how to revert
npm publish --dry-runwithout 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).scripts/build_npm.sh, and install its archive (npm pack target/npm/emberwave-web --pack-destination target/npm) until it is on npm./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.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.shbuilds the module as the pages do (wasm-bindgen --target web, now with declarations) intotarget/npm/emberwave-web/, with apackage.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) andLICENSEandTHIRD_PARTY_NOTICES.mdcopied at build time. The package's name isNAMEin the script; the script checks that the README's examples use it.build_npm.shfails 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.shprintsnpm pack --dry-run, packs, installs the archive into a scratch project offline and runsscripts/check_web.mjs PROJECT_DIR, a new mode that checks the installed files are exactly the seven that ship, thattypeismodule, that every path inmain,module,typesandexportsexists, thatexportsgives 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.npm pack --dry-runTesting
On an Apple M3 Max with rustup's stable (1.93), wasm-bindgen 0.2.129 and Node 20.19.4:
target/:scripts/build_npm.sh, thenscripts/check_npm.sh(also with an empty npm cache), thenscripts/build_web.shandnode scripts/check_web.mjs. The two wasm files are identical; the second cargo build takes 0.04 s.build_npm.shtakes 0.2 s andcheck_npm.shabout 1 s.check_npm.shfails, as it should, for packages broken by hand: without the wasm infiles, without"type": "module", with a wrongmain,module,exports["."].defaultorexports["."].types, and withexports["."]givingdefaultbeforetypes.build_npm.shstops 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-runwithout a login: no warnings aboutpackage.json.cargo fmt --check,cargo clippy --workspace --all-targets -- -D warnings, and the wasm clippy of CI.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.lockor 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 onmain(37 s).Review
Two passes by a reviewer agent (Claude, Sonnet), each reading the commits in a separate worktree.
667c201:"type": "module"(Node 20.19 forgives it), wrongmain,moduleandexportstypes, and did not use Node's ES module resolution. All fixed.build_npm.shwent on building when Node was missing. Fixed.Surface::configuresets the canvas's width and height (wgpu 30.0.2,src/backend/webgpu.rs), andloadandopen_streamconfigure it. Both examples now rely on that, as the methods' docs say.002fac1: the guard missed cargo's sources and the target directory, and would fire for a repository mounted at/emberwave; the check did not requireexportsto give the declarations first; D76's sizes and its note on the documentation filter.npm install emberwave-webwithout "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.[Player::load](crate::Player::load)from the crate's doc comments, which are right in rustdoc.Related issue
None. The README's checklist "What 1.0.0 needs", item Packages.