mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 22:18:17 -05:00
fix(run): stop passing flags as fallback command (#7370)
close #7244 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/grumpy-meals-admire.md
Normal file
6
.changeset/grumpy-meals-admire.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-script-runners": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Fix a bug where pnpm incorrectly passes a flag to a run handler as a fallback command [#7244](https://github.com/pnpm/pnpm/issues/7244).
|
||||
@@ -191,11 +191,23 @@ export async function handler (
|
||||
if (opts.ifPresent) return
|
||||
if (opts.fallbackCommandUsed) {
|
||||
if (opts.argv == null) throw new Error('Could not fallback because opts.argv.original was not passed to the script runner')
|
||||
const params = opts.argv.original.slice(1)
|
||||
while (params.length > 0 && params[0].startsWith('-') && params[0] !== '--') {
|
||||
params.shift()
|
||||
}
|
||||
if (params.length > 0 && params[0] === '--') {
|
||||
params.shift()
|
||||
}
|
||||
if (params.length === 0) {
|
||||
throw new PnpmError('UNEXPECTED_BEHAVIOR', 'Params should not be an empty array', {
|
||||
hint: 'This was a bug caused by programmer error. Please report it',
|
||||
})
|
||||
}
|
||||
return exec({
|
||||
selectedProjectsGraph: {},
|
||||
implicitlyFellbackFromRun: true,
|
||||
...opts,
|
||||
}, opts.argv.original.slice(1))
|
||||
}, params)
|
||||
}
|
||||
if (opts.workspaceDir) {
|
||||
const { manifest: rootManifest } = await tryReadProjectManifest(opts.workspaceDir, opts)
|
||||
|
||||
@@ -900,3 +900,25 @@ test('pnpm exec command not found (explicit call, with a near name package)', as
|
||||
expect(error?.message).toBe('Command "cwsay" not found')
|
||||
expect(error?.hint).toBe('Did you mean "pnpm exec cowsay"?')
|
||||
})
|
||||
|
||||
test('pnpm exec --workspace-root when command not found', async () => {
|
||||
prepare({})
|
||||
|
||||
let error!: any // eslint-disable-line
|
||||
try {
|
||||
await run.handler({
|
||||
...DEFAULT_OPTS,
|
||||
argv: {
|
||||
original: ['pnpm', '--workspace-root', 'command-that-does-not-exist'],
|
||||
},
|
||||
dir: process.cwd(),
|
||||
fallbackCommandUsed: true,
|
||||
recursive: false,
|
||||
selectedProjectsGraph: {},
|
||||
}, ['command-that-does-not-exist'])
|
||||
} catch (err: any) { // eslint-disable-line
|
||||
error = err
|
||||
}
|
||||
|
||||
expect(error?.failures[0].message).toBe('Command "command-that-does-not-exist" not found')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user