Skip to content

fix(installer): make init.sh POSIX-compatible and stop mangling $VERSION#1578

Merged
guybedford merged 1 commit into
wasm-bindgen:masterfrom
guybedford:fix/install-script-posix-and-version
May 13, 2026
Merged

fix(installer): make init.sh POSIX-compatible and stop mangling $VERSION#1578
guybedford merged 1 commit into
wasm-bindgen:masterfrom
guybedford:fix/install-script-posix-and-version

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

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.rs does a literal $VERSIONvX.Y.Z text replacement on the published script. Since 15e4f4f also added real $VERSION shell expansions, every one of those got mangled in the published artifact. The current published init.sh contains, for example:

if [ -z "v0.14.0" ]; then
    VERSION="latest"
fi
# ...
case "v0.14.0" in
    v*) ;;
    *) VERSION="vv0.14.0" ;;
esac

so the runtime --version / VERSION= override has been silently broken in every release since.

This PR:

  • switches the build-time placeholder to @@WASM_PACK_VERSION@@ so it cannot collide with real shell variable references (init.sh and index.html updated).
  • rewrites init.sh as POSIX sh: no arrays, no local, scans args via for _arg in "$@" without consuming them so the original arg list still flows through to wasm-pack-init.
  • preserves the intended precedence: explicit VERSION= env > --version X arg > build-time baked version > "latest" (resolved via the GitHub releases API).

Before (published artifact, paraphrased):

ORIG_ARGS=("$@")              # bash-only
# ...
set -- "${ORIG_ARGS[@]}"      # bash-only
if [ -z "v0.14.0" ]; then ... # broken by $VERSION substitution

After:

DEFAULT_VERSION="@@WASM_PACK_VERSION@@"   # replaced at build time
# ...
resolve_version() {
    if [ -n "${VERSION:-}" ]; then return; fi
    _prev=""
    for _arg in "$@"; do
        if [ "$_prev" = "--version" ]; then VERSION="$_arg"; return; fi
        _prev="$_arg"
    done
    VERSION="${DEFAULT_VERSION:-latest}"
}

Verified syntax-clean (sh -n, dash -n, bash -n) and behaviourally correct under dash, /bin/sh, and bash for:

  • piped invocation (curl ... | sh)
  • curl ... | sh -s -- --version X
  • VERSION=X curl ... | sh
  • extra non-version args passed through to the installer

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.
@guybedford guybedford merged commit a127ae2 into wasm-bindgen:master May 13, 2026
4 checks passed
@guybedford guybedford deleted the fix/install-script-posix-and-version branch May 13, 2026 21:42
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.

Install script does not work using sh, needs bash

1 participant