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

close #6594
This commit is contained in:
await-ovo authored and GitHub committed 2023-07-29 01:18:25 +03:00
1 parent 3c5aaaf84e
commit 32679f0ad4
3 files changed
+24 -2

No files matched your search

+6
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).
+1 -2
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
+17
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'])
})