Skip to content

fix(upgrade): detect npm install method from node_modules path#723

Merged
BYK merged 3 commits intomainfrom
fix/npm-install-detection
Apr 13, 2026
Merged

fix(upgrade): detect npm install method from node_modules path#723
BYK merged 3 commits intomainfrom
fix/npm-install-detection

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 13, 2026

Summary

  • Add detectPackageManagerFromPath() — a fast path-based check that detects npm/pnpm installation by examining process.argv[1] for a node_modules segment
  • Wire it into the detection cascade after Homebrew (/Cellar/) and before the DB lookup, mirroring the same authoritative-override pattern
  • Persists the detected method to SQLite so subsequent runs skip even this cheap check

Problem

When the CLI is installed via npm and run on Windows (especially via NVM/Laravel Herd), spawning npm, pnpm, bun, yarn to detect the install method fails with ENOENT because .cmd files aren't found by spawn() without shell: true. This left the method as "unknown", blocking sentry cli upgrade entirely — even though the CLI was clearly running from a node_modules directory.

Approach

Rather than fixing the Windows spawn issue (which would still be slow and fragile), add a fast path check that examines the script path for a node_modules segment — the same pattern used by the Homebrew /Cellar/ check. Cross-platform (splits on both / and \), handles Windows 8.3 short paths, and distinguishes pnpm via its .pnpm directory.

Fixes CLI-Y1

When the CLI is installed via npm/pnpm and run on Windows (especially
via NVM), spawning package manager binaries to detect the install
method fails with ENOENT because .cmd files aren't found without
shell: true. This left the method as "unknown", blocking upgrades.

Add detectPackageManagerFromPath() — a fast, authoritative check that
examines process.argv[1] for a node_modules segment. Placed in the
detection cascade after Homebrew (which uses /Cellar/) and before the
DB lookup, it overrides stale stored info and avoids subprocess calls
entirely. Detects pnpm via its .pnpm directory; defaults to npm for
other layouts.

Fixes CLI-Y1
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

Upgrade

  • Detect npm install method from node_modules path by BYK in #723
  • Add shell option on Windows for .cmd package managers by BYK in #722

Other

  • (dashboard) Remove overly restrictive dataset-display cross-validation by BYK in #720
  • (init) Remove JSON minification that breaks edit-based codemods by betegon in #719
  • (issue) Support share issue URLs by BYK in #718

Internal Changes 🔧

  • Regenerate skill files by github-actions[bot] in ca16b2ff

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-723/

Built to branch gh-pages at 2026-04-13 11:54 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1603 uncovered lines.
❌ Project coverage is 95.28%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.30%    95.28%    -0.02%
==========================================
  Files          232       232         —
  Lines        33970     33992       +22
  Branches         0         0         —
==========================================
+ Hits         32376     32389       +13
- Misses        1594      1603        +9
- Partials         0         0         —

Generated by Codecov Action

Comment thread src/lib/upgrade.ts Outdated
Comment thread src/lib/upgrade.ts
Address review feedback:
- Replace PATH_SEPARATOR_RE regex with path.sep (already imported)
- Detect bun global installs via .bun path segment
- Use join() in tests for platform-native path construction
@BYK
Copy link
Copy Markdown
Member Author

BYK commented Apr 13, 2026

Addressed both review comments in 387e801:

  1. path.sep instead of regex: Replaced PATH_SEPARATOR_RE with scriptPath.split(sep)sep was already imported from node:path. Tests now use join() for platform-native path construction.

  2. Bun detection: Added .bun segment check — bun global installs live under ~/.bun/install/global/node_modules/. Detection order is now: .pnpm → pnpm, .bun → bun, default → npm.

@BYK BYK marked this pull request as ready for review April 13, 2026 11:40
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 387e801. Configure here.

Comment thread src/lib/upgrade.ts Outdated
Comment thread src/lib/upgrade.ts
Address Cursor BugBot feedback:
- Move detectPackageManagerFromPath() to after subprocess calls in
  detectLegacyInstallationMethod() so stored yarn info is preserved
  and subprocess-based yarn detection still works on macOS/Linux
- Wrap auto-save setInstallInfo() in try-catch so a read-only DB
  doesn't crash detection after it already succeeded
- Update tests: stored info now takes priority over path detection
@BYK BYK merged commit ec08c24 into main Apr 13, 2026
26 checks passed
@BYK BYK deleted the fix/npm-install-detection branch April 13, 2026 12:07
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.

1 participant