Repository navigation
Point npm's global prefix at ~/.local instead of the read-only /usr - #657
Conversation
npm's compiled-in prefix is /usr, the read-only package store at session time, so `npm i -g` fails with ENOENT in every session carrying node or node-lts. Ship a builtin npmrc (npm's lowest-precedence config source) setting prefix=~/.local: global installs then land in a writable home location whose bin/ is already on the session PATH, and any user-level config still overrides it. Fixes gominimal/inbox#559 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGTXbdK7hgDupktNZEkALY
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour. 📝 WalkthroughWalkthroughThe Node and Node LTS packages now configure npm global installations to use Changesnpm global prefix
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change redirects npm global installs from the read-only system location to the user-writable local directory while preserving user overrides; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Fixes gominimal/inbox#559.
What
npm i -gfails withENOENT ... mkdir '/usr/lib/node_modules/...'in every session carryingnodeornode-lts: npm's compiled-in global prefix is/usr, which is the read-only package store at session time. This PR makes both packages ship a builtin npmrc (usr/lib/node_modules/npm/npmrc, npm's lowest-precedence config source) containingprefix=~/.local, and adds anpm_global_prefixregression test to each spec asserting the resolved prefix no longer points at the store.Global installs then land in
~/.local/lib/node_moduleswith executables in~/.local/bin, which is already on the session PATH (crates/sandbox2/src/config.rsin gominimal/minimal hardcodes it). Because builtin is the lowest-precedence source, any user--prefix, env var, or.npmrcstill overrides it. The file is picked up by the existingnode_modulesoutput glob; no changes to outputs or to the CLI.This matches the community workaround already circulating (varlock's sandbox guide hand-rolls
--prefix ~/.local), so that documented quirk becomes deletable.Why not
env_state_wiringAdding
NPM_CONFIG_PREFIXviaenv_state_wiring(the router's approach A on the issue) would put globals under/state/npm-global, but nothing puts a/state/*/binon the session PATH and no wiring facility exists to do so — that would require new machinery in gominimal/minimal. The builtin npmrc needs neither. If persistent-across-recreate npm globals become a want later, the state-dir approach can still be layered on top; this change doesn't foreclose it.Verification
Verified empirically in a live session carrying
node-lts(the packages weren't rebuilt locally — node is a 5x-cost build — so CI's package build + the new spec tests are the authoritative check):npm config get prefix→/usr;npm i -gfails with the issue's exact ENOENT.npm config ls -lreportsprefix = "/usr" ; overridden by builtinand resolvesprefixto/home/.local(~expands via npm's path-type config handling).npm i -g nanoidsucceeds, the executable lands at/home/.local/bin/nanoid, resolves via PATH, and runs.Notes for the reviewer
~/.local/binon PATH; a global install there now succeeds but its bins don't resolve. That is status-quo minus the ENOENT — tasks should declare packages rather than global-install.pip,gem, andcargo installfor the same read-only-store failure mode. Left out deliberately: pip and gem have user-install fallbacks npm lacks, and cargo already defaults to~/.cargo/bin. Follow-up material.🤖 Generated with Claude Code
https://claude.ai/code/session_01JGTXbdK7hgDupktNZEkALY
Summary by CodeRabbit
Bug Fixes
~/.localdirectory.Tests