From c5c6d1603b06df4c10b503047aeed34d6e0c36c2 Mon Sep 17 00:00:00 2001 From: Yucel Okcu Date: Thu, 18 Nov 2021 18:48:17 +0300 Subject: [PATCH] fix: add missing scope on flat options PR-URL: https://github.com/npm/cli/pull/4060 Credit: @yuqu Close: #4060 Reviewed-by: @wraithgar --- lib/utils/config/definitions.js | 5 ++++- test/lib/utils/config/definitions.js | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index b47a46de85e2e..5bd13ac81a479 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -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 }, }) diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js index f6813a8bc0bb5..7af0b683987e4 100644 --- a/test/lib/utils/config/definitions.js +++ b/test/lib/utils/config/definitions.js @@ -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() })