Skip to content

Commit

Permalink
fix: add missing scope on flat options
Browse files Browse the repository at this point in the history
PR-URL: #4060
Credit: @yuqu
Close: #4060
Reviewed-by: @wraithgar
  • Loading branch information
yuqu authored and wraithgar committed Nov 22, 2021
1 parent 5f4040a commit c5c6d16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,10 @@ define('scope', {
`,
flatten (key, obj, flatOptions) {
const value = obj[key]
flatOptions.projectScope = value && !/^@/.test(value) ? `@${value}` : value
const scope = value && !/^@/.test(value) ? `@${value}` : value
flatOptions.scope = scope
// projectScope is kept for compatibility with npm-registry-fetch
flatOptions.projectScope = scope
},
})

Expand Down
6 changes: 3 additions & 3 deletions test/lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,15 @@ t.test('maxSockets', t => {
t.end()
})

t.test('projectScope', t => {
t.test('scope', t => {
const obj = { scope: 'asdf' }
const flat = {}
definitions.scope.flatten('scope', obj, flat)
t.strictSame(flat, { projectScope: '@asdf' }, 'prepend @ if needed')
t.strictSame(flat, { scope: '@asdf', projectScope: '@asdf' }, 'prepend @ if needed')

obj.scope = '@asdf'
definitions.scope.flatten('scope', obj, flat)
t.strictSame(flat, { projectScope: '@asdf' }, 'leave untouched if has @')
t.strictSame(flat, { scope: '@asdf', projectScope: '@asdf' }, 'leave untouched if has @')

t.end()
})
Expand Down

0 comments on commit c5c6d16

Please sign in to comment.