Repository navigation
Fix yarn 1.0.x global packages being missed (#437) - #1798
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Yarn 1.0.0 to 1.0.2 has no `yarn global dir` command, so global scans (`scan -g`, `get -g`, `rollback -g`, `vex -g`) found none of the packages installed with `yarn global add` and still reported success. When `yarn global dir` gives no answer and `yarn --version` reports 1.0.x, the global folder yarn 1.0.x itself uses is crawled instead: ~/.config/yarn/global (/usr/local/share/.config/yarn/global for root), or %LOCALAPPDATA%\Yarn\config\global on Windows. Newer yarn releases and machines without yarn behave as before. Fixes #437 Assisted-by: Claude Code:claude-opus-5-5
Yarn 1.0.x also reads `--global-folder` from .yarnrc, so a configured global folder that exists is crawled before the default one. The `yarn --version` probe now runs only when one of those folders exists, so a Yarn Berry machine (no `yarn global` at all) doesn't pay for a second yarn process on every global scan. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
The yarn 1.0.x fallback read global-folder settings from the current project, so a project .yarnrc naming an existing folder could pass a project directory off as the machine-wide yarn install. It now reads yarn's config from the same neutral directory the `yarn global dir` probe runs in. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cefc03a. Configure here.
|
Ready for review at
Generated by Claude Code |
|
Burn-down agent: labeled Ready for review at
Generated by Claude Code |
Final review briefWhat it does. Fixes #437. Yarn 1.0.0–1.0.2 has no Risk: low. It is a fallback that runs only after Look here
Verified
Changes I made: none. Open questions (non-blocking): yarn 0.x is not covered (deliberately; the supported classic range starts at 1.0.2). Auto-merge (squash) is armed, so approving sends this PR straight to the merge queue. Generated by Claude Code |
LLM Description written by Claude Code:claude-opus-5-5
Fixes #437
Summary
On a machine with yarn 1.0.0–1.0.2, global scans (
scan -g,scan -g --mode agent,get -g,rollback -g,vex -g) now findthe packages installed with
yarn global add. Before this change theyskipped every such package and still exited 0 with
status: success,so a vulnerable yarn-global tool stayed unpatched without any warning.
Root cause
get_yarn_global_prefix_with(crates/socket-patch-core/src/crawlers/npm_crawler.rs)located yarn's global packages only by running
yarn global dir. Thatsubcommand was added in yarn 1.1.0. Yarn 1.0.x prints
error Invalid subcommandand exits 1, so the probe returnedNone, andnothing else looked in yarn's global folder.
Fix
yarn global dirgives no folder, the crawler tries the foldersyarn 1.0.x would use, in order:
configured_yarn_global_folders; yarn1.0.x reads
--global-folderfrom.yarnrc).GLOBAL_MODULE_DIRECTORY(getDirectory('config')/global; checkedin the 1.0.0 and 1.0.2 tarballs). On Unix that is
<userHome>/.config/yarn/global, whereuserHomeis/usr/local/sharefor a root user not under fakeroot. On Windows,when
LOCALAPPDATAis set, it is%LOCALAPPDATA%\Yarn\config\global.That is
config, not theDatathat 1.1+ uses.node_modulesis used, and onlywhen
yarn --versionreports 1.0.x. The version is asked only aftersuch a folder is found. A Yarn Berry machine, which has no
yarn global,therefore doesn't start a second yarn process on every global scan.
Tests
crawler_npm_e2e::get_yarn_global_prefix_with_falls_back_for_yarn_1_0(Global mode never finds yarn 1.0.x global packages:
yarn global dirdoesn't exist before yarn 1.1.0, and there's no fallback #437): mocks yarn 1.0.2 (global dirfails,--version=1.0.2)over a scratch HOME. Red on main (
left: None), green withthe fix.
crawler_npm_e2e::get_yarn_global_prefix_or_falls_back_only_for_yarn_1_0:1.0.0/1.0.1/1.0.2/1.0.2-rc.1 fall back. 1.1.0, 1.22.22, 4.5.0 and no
yarn don't. A configured folder wins over the default. With no folder
present, yarn isn't asked for its version. A working
yarn global diris taken at its word.
yarnrc::tests::yarn_1_0_default_global_folder_follows_yarn_1_0_2covers the user, root, fakeroot, no-home, Windows-with-
LOCALAPPDATAand Windows-without layouts.
npm pack yarn@1.0.2), with HOME pointing at ascratch home:
yarn global direxits 1, andyarn global add left-pad@1.3.0installs into~/.config/yarn/global/node_modules.socket-patch scan -g --ecosystems npm(API stubbed out) printsFound 210 packageswith themainbinary andFound 211 packageswith this branch. The extra package is the yarn-global left-pad.
Local runs at
cefc03a:cargo fmt --all -- --checkandcargo clippy --workspace --all-features -- -D warnings: clean.cargo test -p socket-patch-core --all-features --no-fail-fast: 6908lib tests pass, plus every integration suite. Four lib tests fail:
copy_tree::relax_loop_must_not_traverse_symlinked_root,vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry,pypi_poetry::wire_write_failure_…andpypi_requirements::wire_failure_rolls_back_…. These are chmod-basedwrite-failure tests that can't fail when the sandbox runs as root, and
they don't touch the code changed here.
cargo test --workspacelocally because thesandbox ran out of disk building every CLI test binary. The change is
limited to two
socket-patch-coremodules, and CI runs the wholeworkspace.
dispatch to the binary.
Checklist:
yarn global dirdoesn't exist before yarn 1.1.0, and there's no fallback #437:get_yarn_global_prefix_with_falls_back_for_yarn_1_0(red → green), plus the two unit tests above and the real yarn 1.0.2 checkBugbot
neutral_probe_dir(), the same directory theyarn global dirprobe runs in, not from the process cwd (cefc03a). The test above now also runs from a project whose.yarnrcpoints--global-folderat an existing folder. That assertion fails on 7cacf1e and passes on cefc03a./code-review high
Fixed:
--global-folderis now honored.yarn --versionis no longer spawned on every machine whoseyarn global dirfails.Not changed:
yarn-classic-matrix) starts at 1.0.2, and I didn't verify the 0.xlayout. The gate stays at 1.0.x.
os.homedir()on Windows under MSYS, or on Unix with HOMEunset: the home comes from the same
RcLayoutthat every other yarnrc and folder lookup in
yarnrc.rsuses. Diverging here alone wouldmake this lookup inconsistent with those.
parse_yarn_dir_output:that parser trims whitespace from stdout, which is wrong for a path
socket-patch computed itself.
get_yarn_global_prefix_or: it follows the existingget_*_global_prefix_withinjection pattern that the integrationtests use.
https://claude.ai/code/session_011f9aeR8m1Cm2c7vE7U6qeH
Generated by Claude Code