fix: should not swallows empty string in params (#6871)

close #6594
This commit is contained in:
await-ovo
2023-07-29 06:18:25 +08:00
committed by GitHub
parent 3c5aaaf84e
commit 32679f0ad4
3 changed files with 24 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/parse-cli-args": patch
"pnpm": patch
---
Don't ignore empty strings in params [#6594](https://github.com/pnpm/pnpm/issues/6594).

View File

@@ -139,8 +139,7 @@ export async function parseCliArgs (
}
}
// `pnpm install ""` is going to be just `pnpm install`
const params = argv.remain.slice(1).filter(Boolean)
const params = argv.remain.slice(1)
if (options['recursive'] !== true && (options['filter'] || options['filter-prod'] || recursiveCommandUsed)) {
options['recursive'] = true

View File

@@ -319,3 +319,20 @@ test('everything after an escape arg is a parameter, even if it has a help optio
expect(cmd).toBe('exec')
expect(params).toStrictEqual(['rm', '--help'])
})
test('`pnpm install ""` is going to be just `pnpm install`', async () => {
const { params, cmd } = await parseCliArgs({
...DEFAULT_OPTS,
}, ['install', ''])
expect(cmd).toBe('add')
// empty string in params will be filtered at: https://github.com/pnpm/pnpm/blob/main/pkg-manager/plugin-commands-installation/src/installDeps.ts#L196
expect(params).toStrictEqual([''])
})
test('should not swallows empty string in params', async () => {
const { params, cmd } = await parseCliArgs({
...DEFAULT_OPTS,
}, ['run', 'echo', '', 'foo', '', 'bar'])
expect(cmd).toBe('run')
expect(params).toStrictEqual(['echo', '', 'foo', '', 'bar'])
})