diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index 86e07aee74e71..74a4c6b8dc6aa 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -1129,7 +1129,11 @@ define('location', { description: ` When passed to \`npm config\` this refers to which config file to use. `, - flatten, + flatten: (key, obj, flatOptions) => { + flatten(key, obj, flatOptions) + if (flatOptions.global) + flatOptions.location = 'global' + }, }) define('loglevel', { diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js index 63d9bbd195ab2..a32e55c29f8d6 100644 --- a/test/lib/utils/config/definitions.js +++ b/test/lib/utils/config/definitions.js @@ -812,19 +812,23 @@ t.test('location', t => { location: 'user', } const flat = {} + // the global flattener is what sets location, so run that + definitions.global.flatten('global', obj, flat) definitions.location.flatten('location', obj, flat) // global = true sets location in both places to global - t.strictSame(flat, { location: 'global' }) - t.strictSame(obj, { global: true, location: 'global' }) + t.strictSame(flat, { global: true, location: 'global' }) + // location here is still 'user' because flattening doesn't modify the object + t.strictSame(obj, { global: true, location: 'user' }) obj.global = false obj.location = 'user' delete flat.global delete flat.location + definitions.global.flatten('global', obj, flat) definitions.location.flatten('location', obj, flat) // global = false leaves location unaltered - t.strictSame(flat, { location: 'user' }) + t.strictSame(flat, { global: false, location: 'user' }) t.strictSame(obj, { global: false, location: 'user' }) t.end() })