fix: pnpm exec should specify command (#8774)

This commit is contained in:
btea
2024-11-18 00:07:32 +08:00
committed by GitHub
parent 2f210d9d58
commit ef7c10221c
3 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-script-runners": patch
---
`pnpm exec` should print a meaningful error message when no command is provided [#8752](https://github.com/pnpm/pnpm/issues/8752).

View File

@@ -174,6 +174,9 @@ export async function handler (
if (params[0] === '--') {
params.shift()
}
if (!params[0]) {
throw new PnpmError('EXEC_MISSING_COMMAND', '\'pnpm exec\' requires a command to run')
}
const limitRun = pLimit(opts.workspaceConcurrency ?? 4)
if (opts.verifyDepsBeforeRun && !process.env[SKIP_ENV_KEY]) {
@@ -205,6 +208,10 @@ export async function handler (
}
}
if (!opts.selectedProjectsGraph) {
throw new PnpmError('RECURSIVE_EXEC_NO_PACKAGE', 'No package found in this workspace')
}
if (opts.resumeFrom) {
chunks = getResumedPackageChunks({
resumeFrom: opts.resumeFrom,

View File

@@ -41,3 +41,14 @@ test('exec should set the NODE_OPTIONS env var', async () => {
}),
}))
})
test('exec should specify the command', async () => {
prepareEmpty()
await expect(exec.handler({
...DEFAULT_OPTS,
dir: process.cwd(),
selectedProjectsGraph: {},
}, [])
).rejects.toThrow("'pnpm exec' requires a command to run")
})