Exit installation when detecting changes failed due to non-zero exit code in dry-run

This commit is contained in:
Sander Declerck 2025-09-19 08:52:42 +02:00
parent f7589160af
commit 528a60c166
No known key found for this signature in database
5 changed files with 169 additions and 10 deletions

View file

@ -37,10 +37,17 @@ function checkChangesWithDryRun(args) {
// Dry-run can return a non-zero status code in some cases
// e.g., when running "npm audit fix --dry-run", it returns exit code 1
// when there are vulnurabilities that can be fixed.
// when there are vulnerabilities that can be fixed.
if (dryRunOutput.status !== 0 && !doesCommandReturnNonZero(args)) {
throw new Error(
`Dry-run command failed with exit code ${dryRunOutput.status} and output:\n${dryRunOutput.output}`
);
}
if (dryRunOutput.status !== 0 && !dryRunOutput.output) {
ui.writeError("Detecting changes failed.");
return [];
throw new Error(
`Dry-run command failed with exit code ${dryRunOutput.status} and produced no output.`
);
}
const parsedOutput = parseDryRunOutput(dryRunOutput.output);
@ -48,3 +55,11 @@ function checkChangesWithDryRun(args) {
// reverse the array to have the top-level packages first
return parsedOutput.reverse();
}
function doesCommandReturnNonZero(args) {
if (args.length < 2) {
return false;
}
return args[0] === "audit" && args[1] === "fix";
}