Skip to content

Commit f2f4194

Browse files
authored
fix(ncu-config): allow overriding global encrypted keys with local ones (#1030)
If a value is defined locally, it should make no difference whether the associated key is present or not in the global config. Also fix a bug where the `additional` being ignored if config was previously merged.
1 parent 478250b commit f2f4194

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,21 @@ export function getMergedConfig(dir, home, additional) {
2525
const globalConfig = getConfig(GLOBAL_CONFIG, home);
2626
const projectConfig = getConfig(PROJECT_CONFIG, dir);
2727
const localConfig = getConfig(LOCAL_CONFIG, dir);
28-
mergedConfig = Object.assign(globalConfig, projectConfig, localConfig, additional);
28+
29+
// Using property descriptors to avoid calling any setter if e.g. a
30+
// localConfig value overrides a globalConfig key.
31+
mergedConfig = Object.create(null, {
32+
...Object.getOwnPropertyDescriptors(globalConfig),
33+
...Object.getOwnPropertyDescriptors(projectConfig),
34+
...Object.getOwnPropertyDescriptors(localConfig),
35+
});
2936
}
30-
return mergedConfig;
37+
return additional
38+
? Object.create(null, {
39+
...Object.getOwnPropertyDescriptors(mergedConfig),
40+
...Object.getOwnPropertyDescriptors(additional),
41+
})
42+
: mergedConfig;
3143
};
3244
export function clearCachedConfig() {
3345
mergedConfig = null;

0 commit comments

Comments
 (0)