Skip to content

Commit 016c778

Browse files
authored
fix(core): fixed SettingsType.ANY field not parsing correctly (#5091)
* test: it should correctly resolve "SettingsType.ANY" in the rc file * fix(core): fixed `SettingsType.ANY` field not parsing correctly
1 parent f9e0838 commit 016c778

File tree

4 files changed

+112
-1
lines changed

4 files changed

+112
-1
lines changed

.yarn/versions/72503862.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
releases:
2+
"@yarnpkg/core": minor
3+
4+
declined:
5+
- "@yarnpkg/plugin-compat"
6+
- "@yarnpkg/plugin-constraints"
7+
- "@yarnpkg/plugin-dlx"
8+
- "@yarnpkg/plugin-essentials"
9+
- "@yarnpkg/plugin-exec"
10+
- "@yarnpkg/plugin-file"
11+
- "@yarnpkg/plugin-git"
12+
- "@yarnpkg/plugin-github"
13+
- "@yarnpkg/plugin-http"
14+
- "@yarnpkg/plugin-init"
15+
- "@yarnpkg/plugin-interactive-tools"
16+
- "@yarnpkg/plugin-link"
17+
- "@yarnpkg/plugin-nm"
18+
- "@yarnpkg/plugin-npm"
19+
- "@yarnpkg/plugin-npm-cli"
20+
- "@yarnpkg/plugin-pack"
21+
- "@yarnpkg/plugin-patch"
22+
- "@yarnpkg/plugin-pnp"
23+
- "@yarnpkg/plugin-pnpm"
24+
- "@yarnpkg/plugin-stage"
25+
- "@yarnpkg/plugin-typescript"
26+
- "@yarnpkg/plugin-version"
27+
- "@yarnpkg/plugin-workspace-tools"
28+
- "@yarnpkg/builder"
29+
- "@yarnpkg/cli"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/extensions"
32+
- "@yarnpkg/nm"
33+
- "@yarnpkg/pnpify"
34+
- "@yarnpkg/sdks"

packages/yarnpkg-core/sources/Configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ function parseSingleValue(configuration: Configuration, path: string, valueBase:
702702

703703
switch (definition.type) {
704704
case SettingsType.ANY:
705-
return value;
705+
return configUtils.getValueByTree(value);
706706
case SettingsType.SHAPE:
707707
return parseShape(configuration, path, valueBase, definition, folder);
708708
case SettingsType.MAP:

packages/yarnpkg-core/sources/configUtils.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ export function getValue(value: unknown) {
196196
return isResolvedRcFile(value) ? value[1] : value;
197197
}
198198

199+
export function getValueByTree(valueBase: unknown): unknown {
200+
const value = isResolvedRcFile(valueBase) ? valueBase[1] : valueBase;
201+
202+
if (Array.isArray(value))
203+
return value.map(v => getValueByTree(v));
204+
205+
if (isObject(value)) {
206+
const result: {[key: string]: unknown} = {};
207+
for (const [propKey, propValue] of Object.entries(value))
208+
result[propKey] = getValueByTree(propValue);
209+
return result;
210+
}
211+
212+
return value;
213+
}
214+
199215
export function getSource(value: unknown) {
200216
return isResolvedRcFile(value) ? value[0] : null;
201217
}

packages/yarnpkg-core/tests/Configuration.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,26 @@ describe(`Configuration`, () => {
664664
},
665665
},
666666
},
667+
any: {
668+
description: "",
669+
type: "ANY",
670+
default: "",
671+
},
672+
anyReset: {
673+
description: "",
674+
type: "ANY",
675+
default: "",
676+
},
677+
anyExtend: {
678+
description: "",
679+
type: "ANY",
680+
default: "",
681+
},
682+
anyHardReset: {
683+
description: "",
684+
type: "ANY",
685+
default: "",
686+
},
667687
}`);
668688

669689
await initializeConfiguration({
@@ -700,6 +720,18 @@ describe(`Configuration`, () => {
700720
mapHardReset: {
701721
foo: {string: `foo`},
702722
},
723+
any: {
724+
foo: {string: `foo`},
725+
},
726+
anyReset: {
727+
foo: {string: `foo`},
728+
},
729+
anyExtend: {
730+
foo: {string: `foo`},
731+
},
732+
anyHardReset: {
733+
foo: {string: `foo`},
734+
},
703735
}, async dir => {
704736
const workspaceDirectory = `${dir}/workspace` as PortablePath;
705737
await xfs.mkdirPromise(workspaceDirectory);
@@ -772,6 +804,27 @@ describe(`Configuration`, () => {
772804
bar: {number: 2, string: `bar`},
773805
},
774806
},
807+
any: {
808+
bar: {number: 2, string: `bar`},
809+
},
810+
anyReset: {
811+
onConflict: `reset`,
812+
value: {
813+
bar: {number: 2, string: `bar`},
814+
},
815+
},
816+
anyExtend: {
817+
onConflict: `extend`,
818+
value: {
819+
bar: {number: 2, string: `bar`},
820+
},
821+
},
822+
anyHardReset: {
823+
onConflict: `hardReset`,
824+
value: {
825+
bar: {number: 2, string: `bar`},
826+
},
827+
},
775828
}));
776829

777830
const workspaceDirectory2 = `${dir}/workspace/workspace` as PortablePath;
@@ -785,6 +838,9 @@ describe(`Configuration`, () => {
785838
mapHardReset: {
786839
baz: {string: `baz`},
787840
},
841+
anyHardReset: {
842+
baz: {string: `baz`},
843+
},
788844
}));
789845

790846
const configuration = await Configuration.find(workspaceDirectory2, pluginConfiguration);
@@ -818,6 +874,11 @@ describe(`Configuration`, () => {
818874
expect(configuration.get(`mapHardReset`)).toEqual(new Map([
819875
[`baz`, new Map<string, any>([[`number`, 0], [`string`, `baz`]])],
820876
]));
877+
878+
expect(configuration.get(`any`)).toEqual({bar: {number: `2`, string: `bar`}, foo: {string: `foo`}});
879+
expect(configuration.get(`anyReset`)).toEqual({bar: {number: `2`, string: `bar`}});
880+
expect(configuration.get(`anyExtend`)).toEqual({bar: {number: `2`, string: `bar`}, foo: {string: `foo`}});
881+
expect(configuration.get(`anyHardReset`)).toEqual({baz: {string: `baz`}});
821882
});
822883
});
823884
});

0 commit comments

Comments
 (0)