mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-11 00:18:32 -05:00
fix(dlx): should not print an error stack when dlx fails (#6883)
close #6698
This commit is contained in:
6
.changeset/few-icons-rule.md
Normal file
6
.changeset/few-icons-rule.md
Normal 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).
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user