Skip to content

Commit dd5c312

Browse files
committed
fix apply bug
1 parent 0173bcc commit dd5c312

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

crates/socket-patch-cli/src/commands/apply.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -968,14 +968,16 @@ async fn apply_patches_inner(
968968
let has_any_purls = !partitioned.is_empty();
969969

970970
if all_packages.is_empty() && !has_any_purls {
971+
// Nothing in scope: the manifest lists no patches (or every patch was
972+
// filtered out by `--ecosystems`). There is genuinely no work to do,
973+
// so this is a clean no-op SUCCESS — not a failure. Returning `false`
974+
// here used to exit 1 / `partialFailure`, which broke the npm
975+
// `postinstall` hook (it runs `apply` on every install, including
976+
// fresh projects whose manifest has no matching patches yet).
971977
if !args.common.silent && !args.common.json {
972-
if args.common.global || args.common.global_prefix.is_some() {
973-
eprintln!("No global packages found");
974-
} else {
975-
eprintln!("No package directories found");
976-
}
978+
println!("No patches to apply.");
977979
}
978-
return Ok((false, Vec::new(), Vec::new()));
980+
return Ok((true, Vec::new(), Vec::new()));
979981
}
980982

981983
if all_packages.is_empty() {

crates/socket-patch-cli/tests/in_process_edge_cases.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,13 @@ async fn apply_empty_manifest_is_noop() {
599599
write_manifest(&socket, r#"{ "patches": {} }"#);
600600

601601
let code = apply_run(default_apply(tmp.path())).await;
602-
// Empty manifest → no patches in scope → `apply_patches_inner`
603-
// returns `success == false`, which maps to exit code 1. This must
604-
// be asserted exactly: `code == 0 || code == 1` accepts every
605-
// outcome the function can return and would stay green even if the
606-
// empty-scope path regressed to a spurious success.
607-
assert_eq!(code, 1, "empty manifest is out of scope → exit 1");
602+
// Empty manifest → no patches in scope → there is genuinely nothing
603+
// to do, so `apply` is a clean no-op SUCCESS (exit 0). This must be
604+
// asserted exactly: `code == 0 || code == 1` accepts every outcome the
605+
// function can return and would stay green even if the empty-scope path
606+
// regressed back to the spurious `partialFailure`/exit-1 that broke the
607+
// npm `postinstall` hook (which runs `apply` on every install).
608+
assert_eq!(code, 0, "empty manifest has no work → clean no-op success");
608609
// A true no-op must not invent files. node_modules was never
609610
// created and the manifest must be untouched on disk.
610611
assert!(

0 commit comments

Comments
 (0)