yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.43k stars 1.11k forks source link

[Bug?]: yarn config --home shows local value in confirmation message #4139

Open ASDFGerte opened 2 years ago

ASDFGerte commented 2 years ago

Self-service

Describe the bug

When using yarn config set --home, in the resulting "Successfully set ... to" message, the local config's value is used, if it exists. This is especially confusing, if the local value does exist, but is null, e.g. when the parent setting exists because of a sister setting.

To reproduce

Expected:

➤ YN0000: Successfully set npmScopes.myScope.npmAuthToken to '****'

Actual:

➤ YN0000: Successfully set npmScopes.myScope.npmAuthToken to null

await yarn('init', '-2');                // make project
await yarn(
  'config', 'set',                       // create local sister setting
  'npmScopes.myScope.npmRegistryServer', // resides in same parent as the following
  'https://aya.ya',                      // some value
);
expect(await yarn(
  'config', 'set', '--home',             // global
  'npmScopes.myScope.npmAuthToken',      // setting to write
  'test',                                // some value
)).not.toContain('to null');

Environment

Should be irrelevant.

Additional context

No response

yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).not.toContain(expected) // indexOf

Expected substring: not "to null"
Received string:        "➤ YN0000: Successfully set npmScopes.myScope.npmAuthToken to null
"
    at module.exports (evalmachine.<anonymous>:12:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
yarnbot commented 2 years ago

This issue reproduces on master:

Error: expect(received).not.toContain(expected) // indexOf

Expected substring: not "to null"
Received string:        "➤ YN0000: Successfully set npmScopes.myScope.npmAuthToken to null
"
    at module.exports (evalmachine.<anonymous>:12:8)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
    at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-ccfa417b92.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
oliverdavidt commented 2 years ago

I am seeing the same thing on a project I am working on. I ran: yarn config set -H npmScopes.myscope.npmAuthToken <mytoken> and am getting: ➤ YN0000: Successfully set npmScopes.myscope.npmAuthToken to null. This is only the case if I run it with the -H flag. If I do not it will correctly update my local .yarnrc.yml file. For reference, this is my yarn setup:

`nodeLinker: node-modules

npmScopes: myscope: npmAlwaysAuth: true npmRegistryServer: 'https://myinternal-npm-registry'

yarnPath: .yarn/releases/yarn-3.2.0.cjs`

hckhanh commented 1 year ago

@oliverdavidt, I figured out yarn config set -H npmScopes.myscope.npmAuthToken <mytoken> will not work, somehow. You must use remove the -H option since it will use the Home configurations instead of project configurations:

yarn config set 'npmScopes.myscope.npmAuthToken' '<mytoken>'

It worked