From 0318f442fe6c18275607a5d574c383f085484e6e Mon Sep 17 00:00:00 2001 From: Gar Date: Tue, 11 Jul 2023 12:48:17 -0700 Subject: [PATCH] fix: remove implicit if-present logic from run-script workspaces BREAKING CHANGE: npm no longer treats missing scripts as a special case in workspace mode. Use `if-present` to ignore missing scripts. --- lib/commands/run-script.js | 16 +--------------- test/lib/commands/run-script.js | 7 +------ 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/lib/commands/run-script.js b/lib/commands/run-script.js index 13efdde750a82..75f00a46b84e9 100644 --- a/lib/commands/run-script.js +++ b/lib/commands/run-script.js @@ -207,24 +207,10 @@ class RunScript extends BaseCommand { log.error(err) log.error(` in workspace: ${pkg._id || pkg.name}`) log.error(` at location: ${workspacePath}`) - - const scriptMissing = err.message.startsWith('Missing script') - - // avoids exiting with error code in case there's scripts missing - // in some workspaces since other scripts might have succeeded - if (!scriptMissing) { - process.exitCode = 1 - } - - return scriptMissing + process.exitCode = 1 }) res.push(runResult) } - - // in case **all** tests are missing, then it should exit with error code - if (res.every(Boolean)) { - throw new Error(`Missing script: ${args[0]}`) - } } async listWorkspaces (args, filters) { diff --git a/test/lib/commands/run-script.js b/test/lib/commands/run-script.js index cb54a7f51e900..24f51400e8dfc 100644 --- a/test/lib/commands/run-script.js +++ b/test/lib/commands/run-script.js @@ -781,12 +781,7 @@ t.test('workspaces', async t => { t.test('missing scripts in all workspaces', async t => { const { runScript, RUN_SCRIPTS, cleanLogs } = await mockWorkspaces(t, { exec: null }) - await t.rejects( - runScript.exec(['missing-script']), - /Missing script: missing-script/, - 'should throw missing script error' - ) - + await runScript.exec(['missing-script']) t.match(RUN_SCRIPTS(), []) t.strictSame( cleanLogs(),