From 32679f0ad4762d5c429053e121d52ade85ef4142 Mon Sep 17 00:00:00 2001 From: await-ovo <13152410380@163.com> Date: Sat, 29 Jul 2023 06:18:25 +0800 Subject: [PATCH] fix: should not swallows empty string in params (#6871) close #6594 --- .changeset/lemon-meals-lick.md | 6 ++++++ cli/parse-cli-args/src/index.ts | 3 +-- cli/parse-cli-args/test/index.ts | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/lemon-meals-lick.md diff --git a/.changeset/lemon-meals-lick.md b/.changeset/lemon-meals-lick.md new file mode 100644 index 00000000000..5b9ceba19be --- /dev/null +++ b/.changeset/lemon-meals-lick.md @@ -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). diff --git a/cli/parse-cli-args/src/index.ts b/cli/parse-cli-args/src/index.ts index 93d09e0f26b..206a63c3a86 100644 --- a/cli/parse-cli-args/src/index.ts +++ b/cli/parse-cli-args/src/index.ts @@ -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 diff --git a/cli/parse-cli-args/test/index.ts b/cli/parse-cli-args/test/index.ts index 42c12dcafaf..853cfc90ef9 100644 --- a/cli/parse-cli-args/test/index.ts +++ b/cli/parse-cli-args/test/index.ts @@ -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']) +})