Repository navigation
fix: handle npm link <package-name> in npm shim (auto-reshim) #11748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| ;; | ||
|
|
||
| -*) ;; # Skip other options | ||
|
|
||
| *) | ||
|
|
@@ -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 | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| is_global=1 | ||
| cmd_needs_reshim=true | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| fi | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 With 🤖 Prompt for AI Agents |
||
| else | ||
| exec "$node_bin" "$npm_cli" "$@" | ||
| fi | ||
| } | ||
|
|
||
| wrap_npm_if_reshim_is_needed "$@" | ||
| wrap_npm_if_reshim_is_needed "$@" | ||
Uh oh!
There was an error while loading. Please reload this page.