mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-27 18:46:18 -04:00
fix(dlx): print help message when no arguments are provided (#10690)
* fix(dlx): print help message on calling pnpm dlx without arguments Running `pnpm dlx` with no arguments would crash Node.js with a TypeError as it attempted to call `.indexOf()` on an undefined variable. This commit adds a guard clause and displays the help message instead and exits gracefully. Fixes #10633 * refactor: dlx --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/twenty-parks-end.md
Normal file
6
.changeset/twenty-parks-end.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Print help message on running pnpm dlx without arguments and exit.
|
||||
@@ -87,7 +87,10 @@ export type DlxCommandOptions = {
|
||||
export async function handler (
|
||||
opts: DlxCommandOptions,
|
||||
[command, ...args]: string[]
|
||||
): Promise<{ exitCode: number }> {
|
||||
): Promise<{ exitCode: number, output?: string }> {
|
||||
if (!command && (!opts.package || opts.package.length === 0)) {
|
||||
return { exitCode: 1, output: help() }
|
||||
}
|
||||
const pkgs = opts.package ?? [command]
|
||||
const fullMetadata = (
|
||||
(
|
||||
|
||||
@@ -299,6 +299,17 @@ test('dlx uses the node version specified by --package=node@runtime:<version>',
|
||||
}
|
||||
})
|
||||
|
||||
test('dlx without arguments prints help text and exits with 1', () => {
|
||||
prepareEmpty()
|
||||
|
||||
const result = execPnpmSync(['dlx'])
|
||||
|
||||
expect(result.status).toBe(1)
|
||||
|
||||
const output = result.stdout.toString()
|
||||
expect(output).toMatch(/Run a package in a temporary environment\./)
|
||||
})
|
||||
|
||||
describeOnLinuxOnly('dlx with supportedArchitectures CLI options', () => {
|
||||
type CPU = 'arm64' | 'x64'
|
||||
type LibC = 'glibc' | 'musl'
|
||||
|
||||
Reference in New Issue
Block a user