diff --git a/.changeset/twenty-parks-end.md b/.changeset/twenty-parks-end.md new file mode 100644 index 0000000000..4e66dc93f1 --- /dev/null +++ b/.changeset/twenty-parks-end.md @@ -0,0 +1,6 @@ +--- +"@pnpm/plugin-commands-script-runners": patch +"pnpm": patch +--- + +Print help message on running pnpm dlx without arguments and exit. diff --git a/exec/plugin-commands-script-runners/src/dlx.ts b/exec/plugin-commands-script-runners/src/dlx.ts index d469f319cc..6412e63149 100644 --- a/exec/plugin-commands-script-runners/src/dlx.ts +++ b/exec/plugin-commands-script-runners/src/dlx.ts @@ -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 = ( ( diff --git a/pnpm/test/dlx.ts b/pnpm/test/dlx.ts index 125092d55b..352e2dc523 100644 --- a/pnpm/test/dlx.ts +++ b/pnpm/test/dlx.ts @@ -299,6 +299,17 @@ test('dlx uses the node version specified by --package=node@runtime:', } }) +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'