Skip to content

Commit

Permalink
fixup! fix(config): respect --global correctly, closes #3572
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Aug 24, 2021
1 parent 33abbbf commit 7d7e037
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/utils/config/definitions.js
Expand Up @@ -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', {
Expand Down
10 changes: 7 additions & 3 deletions test/lib/utils/config/definitions.js
Expand Up @@ -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()
})

0 comments on commit 7d7e037

Please sign in to comment.