fix(installer): make init.sh POSIX-compatible and stop mangling $VERSION#1578
Merged
guybedford merged 1 commit intoMay 13, 2026
Merged
Conversation
Two bugs broke `curl https://wasm-bindgen.github.io/wasm-pack/installer/init.sh -sSf | sh`: 1. The arg-parsing block introduced in 15e4f4f used bash arrays (`ORIG_ARGS=("$@")` / `"${ORIG_ARGS[@]}"`), so any non-bash POSIX shell (dash, ash, BusyBox sh) failed with a syntax error. This is issue wasm-bindgen#1527. 2. `docs/_installer/build-installer.rs` does a literal `$VERSION` -> `vX.Y.Z` text replacement on the script. Since 15e4f4f also added real `$VERSION` shell expansions (`if [ -z "$VERSION" ]`, the `case "$VERSION"`, etc.), every one of those got mangled in the published artifact, e.g. `if [ -z "v0.14.0" ]` and `VERSION="vv0.14.0"`. The runtime --version / VERSION-env override has been silently broken in every published release since. This commit: * switches the build-time placeholder to `@@WASM_PACK_VERSION@@` so it cannot collide with real shell variable references (both in init.sh and index.html). * rewrites init.sh as POSIX sh: no arrays, no `local`, scans args via `for _arg in "$@"` without consuming them so they still pass through to wasm-pack-init. * keeps the precedence: explicit `VERSION=` env > `--version X` arg > build-time baked version > "latest" (resolved via GitHub API). Verified syntax-clean and behaviourally correct under dash, /bin/sh, and bash for piped invocation (`curl ... | sh`), `sh -s -- --version X`, env override, and arg passthrough. Supersedes wasm-bindgen#1550, closes wasm-bindgen#1527.
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.
This fixes two bugs that together break
curl https://wasm-bindgen.github.io/wasm-pack/installer/init.sh -sSf | sh. Resolves #1527, supersedes #1550.The arg-parsing block introduced in 15e4f4f used bash arrays (
ORIG_ARGS=("$@")/"${ORIG_ARGS[@]}"), so any POSIX-only shell (dash, ash, BusyBox sh) failed with a syntax error — the symptom reported in #1527.While investigating, I noticed a second, latent bug:
docs/_installer/build-installer.rsdoes a literal$VERSION→vX.Y.Ztext replacement on the published script. Since 15e4f4f also added real$VERSIONshell expansions, every one of those got mangled in the published artifact. The current published init.sh contains, for example:so the runtime
--version/VERSION=override has been silently broken in every release since.This PR:
@@WASM_PACK_VERSION@@so it cannot collide with real shell variable references (init.sh and index.html updated).local, scans args viafor _arg in "$@"without consuming them so the original arg list still flows through towasm-pack-init.VERSION=env >--version Xarg > build-time baked version >"latest"(resolved via the GitHub releases API).Before (published artifact, paraphrased):
After:
Verified syntax-clean (
sh -n,dash -n,bash -n) and behaviourally correct underdash,/bin/sh, andbashfor:curl ... | sh)curl ... | sh -s -- --version XVERSION=X curl ... | sh