Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ The route is taken only when **all** of these hold; otherwise the run takes the

**pnpm per-member locks (#492)**: a workspace whose root `pnpm-workspace.yaml` sets `sharedWorkspaceLockfile: false` (or, when the YAML leaves the key unset, whose root `.npmrc` sets `shared-workspace-lockfile=false`; on disk, when neither file sets it, `pnpm_config_shared_workspace_lockfile` on pnpm 11 and newer, `npm_config_shared_workspace_lockfile` on pnpm 10 and older, either when the major is unknown (#1460, the major as for the `lockfile` setting below); booleans in any letter case, as pnpm's YAML reader takes them) installs each member from the member's own `pnpm-lock.yaml`. Run from the workspace root, hosted mode reads every member lock the `packages:` globs name (quoted `!` negations applied; `node_modules`, `bower_components`, `test` and `tests` trees and symlinked directories skipped) beside the root lock, which may be absent (pnpm 7): each is rewritten like the root lock, a 9.0 member lock engages the `trustLockfile: true` auto-config in the ROOT `pnpm-workspace.yaml` (heal-on-rerun included), and discovery (`list`, `vex`, `rollback`, `remove`) reads the same member locks. A root lock whose `importers:` lists a member is a shared lock, so member locks beside it are stale and never read or attested. When the members' locks cannot be listed or read (no `packages:` key, whose pnpm <= 8 default finds projects in every directory; a `packages:` value that is not a plain list of globs; no member lock and no root lock, or a member lock that exists but is not readable text), every pnpm lock (the root's included) is left untouched and the run warns `redirect_pnpm_member_locks_unresolved` instead of `redirect_pnpm_no_lockfile`; no pnpm pin is confirmed. The lockfile inventory reads the same member locks, so their dependencies are discovered without an installed tree. The in-memory engine gives the same result as a disk run from the workspace root: a directory whose `pnpm-lock.yaml` has no `pnpm-workspace.yaml` beside it is a workspace member, never a root of its own, when (with `npm` among the `ecosystems`) the nearest ancestor `pnpm-workspace.yaml` is readable and its `packages:` globs (read as above, no braces, classes or extglobs) list it, it holds a `package.json` / `package.yaml` / `package.json5`, the workspace root installs it from its own lock (`sharedWorkspaceLockfile: false` with the member list resolved) or from a root lock beside which its lock is a stale leftover, and socket.yml admits the workspace root. Its lock is then demoted into that workspace root, which becomes a root even with no lock of its own (pnpm 7), the way a Cargo member's lock is demoted; the member stays a root only when it holds another lock marker, without its pnpm lock. The workspace root then pins (or refuses) its member locks as above, trusts them in its own file, refuses a member's branch lock (#556) and leaves a member lock beside a shared root lock unread. A directory that fails any of those tests keeps its lock as a root of its own (pinned like any root, or refused with `redirect_pnpm_settings_elsewhere` while the trust auto-config is on and the ancestor file may list it). Path selection adds the workspace root above every candidate to `roots`, fetches it, and fetches the member locks, branch locks and manifests below it in every directory holding a package manifest; given those `roots` as `projectRoots`, the session drops a confirmed member named beside its workspace root (unless it holds another lock) and a lockless workspace root that pins no member, so it runs the roots it would detect. A confirmed member named in `projectRoots` without its workspace root is not pinned: its lock is dropped and the run-level `pnpm_member_lock_ignored` warning names the workspace root to scan.

**pnpm with its lockfile off (#1074)**: pnpm's `lockfile` setting off makes pnpm neither read nor write `pnpm-lock.yaml` (nor a member's own lock): it resolves every dependency from the registry, so a hosted pin in a committed lock never installs. Each pnpm major reads the setting from one file: pnpm 11 and newer a top-level `lockfile: false` in the project's `pnpm-workspace.yaml`, pnpm 10 and older `lockfile=false` in its `.npmrc`; when `lockfile` is unset (or not a boolean) pnpm falls back to npm's `package-lock` (`packageLock: false` / `package-lock=false`), which counts the same way. The major is the one `node_modules/.modules.yaml` records, else package.json's `packageManager` pin, else what the root lock's grammar implies (a pre-9 lock or `shrinkwrap.yaml`: pnpm 8 or older; an env lockfile document: pnpm 11 or newer); when none says, either file turning it off counts. Hosted mode also reads the setting from its environment, in the one variable family that major reads (#1460): `pnpm_config_lockfile` / `pnpm_config_package_lock` on pnpm 11 and newer, `npm_config_lockfile` / `npm_config_package_lock` on pnpm 10 and older, either family when the major is unknown (so the `npm_config_package_lock=` that `npx` / `npm exec` export from an npm-era `.npmrc` refuses nothing on pnpm 11+). Only the project's own files are read (a workspace member with no settings file of its own does not inherit its root's). In a pnpm project (a root pnpm lock or a `pnpm-workspace.yaml`), hosted mode then leaves every pnpm lock and `pnpm-workspace.yaml` untouched (no `trustLockfile` key is added), confirms no npm pin from them and warns `redirect_pnpm_lockfile_disabled` (in place of `redirect_pnpm_no_lockfile`), exiting 0 like the per-branch lock refusal below; the detail names the setting, and the remedy is `--mode vendored` when a pnpm lock exists (pnpm applies the `overrides` it wires without a lock), else removing the setting and running `pnpm install`. The check comes before the per-branch lock check. Manifest-less `vex` keeps the hosted references of such a lock but withholds their lockfile basis (see the pnpm row of the discovery table). Rush locks are not affected: Rush runs pnpm with its own settings. Vendored mode is unchanged. `vex` attests a vendored reference of such a lock only while the override map the governing pnpm reads without a lock routes the package (`name@version` or bare `name`) to the same artifact: package.json `pnpm.overrides` when `.npmrc` turns the lock off (pnpm 10 and older; a pinned pnpm 10 also reads the `pnpm-workspace.yaml` map), `pnpm-workspace.yaml` `overrides` when that file does (pnpm 11 and newer never read `pnpm.overrides`), both when both do and no major is known. Otherwise pnpm installs the registry release and the patch is omitted (`vex_lock_not_read`, see **Locks the package manager is told not to read**).
**pnpm with its lockfile off (#1074)**: pnpm's `lockfile` setting off makes pnpm neither read nor write `pnpm-lock.yaml` (nor a member's own lock): it resolves every dependency from the registry, so a hosted pin in a committed lock never installs. Each pnpm major reads the setting from one file: pnpm 11 and newer a top-level `lockfile: false` in the project's `pnpm-workspace.yaml`, pnpm 10 and older `lockfile=false` in its `.npmrc`; when `lockfile` is unset (or not a boolean) pnpm falls back to npm's `package-lock` (`packageLock: false` / `package-lock=false`), which counts the same way. The major is the one `node_modules/.modules.yaml` records, else package.json's `packageManager` pin, else what the root lock's grammar implies (a pre-9 lock or `shrinkwrap.yaml`: pnpm 8 or older; an env lockfile document: pnpm 11 or newer); when none says, either file turning it off counts. Hosted mode also reads the setting from its environment, in the one variable family that major reads (#1460): `pnpm_config_lockfile` / `pnpm_config_package_lock` on pnpm 11 and newer, `npm_config_lockfile` / `npm_config_package_lock` on pnpm 10 and older, either family when the major is unknown (so the `npm_config_package_lock=` that `npx` / `npm exec` export from an npm-era `.npmrc` refuses nothing on pnpm 11+). Only the project's own files are read (a workspace member with no settings file of its own does not inherit its root's). In a pnpm project (a root pnpm lock or a `pnpm-workspace.yaml`), hosted mode then leaves every pnpm lock and `pnpm-workspace.yaml` untouched (no `trustLockfile` key is added), confirms no npm pin from them and warns `redirect_pnpm_lockfile_disabled` (in place of `redirect_pnpm_no_lockfile`), exiting 0 like the per-branch lock refusal below; the detail names the setting, and the remedy is `--mode vendored` when a pnpm lock exists (pnpm applies the `overrides` it wires without a lock), else removing the setting and running `pnpm install`. The check comes before the per-branch lock check. Manifest-less `vex` keeps the hosted references of such a lock but withholds their lockfile basis (see the pnpm row of the discovery table). Rush locks are not affected: Rush runs pnpm with its own settings. Vendored mode is unchanged. `vex` attests a vendored reference of such a lock only while the override map the governing pnpm reads without a lock routes the package (`name@version` or bare `name`) to the same artifact. When `.npmrc` turns the lock off (pnpm 10 and older), the map follows that pnpm's release, as it does with the lock on (#2403): older than 10.5.1, package.json alone (`pnpm.overrides`, over the top-level `resolutions`); 10.5.1 through 10.x, package.json when it declares any override and `pnpm-workspace.yaml` `overrides` when it declares none (an empty table, `null` or an empty array declare none; a package.json that cannot be read counts as declaring). The releases are the one `node_modules/.modules.yaml` records and the one package.json's `packageManager` pins, which pnpm switches to at the next install: when they differ, the override has to be where each of them reads it (`pnpm-workspace.yaml` `overrides` for a pin of pnpm 11 or newer). Only one exact version names a release: pnpm does not switch to a `packageManager` such as `pnpm@10`. When neither names a release of pnpm 10 or older, the override has to be in package.json, where every such pnpm reads it. When `pnpm-workspace.yaml` turns the lock off, the map is its `overrides` (pnpm 11 and newer never read `pnpm.overrides`); both files have to route the package when both turn it off and no major is known. Otherwise pnpm installs the registry release and the patch is omitted (`vex_lock_not_read`, see **Locks the package manager is told not to read**).

**pnpm per-branch locks (#556)**: with `gitBranchLockfile` on (a top-level `gitBranchLockfile: true` in the root `pnpm-workspace.yaml`; when the YAML leaves the key unset, `git-branch-lockfile=true` in the root `.npmrc`, as pnpm 10 and older read it; on disk also `pnpm_config_git_branch_lockfile` (pnpm 11 and newer) or `npm_config_git_branch_lockfile` (pnpm 10 and older; either when the major is unknown, read as for the `lockfile` setting above) set to `true`; a workspace member with no `pnpm-workspace.yaml` of its own reads the governing ancestor's file and the `.npmrc` beside it), pnpm installs a git branch from its own `pnpm-lock.<branch>.yaml` whenever that lock exists, in every directory it installs a lock from: the root, and under `sharedWorkspaceLockfile: false` each member's (#492). When the setting is on AND at least one such `pnpm-lock.<branch>.yaml` exists (at the root, or in a member that installs from its own lock), hosted mode leaves every root pnpm lock (`pnpm-lock.yaml`, `shrinkwrap.yaml`) and `pnpm-workspace.yaml` untouched (every member lock too), confirms no npm pin from them and warns `redirect_pnpm_git_branch_lockfile` (in place of `redirect_pnpm_no_lockfile` when the branch lock is the only one); the detail names the setting and the branch lock(s), and the remedy is to turn `gitBranchLockfile` off and fold the branch locks into `pnpm-lock.yaml` with `pnpm install --merge-git-branch-lockfiles`, then re-run. A vendored→hosted takeover of a pnpm-vendored purl is refused with the same code (the vendored wiring and ledger stay byte-for-byte). Vendored mode refuses the same projects with `vendor_pnpm_git_branch_lockfile`, before any write and in the pre-flight. The setting with no branch lock (main, or a branch whose dependencies never changed) installs from `pnpm-lock.yaml`, which both modes wire as usual; a stray branch lock with the setting off is ignored. The in-memory engine fetches root `pnpm-lock.*.yaml` names presence-only and refuses the same way. `vex` omits every pin of those pnpm locks (`vex_pnpm_git_branch_lockfile`) whenever such a branch lock exists, whatever the setting says (fail-closed; read from the project's files only, not the environment); see **Unattested references**.

Expand Down
105 changes: 105 additions & 0 deletions crates/socket-patch-cli/tests/e2e_vex_vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,111 @@ fn vendored_pin_in_a_lock_npm_install_ignores_is_not_attested() {
assert_lock_not_read(cwd, purl);
}

/// REGRESSION (#2403): with pnpm's lock off the vendored override has to
/// be in the map the project's pnpm release reads. Real pnpm, `.npmrc`
/// `lockfile=false`, the override in `pnpm-workspace.yaml` alone: 10.4.1
/// and 10.5.0 install the registry release and exit 0, 10.5.1 and 10.28.0
/// install the artifact, and 10.28.0 installs the registry release once
/// `package.json` declares an override of its own; a tree 10.28.0
/// installed whose pin moves to 10.4.1 gets the registry release at the
/// next install. `vex` read every pnpm 10 as reading either file and
/// attested the registry rows.
#[test]
fn vendored_pnpm_pin_with_the_lock_off_needs_the_override_its_release_reads() {
let tmp = tempfile::tempdir().unwrap();
let cwd = tmp.path();
let uuid = "55555555-5555-4555-8555-555555555555";
let purl = "pkg:npm/foo@1.0.0";
let rel = write_foo_ledger(
cwd,
uuid,
b"patched foo\n",
&[
("pnpm-workspace.yaml", "override"),
("pnpm-lock.yaml", "lock"),
],
);
let manifest = |pnpm: &str, own: &str| {
std::fs::write(
cwd.join("package.json"),
format!(
r#"{{"name":"app","version":"0.1.0","packageManager":"pnpm@{pnpm}","dependencies":{{"foo":"1.0.0"}}{own}}}"#
),
)
.unwrap();
};
std::fs::write(
cwd.join("pnpm-lock.yaml"),
format!(
"lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n \
excludeLinksFromLockfile: false\n\noverrides:\n foo@1.0.0: file:{rel}\n\n\
importers:\n\n .:\n dependencies:\n foo:\n \
specifier: file:{rel}\n version: file:{rel}\n\npackages:\n\n foo@file:{rel}:\n \
resolution: {{integrity: sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==, tarball: file:{rel}}}\n \
version: 1.0.0\n\nsnapshots:\n\n foo@file:{rel}: {{}}\n"
),
)
.unwrap();
std::fs::write(
cwd.join("pnpm-workspace.yaml"),
format!("packages:\n - '.'\noverrides:\n foo@1.0.0: file:{rel}\n"),
)
.unwrap();
std::fs::write(cwd.join(".npmrc"), "lockfile=false\n").unwrap();
let not_read_because = |what: &str| {
assert_lock_not_read(cwd, purl);
let (_, env) = vex_json(cwd, &["--offline"]);
assert!(env.to_string().contains(what), "{what}: {env}");
};

// The releases that read the workspace file.
for pnpm in ["10.5.1", "10.28.0"] {
manifest(pnpm, "");
assert_vendored_attested(cwd, purl, pnpm);
}
// The ones that read package.json alone.
for pnpm in ["10.4.1", "10.5.0"] {
manifest(pnpm, "");
not_read_because(&format!(
"(pnpm@{pnpm} (package.json packageManager) reads overrides from package.json alone)"
));
}
// package.json's own overrides replace the workspace file's.
for own in [
r#","pnpm":{"overrides":{"is-number":"7.0.0"}}"#,
r#","resolutions":{"is-number":"7.0.0"}"#,
] {
manifest("10.28.0", own);
not_read_because(
"(pnpm@10.28.0 (package.json packageManager) reads package.json's overrides when it \
declares any (`pnpm.overrides` or `resolutions`), and pnpm-workspace.yaml \
`overrides` when it declares none)",
);
}
// Declared where that pnpm reads it, it attests again.
manifest(
"10.28.0",
&format!(r#","pnpm":{{"overrides":{{"is-number":"7.0.0","foo@1.0.0":"file:{rel}"}}}}"#),
);
assert_vendored_attested(cwd, purl, "package.json declares it beside its own");

// A tree pnpm 10.28.0 installed, whose pin then moves to 10.4.1: the
// next install switches to the pinned release, which reads
// package.json alone (real pnpm: it installs the registry release).
std::fs::create_dir_all(cwd.join("node_modules")).unwrap();
std::fs::write(
cwd.join("node_modules/.modules.yaml"),
r#"{"packageManager":"pnpm@10.28.0"}"#,
)
.unwrap();
manifest("10.28.0", "");
assert_vendored_attested(cwd, purl, "the record and the pin agree");
manifest("10.4.1", "");
not_read_because(
"pnpm@10.4.1 (package.json packageManager) reads overrides from package.json alone",
);
}

/// A vendored pnpm lock entry with pnpm's lock turned off
/// (`lockfile=false` in `.npmrc`): pnpm resolves without the lock, so the
/// artifact installs only through an override (real pnpm 10.34.1: the
Expand Down
2 changes: 1 addition & 1 deletion crates/socket-patch-core/src/formats/pnpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) mod registry_alias;
mod version;
pub(crate) mod workspace;

pub(crate) use version::range_admits;
pub(crate) use version::{governing_override_sources, range_admits};
pub use version::{
matches_file_id_build_keys, pinned_override_sources, registry_route_pins,
root_only_workspace_breaks_add, routed_build_keys, OverrideSource, RegistryRoutePins,
Expand Down
Loading
Loading