diff --git a/packages/safe-chain/src/main.js b/packages/safe-chain/src/main.js index 3d4d5b1..da36a59 100644 --- a/packages/safe-chain/src/main.js +++ b/packages/safe-chain/src/main.js @@ -16,24 +16,36 @@ export async function main(args) { args = initializeCliArguments(args); if (shouldScanCommand(args)) { - await scanCommand(args); + const resultCode = await scanCommand(args); + + // Returning the exit code back to the caller allows the promise + // to be awaited in the bin files and return the correct exit code + if (resultCode !== 0) { + return resultCode; + } } + + var result = await getPackageManager().runCommand(args); + + proxy.verifyNoMaliciousPackages(); + + ui.emptyLine(); + ui.writeInformation( + `${chalk.green( + "✔" + )} Safe-chain: Command completed, no malicious packages found.` + ); + + // Returning the exit code back to the caller allows the promise + // to be awaited in the bin files and return the correct exit code + return result.status; } catch (error) { ui.writeError("Failed to check for malicious packages:", error.message); - process.exit(1); + + // Returning the exit code back to the caller allows the promise + // to be awaited in the bin files and return the correct exit code + return 1; + } finally { + await proxy.stopServer(); } - - var result = await getPackageManager().runCommand(args); - - await proxy.stopServer(); - proxy.verifyNoMaliciousPackages(); - - ui.emptyLine(); - ui.writeInformation( - `${chalk.green( - "✔" - )} Safe-chain: Command completed, no malicious packages found.` - ); - - return result.status; } diff --git a/packages/safe-chain/src/scanning/index.js b/packages/safe-chain/src/scanning/index.js index d4f8613..91314ae 100644 --- a/packages/safe-chain/src/scanning/index.js +++ b/packages/safe-chain/src/scanning/index.js @@ -62,9 +62,11 @@ export async function scanCommand(args) { if (!audit || audit.isAllowed) { spinner.stop(); + return 0; } else { printMaliciousChanges(audit.disallowedChanges, spinner); await onMalwareFound(); + return 1; } }