Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn config respect --no-defaults with --json (fixes #6341) #6635

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sparrowt
Copy link

What's the problem this PR addresses?

As documented here https://yarnpkg.com/cli/config you would expect --no-defaults to omit defaults even when --json is also specified.

This PR resolves #6341

How did you fix it?

By respecting noDefaults in the if (this.json) { branch as well as the else

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

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.
@arcanis
Copy link
Member

arcanis commented Dec 17, 2024

That looks good to me; can you also add a test to prevent regressions?

@sparrowt
Copy link
Author

I'm new to the repo so will have a look...!

I tried yarn version check --interactive but didn't know what to answer at this point:
image

@arcanis
Copy link
Member

arcanis commented Dec 17, 2024

For something like this you'd set both plugin-essentials and cli to patch, and everything else to decline.

@sparrowt
Copy link
Author

Re tests it seems https://github.com/yarnpkg/berry/blob/master/packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts is the right place though AFAICS there is no test for --no-defaults at all but I'll have a go

@sparrowt
Copy link
Author

sparrowt commented Dec 17, 2024

Trying to run yarn test:integration config.test.ts even before adding tests, they all fail as follows: (on WSL, node 23.4.0)

Console output
$ yarn test:integration config.test.ts
 FAIL  packages/acceptance-tests/pkg-tests-specs/sources/commands/config.test.ts
  Commands
    config
      ✕ test (folder without rcfile in ancestry / without flags) (277 ms)
      ✕ test (folder without rcfile in ancestry / as json) (2 ms)
      ✕ test (folder with rcfile / without flags) (2 ms)
      ✕ test (folder with rcfile / as json) (2 ms)
      ✕ test (folder with rcfile without trailing newline / without flags) (2 ms)
      ✕ test (folder with rcfile without trailing newline / as json) (2 ms)
      ✕ test (folder with rcfile and rc in parent / without flags) (2 ms)
      ✕ test (folder with rcfile and rc in parent / as json) (2 ms)
      ✕ test (folder with rcfile and rc in ancestor parent / without flags) (2 ms)
      ✕ test (folder with rcfile and rc in ancestor parent / as json) (2 ms)
      ✕ test (folder with rcfile and rc in home folder / without flags) (2 ms)
      ✕ test (folder with rcfile and rc in home folder / as json) (2 ms)

  ● Commands › config › test (folder without rcfile in ancestry / without flags)

    TypeError: Temporary fixture folder: /tmp/xfs-2eb22015/test

    Cannot read properties of undefined (reading 'replace')

      41 | };
      42 |
    > 43 | function cleanupPlainOutput(output: string, path: PortablePath, homePath: PortablePath) {
         |                   ^
      44 |   // Replace multiple consecutive spaces with one space.
      45 |   // The output of the config command is aligned according to the longest value, which probably
      46 |   // contains `path`. In other words, the formatting depends on the length of `path`.

      at cleanupPlainOutput (pkg-tests-specs/sources/commands/config.test.ts:43:19)
      at pkg-tests-specs/sources/commands/config.test.ts:95:20
      at Object.<anonymous> (pkg-tests-core/sources/utils/tests.ts:683:11)

...

what have I missed?

EDIT: ah sorry, I hadn't yet run yarn build:cli (that'll teach me to read more carefully...!)

sparrowt pushed a commit to sparrowt/berry that referenced this pull request Dec 17, 2024
This is all new to me but these choices are based on:
yarnpkg#6635 (comment)
This is all new to me but these choices are based on:
yarnpkg#6635 (comment)
Squashed from several commits while figuring out what was going on:

Remove unnecessary replacements

Back in 7835a7d 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
@sparrowt
Copy link
Author

@arcanis hopefully I've done the right thing with committing that releases file.

The tests were gnarly because there was a bunch of dead code which was 'resurrected' by adding a test which returned a single json line - hopefully the commit message explains it sufficiently (!)

@sparrowt
Copy link
Author

sparrowt commented Dec 19, 2024

The 2 CI failures look unrelated, are they a known issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug?]: --no-defaults flag is ignore on yarn config when the --json flag is present
2 participants