fix(dlx): should not print an error stack when dlx fails (#6883)

close #6698
This commit is contained in:
Zoltan Kochan
2023-07-30 21:50:48 +03:00
committed by GitHub
parent b97ce54396
commit b454bb07bf
3 changed files with 37 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-script-runners": patch
"pnpm": patch
---
`pnpm dlx` should not print an error stack when the underlying script execution fails [#6698](https://github.com/pnpm/pnpm/issues/6698).

View File

@@ -96,12 +96,22 @@ export async function handler (
const binName = opts.package
? command
: await getBinName(modulesDir, await getPkgName(prefix))
await execa(binName, args, {
cwd: process.cwd(),
env,
stdio: 'inherit',
shell: opts.shellMode ?? false,
})
try {
await execa(binName, args, {
cwd: process.cwd(),
env,
stdio: 'inherit',
shell: opts.shellMode ?? false,
})
} catch (err: any) { // eslint-disable-line
if (err.exitCode != null) {
return {
exitCode: err.exitCode,
}
}
throw err
}
return { exitCode: 0 }
}
async function getPkgName (pkgDir: string) {

View File

@@ -106,3 +106,18 @@ test('dlx should work in shell mode', async () => {
expect(fs.existsSync('foo')).toBeTruthy()
})
test('dlx should return a non-zero exit code when the underying script fails', async () => {
prepareEmpty()
const { exitCode } = await dlx.handler({
...DEFAULT_OPTS,
dir: path.resolve('project'),
storeDir: path.resolve('store'),
package: [
'touch@3.1.0',
],
}, ['nodetouch', '--bad-option'])
expect(exitCode).toBe(1)
})