diff --git a/modules/nodejs/install.sh b/modules/nodejs/install.sh index 0552227..86bf269 100755 --- a/modules/nodejs/install.sh +++ b/modules/nodejs/install.sh @@ -57,9 +57,11 @@ _ensure_npm_prefix() { # rewrite, not accept. (Reading the value to COMPARE is safe; we never re-emit # it — the rewrite below drops+appends rather than sed-substituting the path, # so a HOME with sed metacharacters can't break or inject the write.) + # `|| true`: an .npmrc with no prefix line (e.g. only an auth token) makes + # grep exit 1, which under pipefail + errexit would abort the module. local cur cur="$(grep -E '^[[:space:]]*prefix[[:space:]]*=' "$npmrc" | tail -1 \ - | sed -E 's/^[[:space:]]*prefix[[:space:]]*=[[:space:]]*//; s/[[:space:]]*$//')" + | sed -E 's/^[[:space:]]*prefix[[:space:]]*=[[:space:]]*//; s/[[:space:]]*$//' || true)" [[ "$cur" == "$want" ]] && return 0 fi local tmp; tmp="$(mktemp)" diff --git a/test/integration/test_install.sh b/test/integration/test_install.sh index cd55d92..66f401b 100755 --- a/test/integration/test_install.sh +++ b/test/integration/test_install.sh @@ -415,6 +415,9 @@ fi echo "" echo "--- Test: mise module + nodejs provider=mise (fixture overlay) ---" MISE_FIXTURE="${DOTFILES_DIR}/test/integration/fixtures/mise-overlay" +# An existing ~/.npmrc with no prefix line (only a registry setting) must not +# abort the nodejs module; the prefix is appended and the other line kept. +printf '//registry.example.invalid/:always-auth=true\n' >"$HOME/.npmrc" MISE_OUT="$(env -u GITHUB_TOKEN -u MISE_GITHUB_TOKEN DOTFILES_CONTENT_DIR="$MISE_FIXTURE" \ ./bin/dotfiles install --unattended mise nodejs extra-tools 2>&1)" || true assert_output_contains "mise + nodejs + overlay tool module install succeeded" "0 failed" "$MISE_OUT" @@ -463,6 +466,11 @@ if [[ "$(zsh -c 'npm config get prefix' 2>/dev/null)" == "$HOME/.local" ]]; then else fail "npm global prefix stays ~/.local under the mise provider" fi +if grep -qxF '//registry.example.invalid/:always-auth=true' "$HOME/.npmrc"; then + pass "prefix-less ~/.npmrc: existing settings preserved" +else + fail "prefix-less ~/.npmrc: existing settings preserved" +fi MISE_OUT2="$(env -u GITHUB_TOKEN -u MISE_GITHUB_TOKEN DOTFILES_CONTENT_DIR="$MISE_FIXTURE" \ ./bin/dotfiles install --unattended mise nodejs extra-tools 2>&1)" || true assert_output_contains "mise re-install is a no-op" "0 succeeded, 0 failed" "$MISE_OUT2"