fix: discover pnpm 11 isolated global package roots - #207
Conversation
pnpm 11 installs each global package into its own isolated directory (<global>/<dir>/node_modules/<pkg>), so `pnpm root -g` no longer points at a scannable node_modules dir and `list --global` came back empty. Global detection now asks pnpm for resolved package paths via `pnpm ls -g --json --depth 0` and derives the set of node_modules roots (deduped; collapses to the single root on pnpm <= 10), keeping `pnpm root -g` plus the npm/yarn commands as fallbacks. The scanner scans every detected root, and INTENT_GLOBAL_NODE_MODULES accepts a path.delimiter-separated list of roots. Fixes TanStack#206
Scanner tests exercise temp-dir fixtures for the pnpm 11 isolated global layout (several roots via a path-list override, deduped when two roots alias the same directory) and the npm-style single global root. Unit tests cover parsePnpmGlobalLsRoots fixture output for the pnpm 11 and pnpm 10 layouts plus the INTENT_GLOBAL_NODE_MODULES path-list parsing.
📝 WalkthroughWalkthroughGlobal ChangesGlobal node_modules discovery
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant scanForIntents
participant detectGlobalNodeModules
participant nodeModules.global
participant scanTarget
participant scanNodeModulesDir
scanForIntents->>detectGlobalNodeModules: resolve global node_modules roots
detectGlobalNodeModules-->>nodeModules.global: return paths and source
nodeModules.global->>scanTarget: provide configured roots
scanTarget->>scanNodeModulesDir: scan each root
scanNodeModulesDir-->>scanForIntents: return discovered global packages
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/intent/tests/global-node-modules.test.ts (1)
138-148: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover automatic pnpm discovery.
This test sets the override, so it never exercises
pnpm ls -g --json --depth 0. Add a mocked command/shim test for parsed roots and fallback behavior.🤖 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 `@packages/intent/tests/global-node-modules.test.ts` around lines 138 - 148, Add coverage for the automatic pnpm discovery path in detectGlobalNodeModules by removing the INTENT_GLOBAL_NODE_MODULES override for that test and mocking the pnpm ls -g --json --depth 0 command or shim. Assert parsed global module roots and add a case verifying the existing fallback behavior when the command fails or returns unusable output.
🤖 Prompt for all review comments with 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.
Nitpick comments:
In `@packages/intent/tests/global-node-modules.test.ts`:
- Around line 138-148: Add coverage for the automatic pnpm discovery path in
detectGlobalNodeModules by removing the INTENT_GLOBAL_NODE_MODULES override for
that test and mocking the pnpm ls -g --json --depth 0 command or shim. Assert
parsed global module roots and add a case verifying the existing fallback
behavior when the command fails or returns unusable output.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 16610cb9-e320-4162-a4c5-4bb96c6dd2c6
📒 Files selected for processing (6)
packages/intent/src/discovery/register.tspackages/intent/src/discovery/scanner.tspackages/intent/src/shared/types.tspackages/intent/src/shared/utils.tspackages/intent/tests/global-node-modules.test.tspackages/intent/tests/scanner.test.ts
|
Please refrain from removing the PR template when submitting a PR. It is there for a reason. |
|
Sorry about that, template restored. Also added the changeset the template asks for and ran pnpm run test:pr (all targets green, including the eslint findings the type changes surfaced in staleness.test.ts, fixed in 238fcf7). |
🎯 Changes
Fixes #206, reported by @KATT.
list --global/--global-onlyfound nothing for packages installed globally with pnpm 11, while local scanning worked (packageJsonReadCount: 0in debug). pnpm 11's global layout is isolated:pnpm root -gentries are symlinks into a.pnpmvirtual store, and each package's dependencies live in additional roots inside that store rather than one flat node_modules, so single-root scanning read nothing.This teaches global discovery to resolve pnpm's isolated layout: symlinked roots are followed and the store's package roots are included as additional scan roots, while npm/yarn flat layouts keep working unchanged. Nine new tests cover multi-root global discovery with temp-dir fixtures mimicking pnpm 11's layout plus the npm flat layout (no dependency on a real global install); 12 tests fail without the fix, and the full suite has zero new failures vs main.
(Apologies for initially dropping the template.)
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
node_modulesroots.