Skip to content
Merged
Changes from 2 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
26 changes: 21 additions & 5 deletions src/plugins/core/assets/node_npm_shim
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ should_reshim() {

local is_global='' cmd='' cmd_needs_reshim=''
local additional_bare_cmds=()
local has_workspace_flag=false

for arg; do
case "$arg" in
-g | --global)
is_global=true
;;

--workspace=*)
# Workspace-local link: npm link <pkg> --workspace=foo
has_workspace_flag=true
;;

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
-*) ;; # Skip other options

*)
Expand All @@ -49,14 +55,20 @@ should_reshim() {
;;

link | ln)
# Workspace-local links are NOT global
if [ "$has_workspace_flag" = true ]; then
is_global=''
cmd_needs_reshim=''
# Bare link installs a global package
if ! [ "${additional_bare_cmds[0]-}" ]; then
elif ! [ "${additional_bare_cmds[0]-}" ]; then
is_global=1
cmd_needs_reshim=true
fi

# Links to directories also install a global package
if [[ "${additional_bare_cmds[0]-}" =~ [./].* && -d "${additional_bare_cmds[0]-}" ]]; then
elif [[ "${additional_bare_cmds[0]-}" =~ ^[./].* && -d "${additional_bare_cmds[0]-}" ]]; then
is_global=1
cmd_needs_reshim=true
# npm link <package-name> also installs globally (creates symlink in global node_modules)
elif [ "${additional_bare_cmds[0]-}" ]; then
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
is_global=1
cmd_needs_reshim=true
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
fi
Expand All @@ -71,12 +83,16 @@ wrap_npm_if_reshim_is_needed() {
local npm_cli="$plugin_dir/lib/node_modules/npm/bin/npm-cli.js"
local node_bin="$plugin_dir/bin/node"
if should_reshim "$@"; then
# Run npm and capture its exit code
"$node_bin" "$npm_cli" "$@"
local npm_exit=$?
printf "Reshimming mise %s...\n" "$plugin_name" >&2
mise reshim
# Return npm's exit code, not mise reshim's
return $npm_exit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
nl -ba src/plugins/core/assets/node_npm_shim | sed -n '1,105p'

Repository: jdx/mise

Length of output: 186


🏁 Script executed:

#!/usr/bin/env bash
set -u

path="src/plugins/core/assets/node_npm_shim"
if [ -f "$path" ]; then
  awk '{printf "%6d\t%s\n", NR, $0}' "$path" | sed -n '1,105p'
else
  echo "missing: $path"
fi

printf '\n--- relevant occurrences ---\n'
awk '/# Run npm and capture its exit code|mise reshim|return \$npm_exit/ {printf "%6d\t%s\n", NR, $0}' "$path"

Repository: jdx/mise

Length of output: 3542


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
script="$tmpdir/breakpoint.sh"
cat > "$script" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

run_failing_command_can_use_exit=$?
local npm_exit=$?
printf "npm_exit is empty: %s\n" "$npm_exit"
printf "run_failing_command_can_use_exit is: %s\n" "$run_failing_command_can_use_exit"
npm_cmd="$1"
"$npm_cmd" || exit $npm_cmd
local npm_exit=$?
printf "npm_exit captured: %s\n" "$npm_exit"

reshim_cmd="$2"
"$reshim_cmd"
local reshim_exit=$?
printf "npm_exit is: %s\n" "$npm_exit"
printf "reshim_exit is: %s\n" "$reshim_exit"
return "$npm_exit"
EOF
chmod +x "$script"
bash "$tmpdir/breakpoint.sh" "shopt -u nocasematch false" "shopt -u nocasematch true"
printf '"%s"\n' "$?"

Repository: jdx/mise

Length of output: 227


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
script="$tmpdir/breakpoint.sh"
cat > "$script" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

run_failing_command_can_use_exit=$?
local npm_exit=$?
printf 'run_failing_command_can_use_exit is: %s\n' "$run_failing_command_can_use_exit"
echo "line 6 reached"

npm_cmd="$1"
"$npm_cmd" || exit $npm_cmd
local npm_exit=$?
printf 'npm_exit captured: %s\n' "$npm_exit"

reshim_cmd="$2"
"$reshim_cmd" || exit $?
local reshim_exit=$?
printf 'npm_exit is: %s\n' "$npm_exit"
printf 'reshim_exit is: %s\n' "$reshim_exit"
return "$npm_exit"
EOF
chmod +x "$script"
bash "$tmpdir/breakpoint.sh" "false" "true"
printf 'final status: "%s"\n' "$?"

Repository: jdx/mise

Length of output: 227


🏁 Script executed:

#!/usr/bin/env bash
set -u

tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
script="$tmpdir/breakpoint.sh"
cat > "$script" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

run_failing_command_can_use_exit=$?
local npm_exit=$?
printf 'run_failing_command_can_use_exit is: %s\n' "$run_failing_command_can_use_exit"
echo "line 6 reached"

npm_cmd="$1"
"$npm_cmd" || exit $npm_cmd
local npm_exit=$?
printf 'npm_exit captured: %s\n' "$npm_exit"

reshim_cmd="$2"
"$reshim_cmd" || exit $?
local reshim_exit=$?
printf 'npm_exit is: %s\n' "$npm_exit"
printf 'reshim_exit is: %s\n' "$reshim_exit"
return "$npm_exit"
EOF
chmod +x "$script"
(set +e; bash "$tmpdir/breakpoint.sh" "false" "true"); printf 'final status: "%s"\n' "$?"

Repository: jdx/mise

Length of output: 245


Preserve npm’s exit status under set -e.

With set -euo pipefail, a failed npm command exits at Line 87 before npm_exit is assigned, and a failed mise reshim exits before return $npm_exit. Capture each command’s status in if/else or || lists, then return npm_exit unconditionally.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/core/assets/node_npm_shim` around lines 86 - 92, Update the npm
wrapper flow around the command invocation and reshim call so both statuses are
captured safely under set -euo pipefail using if/else or || lists. Preserve
npm’s status in npm_exit, allow mise reshim to run regardless of npm failure,
and return npm_exit unconditionally after reshim completes.

else
exec "$node_bin" "$npm_cli" "$@"
fi
}

wrap_npm_if_reshim_is_needed "$@"
wrap_npm_if_reshim_is_needed "$@"