feat(cli/config): get/set objects and property paths#9811
Conversation
| return { output: Array.isArray(config) ? config.join(',') : String(config), exitCode: 0 } | ||
| let output: string | ||
| if (Array.isArray(config)) { | ||
| output = config.join(',') |
There was a problem hiding this comment.
This was on me: #7917. I don't remember why I decided to return a comma-separated list instead of a JSON string, but changing it now would be a breaking change.
|
I do feel that
|
|
Yes, probably we should support that. But I think the field names should be separated by dots: |
|
|
And escaping is necessary because dependency names can contain all kinds of symbols: |
|
See how Yarn also supports this: https://yarnpkg.com/cli/config/set We can check what library Yarn uses. It should be something small. |
3b1a9ef to
e28f84f
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
8161463 to
0dc5e8d
Compare
0dc5e8d to
aeef6df
Compare
Discovered flawsNote The following flaws can't be fixed without breaking changes.
|
config get prints json for objectThis reverts commit 66add58.
| export class ConfigSetDeepKeyError extends PnpmError { | ||
| constructor () { | ||
| // it shouldn't be supported until there is a mechanism to validate the config value | ||
| super('CONFIG_SET_DEEP_KEY', 'Setting deep property path is not supported') |
There was a problem hiding this comment.
This error breaks pnpm config set supportedArchitectures.cpu "${CPU_ARCH}", what's the replacement then?
There was a problem hiding this comment.
It does not break. It only reveals a flawed assumption.
pnpm config set supportedArchitectures.cpu doesn't actually do what you think it does:
As you can see, it didn't actually create an object named supportedArchitectures with the content { "cpu": "x64" }. Instead, it added a field named supported-architectures-cpu to the global rc file.
what's the replacement then?
Write a small JS script that modifies package.json. This applies to older pnpm too (because it has never worked with older pnpm, it's just that they don't print error).
There was a problem hiding this comment.
@KSXGitHub But config get works after config set previously.
Anyway, we want to modify the global pnpm config without changing the source files, it seems impossible now?
Personally, I think merging this PR without implementing setting correctly is incomplete and should be considered as BREAKING CHNAGE.
There was a problem hiding this comment.
pnpm config get supportedArchitectures.cpu is literally the same as pnpm config get supported-architectures-cpu (there's no object path, just a property name that makes no sense). You were already misusing it before, removing it has zero effect.
Anyway, we want to modify the global pnpm config without changing the source files, it seems impossible now?
pnpm has never read supportedArchitectures from rc files, be it local or global. The fact pnpm get makes it seems like your use-case has effect was just an illusion caused by ill-thought-out config implementation. But the loading code has always only loads fields that appear in types (which doesn't include supportedArchitectures):
pnpm/config/config/src/index.ts
Lines 238 to 240 in 6aaf938
In other words, it was always impossible, it's just that older pnpm versions silently ignored the error.
BREAKING CHNAGE
I certainly didn't think anybody would be mistakenly believing that pnpm supports property paths, but then I have insight from the code itself. Regardless though, I don't think it's a breaking change because it doesn't actually break legitimate use-cases, it only reveals a nonsense use-case that doesn't do anything.
You may believe that temporary downgrade pnpm would fix the problem, but it actually doesn't, because as I already explained: pnpm get/set supportedArchitectures.cpu doesn't do anything except reading/setting supported-architectures-cpu which has zero effect. It is the same as not doing anything at all. The only way to fix the problem is to replace the wrong pnpm config set with a script that modifies either package.json or pnpm-workspace.yaml.
There was a problem hiding this comment.
BTW, I also made a suggestion to your PR.

Resolves #9797