fix: --no-bail

close #3036
PR #3040
This commit is contained in:
Zoltan Kochan
2020-12-23 00:05:23 +02:00
committed by GitHub
parent ec37069f2a
commit 9427ab3925
3 changed files with 41 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
--no-bail should work with non-recursive run commands as well.

View File

@@ -92,6 +92,10 @@ For options that may be used with `-r`, see "pnpm help recursive"',
name: '--recursive',
shortAlias: '-r',
},
{
description: 'The command will exit with a 0 exit code even if the script fails',
name: '--no-bail',
},
IF_PRESENT_OPTION_HELP,
PARALLEL_OPTION_HELP,
...UNIVERSAL_OPTIONS,
@@ -166,12 +170,18 @@ so you may run "pnpm -w ${scriptName}"`,
if (pnpPath) {
lifecycleOpts.extraEnv = makeNodeRequireOption(pnpPath)
}
if (manifest.scripts?.[`pre${scriptName}`]) {
await runLifecycleHooks(`pre${scriptName}`, manifest, lifecycleOpts)
}
await runLifecycleHooks(scriptName, manifest, { ...lifecycleOpts, args: passedThruArgs })
if (manifest.scripts?.[`post${scriptName}`]) {
await runLifecycleHooks(`post${scriptName}`, manifest, lifecycleOpts)
try {
if (manifest.scripts?.[`pre${scriptName}`]) {
await runLifecycleHooks(`pre${scriptName}`, manifest, lifecycleOpts)
}
await runLifecycleHooks(scriptName, manifest, { ...lifecycleOpts, args: passedThruArgs })
if (manifest.scripts?.[`post${scriptName}`]) {
await runLifecycleHooks(`post${scriptName}`, manifest, lifecycleOpts)
}
} catch (err) {
if (opts.bail !== false) {
throw err
}
}
return undefined
}

View File

@@ -44,6 +44,26 @@ test('pnpm run: returns correct exit code', async () => {
expect(err.errno).toBe(1)
})
test('pnpm run --no-bail never fails', async () => {
prepare({
scripts: {
exit1: 'node recordArgs && exit 1',
},
})
await fs.writeFile('args.json', '[]', 'utf8')
await fs.writeFile('recordArgs.js', RECORD_ARGS_FILE, 'utf8')
await run.handler({
bail: false,
dir: process.cwd(),
extraBinPaths: [],
rawConfig: {},
}, ['exit1'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([[]])
})
const RECORD_ARGS_FILE = 'require(\'fs\').writeFileSync(\'args.json\', JSON.stringify(require(\'./args.json\').concat([process.argv.slice(2)])), \'utf8\')'
test('run: pass the args to the command that is specfied in the build script', async () => {