Skip to content

Commit

Permalink
fix: should not swallows empty string in params (#6871)
Browse files Browse the repository at this point in the history
close #6594
  • Loading branch information
await-ovo committed Jul 28, 2023
1 parent 3c5aaaf commit 32679f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/lemon-meals-lick.md
Original file line number Diff line number Diff line change
@@ -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).
3 changes: 1 addition & 2 deletions cli/parse-cli-args/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cli/parse-cli-args/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})

0 comments on commit 32679f0

Please sign in to comment.