fix: revert backwards compatible handling of -- for run (#4291)

This commit is contained in:
Brandon Cheng
2022-01-31 08:11:14 -05:00
committed by GitHub
parent 3b77e2f1e5
commit 3e682067de
3 changed files with 5 additions and 28 deletions

View File

@@ -4,4 +4,4 @@
"pnpm": major
---
When using `pnpm run <script>`, all command line arguments after the script name are now passed to the script's argv. Previously flagged arguments (e.g. `--silent`) were intepreted as pnpm arguments unless `--` came before it.
When using `pnpm run <script>`, all command line arguments after the script name are now passed to the script's argv, even `--`. For example, `pnpm run echo --hello -- world` will now pass `--hello -- world` to the `echo` script's argv. Previously flagged arguments (e.g. `--silent`) were intepreted as pnpm arguments unless `--` came before it.

View File

@@ -134,11 +134,6 @@ export async function handler (
) {
let dir: string
const [scriptName, ...passedThruArgs] = params
// For backward compatibility
const firstDoubleDash = passedThruArgs.findIndex((arg) => arg === '--')
if (firstDoubleDash !== -1) {
passedThruArgs.splice(firstDoubleDash, 1)
}
if (opts.recursive) {
if (scriptName || Object.keys(opts.selectedProjectsGraph).length > 1) {
return runRecursive(params, opts)

View File

@@ -47,8 +47,10 @@ test('run: pass the args to the command that is specfied in the build script', a
])
})
// Before pnpm v7, `--` was required to pass flags to a build script.
test('run: handle -- in a backwards compatible manner', async () => {
// Before pnpm v7, `--` was required to pass flags to a build script. Now all
// arguments after the script name should be passed to the build script, even
// `--`.
test('run: pass all arguments after script name to the build script, even --', async () => {
prepare({
name: 'project',
scripts: {
@@ -62,26 +64,6 @@ test('run: handle -- in a backwards compatible manner', async () => {
await execPnpm(['run', 'foo', 'arg', '--', '--flag=true'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
['arg', '--flag=true'],
])
})
test('run: pass -- to the build script if specified twice', async () => {
prepare({
name: 'project',
scripts: {
foo: 'node recordArgs',
postfoo: 'node recordArgs',
prefoo: 'node recordArgs',
},
})
await fs.writeFile('args.json', '[]', 'utf8')
await fs.writeFile('recordArgs.js', RECORD_ARGS_FILE, 'utf8')
await execPnpm(['run', 'foo', '--', 'arg', '--', '--flag=true'])
const { default: args } = await import(path.resolve('args.json'))
expect(args).toStrictEqual([
['arg', '--', '--flag=true'],