Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/nodejs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
8 changes: 8 additions & 0 deletions test/integration/test_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading