Skip to content

Commit

Permalink
fix: remove implicit if-present logic from run-script workspaces
Browse files Browse the repository at this point in the history
BREAKING CHANGE: npm no longer treats missing scripts as a special case
in workspace mode.  Use `if-present` to ignore missing scripts.
  • Loading branch information
wraithgar authored and lukekarrys committed Jul 26, 2023
1 parent 392682b commit 0318f44
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
16 changes: 1 addition & 15 deletions lib/commands/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions test/lib/commands/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 0318f44

Please sign in to comment.