berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug?]: Example to set a complex config does not work on Windows (Powershell / cmd)

Open julianess opened this issue 2 years ago • 2 comments

Self-service

  • [ ] I'd be willing to implement a fix

Describe the bug

When trying to set the "npmRegistries" entry either via dot notation or with --json flag, configuration cannot be set neither in powershell, nor in cmd on Windows.

Even when the example from the doc is used, the command fails:

yarn config set 'npmRegistries["//npm.example.com"].npmAuthToken' ffffffff-ffff-ffff-ffff-ffffffffffff

The problem occurs from the url. If it includes a "." (e.g. //npm.example.com) it fails to be parsed:

Usage Error: Unrecognized configuration settings found: npmRegistries['//npm'].example - run "yarn config -v" to see the list of settings supported in Yarn in C:\Users\MyUser\.yarnrc.yml (in C:\Users\MyUser\.yarnrc.yml)

The resulting .yarnrc.yml file has this entry set from now on:

npmRegistries:
  //npm:
    example:
      com:
        npmAuthToken: ffffffff-ffff-ffff-ffff-ffffffffffff

I only got the command running by replacing all the "." in the URL with something else. Then the command works, but of course the URL is wrong then.

When using the same command with json notation:

yarn config set npmRegistries --json '{"//npm.example.com": {"npmAuthToken": "ffffffff-ffff-ffff-ffff-ffffffffffff"}}'

Results in:

Syntax Error: Unexpected token / in JSON at position 1
    at JSON.parse (<anonymous>)
    at Th.execute (C:\Users\MyUser\AppData\Local\node\corepack\yarn\4.0.2\yarn.js:407:1341)
    at async Th.validateAndExecute (C:\Users\MyUser\AppData\Local\node\corepack\yarn\4.0.2\yarn.js:94:787)
    at async as.run (C:\Users\MyUser\AppData\Local\node\corepack\yarn\4.0.2\yarn.js:98:3250)
    at async oPt (C:\Users\MyUser\AppData\Local\node\corepack\yarn\4.0.2\yarn.js:734:11269)
    at async sk (C:\Users\MyUser\AppData\Local\node\corepack\yarn\4.0.2\yarn.js:734:11625)

I did not get this command to run with --json option in any kind, results in error while parsing always. I've checked my notatation on a JSON validator though. There seems to be something odd when parsing the string parameter

To reproduce

Try executing the commands from the doc in a Windows powershell or cmd to reproduce.

Environment

System:
    OS: Windows 10 10.0.19044
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
  Binaries:
    Node: 18.16.0 - ~\AppData\Local\Temp\xfs-bec47249\node.CMD
    Yarn: 4.0.2 - ~\AppData\Local\Temp\xfs-bec47249\yarn.CMD
    npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.12.1 - C:\Program Files\nodejs\pnpm.CMD

Additional context

No response

julianess avatar Dec 21 '23 14:12 julianess

Found out, that the name of the config which is preserved to the command implementation of "config set" has already stripped away the quotes inside the brackets. The config name is given as npmRegistries[//npm.example.com].npmAuthToken. Since the quotes are lost, lodash.setPath is acting as the //npm.example.com is also a path on its own. Wrapping the bracket values in quotes again does workaround this issue but it might already be wrong transferred from the clipanion command implementation. Going to check this behavior on MacOS as well...

julianess avatar Dec 22 '23 11:12 julianess

On MacOS and Linux this is working fine, the URL in the brackets stays quoted.

julianess avatar Dec 22 '23 13:12 julianess