Skip to content

Commit

Permalink
chore: fix coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Dec 2, 2023
1 parent f1274d3 commit f940cb5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
20 changes: 13 additions & 7 deletions lib/commands/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,28 @@ class RunScript extends BaseCommand {
}

async runWorkspaces (args, filters) {
const res = []
await this.setWorkspaces()
const errors = []

for (const workspacePath of this.workspacePaths) {
const { content: pkg } = await pkgJson.normalize(workspacePath)
const runResult = await this.run(args, {
path: workspacePath,
pkg,
}).catch(err => {
try {
await this.run(args, {
path: workspacePath,
pkg,
})
} catch (err) {
log.error(`Lifecycle script \`${args[0]}\` failed with error:`)
log.error(err)
log.error(` in workspace: ${pkg._id || pkg.name}`)
log.error(` at location: ${workspacePath}`)
errors.push(err)
process.exitCode = 1
})
res.push(runResult)
}
}

if (errors.some(r => r?.message.startsWith('Missing script'))) {
throw new Error(`Missing script: ${args[0]}`)

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.17.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.17.0

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.17.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.5.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.5.0

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.5.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.17.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.17.0

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.17.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.5.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.5.0

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.5.0

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

Missing script: test

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

Missing script: missing-script

Check failure on line 218 in lib/commands/run-script.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

Missing script: test
}
}

Expand Down
12 changes: 4 additions & 8 deletions lib/utils/exit-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,16 @@ const exitHandler = err => {
}

let exitCode = err ? 1 : process.exitCode || 0
let suppressLogMessage = exitCode === 0
let suppressLogMessage = !err
let jsonError

if (err) {
// if we got a command that just shells out to something else, then it
// will presumably print its own errors and exit with a proper status
// code if there's a problem. If we got an error with a code=0, then...
// something else went wrong along the way, so maybe an npm problem?
const isShellout = npm.isShellout
const quietShellout = isShellout && typeof err.code === 'number' && err.code
if (quietShellout) {
exitCode = err.code || 0
if (npm.isShellout && typeof err.code === 'number' && err.code) {
exitCode = err.code
suppressLogMessage = true
} else if (typeof err === 'string') {
// XXX: we should stop throwing strings
Expand Down Expand Up @@ -209,9 +207,7 @@ const exitHandler = err => {

log.verbose('exit', exitCode)

showLogFileError = (hasLoadedNpm && npm.silent) || suppressLogMessage
? false
: exitCode !== 0
showLogFileError = npm?.silent || suppressLogMessage ? false : exitCode !== 0

// explicitly call process.exit now so we don't hang on things like the
// update notifier, also flush stdout/err beforehand because process.exit doesn't
Expand Down
1 change: 0 additions & 1 deletion smoke-tests/test/workspace-run-script-error-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ t.test('basic', async t => {
await npm('init', '-y', `--workspace=pkgb`)

await npm('pkg', 'set', '-w=pkga', `scripts.hello=echo a`)
await npm('pkg', 'set', '-w=pkgb', `scripts.hello=exit 1`)

const logs = await npm('run', 'hello', '-ws').catch((r) => r.stderr)

Expand Down

0 comments on commit f940cb5

Please sign in to comment.