From fc2bf0f9cc5763ba0996f997bf7385d7f54428c7 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Tue, 17 Dec 2024 09:44:04 +0000 Subject: [PATCH 1/3] Yarn config respect --no-defaults with --json (fixes #6341) As documented here https://yarnpkg.com/cli/config you would expect `--no-defaults` to omit defaults even when `--json` is also specified. This commit fixes that behaviour to be as expected. --- packages/plugin-essentials/sources/commands/config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/plugin-essentials/sources/commands/config.ts b/packages/plugin-essentials/sources/commands/config.ts index 895ca949fb5b..ffbe334b6fb0 100644 --- a/packages/plugin-essentials/sources/commands/config.ts +++ b/packages/plugin-essentials/sources/commands/config.ts @@ -76,6 +76,9 @@ export default class ConfigCommand extends BaseCommand { if (this.json) { for (const name of names) { + if (this.noDefaults && !configuration.sources.has(name)) + continue; + const data = configuration.settings.get(name); if (typeof data === `undefined`) report.reportError(MessageName.INVALID_CONFIGURATION_KEY, `No configuration key named "${name}"`); From 0436d4c54d5f07d6410feb91ced1afa096abf3fd Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:30:06 +0000 Subject: [PATCH 2/3] Releases for #6635 This is all new to me but these choices are based on: https://github.com/yarnpkg/berry/pull/6635#issuecomment-2547997158 --- .yarn/versions/c7de517e.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .yarn/versions/c7de517e.yml diff --git a/.yarn/versions/c7de517e.yml b/.yarn/versions/c7de517e.yml new file mode 100644 index 000000000000..b9ef967a4a38 --- /dev/null +++ b/.yarn/versions/c7de517e.yml @@ -0,0 +1,23 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/plugin-essentials": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-init" + - "@yarnpkg/plugin-interactive-tools" + - "@yarnpkg/plugin-nm" + - "@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/core" + - "@yarnpkg/doctor" From bca6312490ee21371ba59031638773b646a12fd7 Mon Sep 17 00:00:00 2001 From: Tom Sparrow <793763+sparrowt@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:44:43 +0000 Subject: [PATCH 3/3] Add tests for --no-default and --no-default --json Squashed from several commits while figuring out what was going on: Remove unnecessary replacements Back in 7835a7d39598e400c374d0cbf815405022bf223f there was no `FILTER` at the top but now that there is, these settings are not in the output. Remove confusing cleanupJsonOutput method This does not support ndjson so in all tests (prior to this PR) it was failing to parse the JSON and not actually executing most of the method body. Now that one of the new tests returns only a single line of JSON this 'resurrected' this dead broken method causing tests to fail. Instead use the same cleanup method for all cases, which is what has been happening anyway (due to the fallback in the `catch`) Add the remaining to snapshots now the tests are fixed --- .../__snapshots__/config.test.ts.snap | 139 ++++++++++++++++++ .../sources/commands/config.test.ts | 51 +------ 2 files changed, 147 insertions(+), 43 deletions(-) diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/config.test.ts.snap b/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/config.test.ts.snap index 82ad7018b2a9..32e8bfa4a8a4 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/config.test.ts.snap +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/config.test.ts.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Commands config test (folder with rcfile / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "{"key":"initScope","effective":"my-test","source":"WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml","description":"Scope used when creating packages via the init command","type":"STRING","default":null} +", +} +`; + exports[`Commands config test (folder with rcfile / as json) 1`] = ` { "code": 0, @@ -11,6 +20,18 @@ exports[`Commands config test (folder with rcfile / as json) 1`] = ` } `; +exports[`Commands config test (folder with rcfile / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "└─ initScope + - ├─ Description: Scope used when creating packages via the init command + - ├─ Source: WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml + - └─ Value: 'my-test' +", +} +`; + exports[`Commands config test (folder with rcfile / without flags) 1`] = ` { "code": 0, @@ -33,6 +54,16 @@ exports[`Commands config test (folder with rcfile / without flags) 1`] = ` } `; +exports[`Commands config test (folder with rcfile and rc in ancestor parent / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "{"key":"initScope","effective":"my-test","source":"WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml","description":"Scope used when creating packages via the init command","type":"STRING","default":null} +{"key":"lastUpdateCheck","effective":"1555784893958","source":"WORKSPACE_ROOT/.yarnrc.yml","description":"Last timestamp we checked whether new Yarn versions were available","type":"STRING","default":null} +", +} +`; + exports[`Commands config test (folder with rcfile and rc in ancestor parent / as json) 1`] = ` { "code": 0, @@ -44,6 +75,23 @@ exports[`Commands config test (folder with rcfile and rc in ancestor parent / as } `; +exports[`Commands config test (folder with rcfile and rc in ancestor parent / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "├─ initScope +│ - ├─ Description: Scope used when creating packages via the init command +│ - ├─ Source: WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml +│ - └─ Value: 'my-test' +│ +└─ lastUpdateCheck + - ├─ Description: Last timestamp we checked whether new Yarn versions were available + - ├─ Source: WORKSPACE_ROOT/.yarnrc.yml + - └─ Value: '1555784893958' +", +} +`; + exports[`Commands config test (folder with rcfile and rc in ancestor parent / without flags) 1`] = ` { "code": 0, @@ -66,6 +114,16 @@ exports[`Commands config test (folder with rcfile and rc in ancestor parent / wi } `; +exports[`Commands config test (folder with rcfile and rc in home folder / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "{"key":"initScope","effective":"my-test","source":"WORKSPACE_ROOT/.yarnrc.yml","description":"Scope used when creating packages via the init command","type":"STRING","default":null} +{"key":"lastUpdateCheck","effective":"1555784893958","source":"WORKSPACE_ROOT/.yarnrc.yml","description":"Last timestamp we checked whether new Yarn versions were available","type":"STRING","default":null} +", +} +`; + exports[`Commands config test (folder with rcfile and rc in home folder / as json) 1`] = ` { "code": 0, @@ -77,6 +135,23 @@ exports[`Commands config test (folder with rcfile and rc in home folder / as jso } `; +exports[`Commands config test (folder with rcfile and rc in home folder / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "├─ initScope +│ - ├─ Description: Scope used when creating packages via the init command +│ - ├─ Source: WORKSPACE_ROOT/.yarnrc.yml +│ - └─ Value: 'my-test' +│ +└─ lastUpdateCheck + - ├─ Description: Last timestamp we checked whether new Yarn versions were available + - ├─ Source: WORKSPACE_ROOT/.yarnrc.yml + - └─ Value: '1555784893958' +", +} +`; + exports[`Commands config test (folder with rcfile and rc in home folder / without flags) 1`] = ` { "code": 0, @@ -99,6 +174,16 @@ exports[`Commands config test (folder with rcfile and rc in home folder / withou } `; +exports[`Commands config test (folder with rcfile and rc in parent / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "{"key":"initScope","effective":"my-test","source":"WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml","description":"Scope used when creating packages via the init command","type":"STRING","default":null} +{"key":"lastUpdateCheck","effective":"1555784893958","source":"WORKSPACE_ROOT/subfolder/.yarnrc.yml","description":"Last timestamp we checked whether new Yarn versions were available","type":"STRING","default":null} +", +} +`; + exports[`Commands config test (folder with rcfile and rc in parent / as json) 1`] = ` { "code": 0, @@ -110,6 +195,23 @@ exports[`Commands config test (folder with rcfile and rc in parent / as json) 1` } `; +exports[`Commands config test (folder with rcfile and rc in parent / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "├─ initScope +│ - ├─ Description: Scope used when creating packages via the init command +│ - ├─ Source: WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml +│ - └─ Value: 'my-test' +│ +└─ lastUpdateCheck + - ├─ Description: Last timestamp we checked whether new Yarn versions were available + - ├─ Source: WORKSPACE_ROOT/subfolder/.yarnrc.yml + - └─ Value: '1555784893958' +", +} +`; + exports[`Commands config test (folder with rcfile and rc in parent / without flags) 1`] = ` { "code": 0, @@ -132,6 +234,15 @@ exports[`Commands config test (folder with rcfile and rc in parent / without fla } `; +exports[`Commands config test (folder with rcfile without trailing newline / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "{"key":"initScope","effective":"my-test","source":"WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml","description":"Scope used when creating packages via the init command","type":"STRING","default":null} +", +} +`; + exports[`Commands config test (folder with rcfile without trailing newline / as json) 1`] = ` { "code": 0, @@ -143,6 +254,18 @@ exports[`Commands config test (folder with rcfile without trailing newline / as } `; +exports[`Commands config test (folder with rcfile without trailing newline / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "└─ initScope + - ├─ Description: Scope used when creating packages via the init command + - ├─ Source: WORKSPACE_ROOT/subfolder/subfolder/.yarnrc.yml + - └─ Value: 'my-test' +", +} +`; + exports[`Commands config test (folder with rcfile without trailing newline / without flags) 1`] = ` { "code": 0, @@ -165,6 +288,14 @@ exports[`Commands config test (folder with rcfile without trailing newline / wit } `; +exports[`Commands config test (folder without rcfile in ancestry / as json no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "", +} +`; + exports[`Commands config test (folder without rcfile in ancestry / as json) 1`] = ` { "code": 0, @@ -176,6 +307,14 @@ exports[`Commands config test (folder without rcfile in ancestry / as json) 1`] } `; +exports[`Commands config test (folder without rcfile in ancestry / no defaults) 1`] = ` +{ + "code": 0, + "stderr": "", + "stdout": "", +} +`; + exports[`Commands config test (folder without rcfile in ancestry / without flags) 1`] = ` { "code": 0, diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts index f48bfbcde35a..0027cd9f759d 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts @@ -2,7 +2,6 @@ import {PortablePath, npath, ppath, xfs} from '@yarnpkg/fslib'; const RC_FILENAME = `.yarnrc.yml`; const SUBFOLDER = `subfolder`; -const FAKE_REGISTRY_URL = `http://yarn.test.registry`; const FAKE_LOCAL_APP_DATA = `LOCAL_APP_DATA`; const FAKE_WORKSPACE_ROOT = `WORKSPACE_ROOT`; const FAKE_HOME = `HOME`; @@ -40,7 +39,7 @@ const environments: Record input - .replaceAll(pathN, FAKE_WORKSPACE_ROOT) - .replaceAll(homePathN, FAKE_HOME); - - for (const setting of Object.values(outputObject)) { - if (typeof setting.source === `string`) - setting.source = cleanPath(setting.source); - - if (typeof setting.default === `string`) - setting.default = cleanPath(setting.default); - - if (typeof setting.effective === `string`) { - setting.effective = cleanPath(setting.effective); - } - } - - return JSON.stringify(outputObject); -} - const options = { - [`without flags`]: {cleanupStdout: cleanupPlainOutput, flags: []}, - [`as json`]: {cleanupStdout: cleanupJsonOutput, flags: [`--json`]}, + [`without flags`]: {flags: []}, + [`as json`]: {flags: [`--json`]}, + [`no defaults`]: {flags: [`--no-defaults`]}, + [`as json no defaults`]: {flags: [`--json`, `--no-defaults`]}, }; describe(`Commands`, () => { describe(`config`, () => { for (const [environmentDescription, environment] of Object.entries(environments)) { - for (const [optionDescription, {flags, cleanupStdout}] of Object.entries(options)) { + for (const [optionDescription, {flags}] of Object.entries(options)) { test(`test (${environmentDescription} / ${optionDescription})`, makeTemporaryEnv({}, async ({path, run, source}) => { const cwd = ppath.join(path, `${SUBFOLDER}/${SUBFOLDER}`); const homePath = await xfs.mktempPromise(); @@ -127,8 +92,8 @@ describe(`Commands`, () => { ({code, stdout, stderr} = error); } - stdout = cleanupStdout(stdout, path, homePath); - stderr = cleanupPlainOutput(stderr, path, homePath); + stdout = cleanupOutput(stdout, path, homePath); + stderr = cleanupOutput(stderr, path, homePath); expect({code, stdout, stderr}).toMatchSnapshot(); }));