From c4bf2eaf1231699d3f14a5df79e197d00baebd8b Mon Sep 17 00:00:00 2001 From: tthijm <59415467+tthijm@users.noreply.github.com> Date: Fri, 2 Aug 2024 13:46:24 +0200 Subject: [PATCH 1/3] Add unset command --- .yarn/versions/2f8bb76f.yml | 35 ++++++++++++++++++++++ packages/yarnpkg-shell/sources/index.ts | 13 ++++++++ packages/yarnpkg-shell/tests/shell.test.ts | 29 ++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 .yarn/versions/2f8bb76f.yml diff --git a/.yarn/versions/2f8bb76f.yml b/.yarn/versions/2f8bb76f.yml new file mode 100644 index 000000000000..a8ed3ee7f3b6 --- /dev/null +++ b/.yarn/versions/2f8bb76f.yml @@ -0,0 +1,35 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + "@yarnpkg/shell": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@yarnpkg/plugin-exec" + - "@yarnpkg/plugin-file" + - "@yarnpkg/plugin-git" + - "@yarnpkg/plugin-github" + - "@yarnpkg/plugin-http" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-link" + - "@yarnpkg/plugin-nm" + - "@yarnpkg/plugin-npm" + - "@yarnpkg/plugin-npm-cli" + - "@yarnpkg/plugin-pack" + - "@yarnpkg/plugin-patch" + - "@yarnpkg/plugin-pnp" + - "@yarnpkg/plugin-pnpm" + - "@yarnpkg/plugin-stage" + - "@yarnpkg/plugin-typescript" + - "@yarnpkg/plugin-version" + - "@yarnpkg/plugin-workspace-tools" + - "@yarnpkg/builder" + - "@yarnpkg/doctor" + - "@yarnpkg/extensions" + - "@yarnpkg/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks" diff --git a/packages/yarnpkg-shell/sources/index.ts b/packages/yarnpkg-shell/sources/index.ts index b0c505b7cd12..24cfa88aa159 100644 --- a/packages/yarnpkg-shell/sources/index.ts +++ b/packages/yarnpkg-shell/sources/index.ts @@ -166,6 +166,19 @@ const BUILTINS = new Map([ return await setTimeout(1000 * seconds, 0); }], + [`unset`, async ([name, ...rest]: Array, opts: ShellOptions, state: ShellState) => { + if (typeof name === `undefined`) + throw new ShellError(`unset: missing name`); + + if (!Object.hasOwn(state.environment, name) && !Object.hasOwn(state.variables, name)) + throw new ShellError(`unset: unbound variable "${name}"`); + + delete state.environment[name]; + delete state.variables[name]; + + return 0; + }], + [`__ysh_run_procedure`, async (args: Array, opts: ShellOptions, state: ShellState) => { const procedure = state.procedures[args[0]]; diff --git a/packages/yarnpkg-shell/tests/shell.test.ts b/packages/yarnpkg-shell/tests/shell.test.ts index dc90d6e6874b..d462f4f63cf0 100644 --- a/packages/yarnpkg-shell/tests/shell.test.ts +++ b/packages/yarnpkg-shell/tests/shell.test.ts @@ -2094,5 +2094,34 @@ describe(`Shell`, () => { }); }); }); + + describe(`unset`, () => { + it(`should throw a recoverable error when the variable name is missing`, async () => { + await expectResult(bufferResult( + `unset`, + ), { + exitCode: 1, + stderr: `unset: missing name\n`, + }); + }); + + it(`should throw a recoverable error when the variable is unbound`, async () => { + await expectResult(bufferResult( + `unset FOO`, + ), { + exitCode: 1, + stderr: `unset: unbound variable "FOO"\n`, + }); + }); + + it(`should unset the variable`, async () => { + await expectResult(bufferResult( + `FOO=bar; unset FOO; echo $FOO`, + ), { + exitCode: 1, + stderr: `Unbound variable "FOO"\n`, + }); + }); + }); }); }); From cc4f2cdea244de0c81b499799585eb01064e9ad8 Mon Sep 17 00:00:00 2001 From: tthijm <59415467+tthijm@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:34:16 +0200 Subject: [PATCH 2/3] Fix unset command --- .yarn/versions/2f8bb76f.yml | 13 +------------ packages/yarnpkg-shell/sources/index.ts | 14 +++++--------- packages/yarnpkg-shell/tests/shell.test.ts | 21 ++++++--------------- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/.yarn/versions/2f8bb76f.yml b/.yarn/versions/2f8bb76f.yml index a8ed3ee7f3b6..005fa5f089cd 100644 --- a/.yarn/versions/2f8bb76f.yml +++ b/.yarn/versions/2f8bb76f.yml @@ -1,6 +1,5 @@ releases: "@yarnpkg/cli": patch - "@yarnpkg/core": patch "@yarnpkg/shell": patch declined: @@ -8,16 +7,9 @@ declined: - "@yarnpkg/plugin-constraints" - "@yarnpkg/plugin-dlx" - "@yarnpkg/plugin-essentials" - - "@yarnpkg/plugin-exec" - - "@yarnpkg/plugin-file" - - "@yarnpkg/plugin-git" - - "@yarnpkg/plugin-github" - - "@yarnpkg/plugin-http" - "@yarnpkg/plugin-init" - "@yarnpkg/plugin-interactive-tools" - - "@yarnpkg/plugin-link" - "@yarnpkg/plugin-nm" - - "@yarnpkg/plugin-npm" - "@yarnpkg/plugin-npm-cli" - "@yarnpkg/plugin-pack" - "@yarnpkg/plugin-patch" @@ -28,8 +20,5 @@ declined: - "@yarnpkg/plugin-version" - "@yarnpkg/plugin-workspace-tools" - "@yarnpkg/builder" + - "@yarnpkg/core" - "@yarnpkg/doctor" - - "@yarnpkg/extensions" - - "@yarnpkg/nm" - - "@yarnpkg/pnpify" - - "@yarnpkg/sdks" diff --git a/packages/yarnpkg-shell/sources/index.ts b/packages/yarnpkg-shell/sources/index.ts index 24cfa88aa159..175448ac6cb3 100644 --- a/packages/yarnpkg-shell/sources/index.ts +++ b/packages/yarnpkg-shell/sources/index.ts @@ -166,15 +166,11 @@ const BUILTINS = new Map([ return await setTimeout(1000 * seconds, 0); }], - [`unset`, async ([name, ...rest]: Array, opts: ShellOptions, state: ShellState) => { - if (typeof name === `undefined`) - throw new ShellError(`unset: missing name`); - - if (!Object.hasOwn(state.environment, name) && !Object.hasOwn(state.variables, name)) - throw new ShellError(`unset: unbound variable "${name}"`); - - delete state.environment[name]; - delete state.variables[name]; + [`unset`, async (args: Array, opts: ShellOptions, state: ShellState) => { + for (const name of args) { + delete state.environment[name]; + delete state.variables[name]; + } return 0; }], diff --git a/packages/yarnpkg-shell/tests/shell.test.ts b/packages/yarnpkg-shell/tests/shell.test.ts index d462f4f63cf0..c79ea00405e2 100644 --- a/packages/yarnpkg-shell/tests/shell.test.ts +++ b/packages/yarnpkg-shell/tests/shell.test.ts @@ -2096,30 +2096,21 @@ describe(`Shell`, () => { }); describe(`unset`, () => { - it(`should throw a recoverable error when the variable name is missing`, async () => { + it(`should unset one variable`, async () => { await expectResult(bufferResult( - `unset`, - ), { - exitCode: 1, - stderr: `unset: missing name\n`, - }); - }); - - it(`should throw a recoverable error when the variable is unbound`, async () => { - await expectResult(bufferResult( - `unset FOO`, + `FOO=bar; unset FOO; echo $FOO`, ), { exitCode: 1, - stderr: `unset: unbound variable "FOO"\n`, + stderr: `Unbound variable "FOO"\n`, }); }); - it(`should unset the variable`, async () => { + it(`should unset multiple variables`, async () => { await expectResult(bufferResult( - `FOO=bar; unset FOO; echo $FOO`, + `A=1 B=2; unset A B; echo $A; echo $B`, ), { exitCode: 1, - stderr: `Unbound variable "FOO"\n`, + stderr: `Unbound variable "A"\nUnbound variable "B"\n`, }); }); }); From c2f4982306e499781840723d63bb2c12b6c3020f Mon Sep 17 00:00:00 2001 From: merceyz Date: Sun, 25 Aug 2024 16:32:40 +0200 Subject: [PATCH 3/3] chore: mark as minor --- .yarn/versions/2f8bb76f.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.yarn/versions/2f8bb76f.yml b/.yarn/versions/2f8bb76f.yml index 005fa5f089cd..a03b6c200680 100644 --- a/.yarn/versions/2f8bb76f.yml +++ b/.yarn/versions/2f8bb76f.yml @@ -1,6 +1,6 @@ releases: - "@yarnpkg/cli": patch - "@yarnpkg/shell": patch + "@yarnpkg/cli": minor + "@yarnpkg/shell": minor declined: - "@yarnpkg/plugin-compat"