Skip to content

Commit 4da8346

Browse files
committed
feat: allows yarn to get the current value when parsing the rcfile
1 parent 77e525a commit 4da8346

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/yarnpkg-core/sources/Configuration.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,26 @@ export type ConfigurationDefinitionMap<V = ConfigurationValueMap> = {
662662
[K in keyof V]: DefinitionForType<V[K]>;
663663
};
664664

665+
function getCurrentValue(configuration: Configuration, path: string): unknown {
666+
const keys = path.split(`.`);
667+
const currentValue = keys.reduce((prev, currentKey) => {
668+
if (prev instanceof Map)
669+
return prev?.get(currentKey);
670+
671+
return prev?.[currentKey];
672+
}, configuration.values);
673+
674+
return currentValue;
675+
}
676+
665677
function parseValue(configuration: Configuration, path: string, value: unknown, definition: SettingsDefinition, folder: PortablePath) {
666678
if (definition.isArray || (definition.type === SettingsType.ANY && Array.isArray(value))) {
667679
if (!Array.isArray(value)) {
668680
return String(value).split(/,/).map(segment => {
669681
return parseSingleValue(configuration, path, segment, definition, folder);
670682
});
671683
} else {
672-
return value.map((sub, i) => parseSingleValue(configuration, `${path}[${i}]`, sub, definition, folder));
684+
return value.map((sub, i) => parseSingleValue(configuration, `${path}.${i}`, sub, definition, folder));
673685
}
674686
} else {
675687
if (Array.isArray(value)) {
@@ -766,7 +778,7 @@ function parseMap(configuration: Configuration, path: string, value: unknown, de
766778

767779
for (const [propKey, propValue] of Object.entries(value)) {
768780
const normalizedKey = definition.normalizeKeys ? definition.normalizeKeys(propKey) : propKey;
769-
const subPath = `${path}['${normalizedKey}']`;
781+
const subPath = `${path}.${normalizedKey}`;
770782

771783
// @ts-expect-error: SettingsDefinitionNoDefault has ... no default ... but
772784
// that's fine because we're guaranteed it's not undefined.

0 commit comments

Comments
 (0)