From 543b0e39bcb94fc408804b01ca9c0d7b960b2681 Mon Sep 17 00:00:00 2001 From: James Chen-Smith Date: Tue, 23 Mar 2021 21:15:39 -0500 Subject: [PATCH 1/5] fix(uninstall): use correct local prefix Corrects non-global prefix path by using this.npm.localPrefix. A location already used throughout the repository. Later, this will be taken from the unified config library. Signed-off-by: James Chen-Smith PR-URL: https://github.com/npm/cli/pull/2930 Credit: @jameschensmith Close: #2930 Reviewed-by: @ruyadorno --- lib/uninstall.js | 5 +++-- test/lib/uninstall.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/uninstall.js b/lib/uninstall.js index 11e65533a8e98..dfdd8ebd5a1db 100644 --- a/lib/uninstall.js +++ b/lib/uninstall.js @@ -38,8 +38,9 @@ class Uninstall extends BaseCommand { async uninstall (args) { // the /path/to/node_modules/.. const global = this.npm.config.get('global') - const prefix = this.npm.config.get('prefix') - const path = global ? resolve(this.npm.globalDir, '..') : prefix + const path = global + ? resolve(this.npm.globalDir, '..') + : this.npm.localPrefix if (!args.length) { if (!global) diff --git a/test/lib/uninstall.js b/test/lib/uninstall.js index 5cb8a243ec19b..589191ea28e6b 100644 --- a/test/lib/uninstall.js +++ b/test/lib/uninstall.js @@ -22,6 +22,7 @@ const uninstall = new Uninstall(npm) t.afterEach(cb => { npm.globalDir = '' npm.prefix = '' + npm.localPrefix = '' npm.flatOptions.global = false npm.flatOptions.prefix = '' cb() @@ -85,7 +86,7 @@ t.test('remove single installed lib', t => { const b = resolve(path, 'node_modules/b') t.ok(() => fs.statSync(b)) - npm.config.set('prefix', path) + npm.localPrefix = path uninstall.exec(['b'], err => { if (err) @@ -148,7 +149,7 @@ t.test('remove multiple installed libs', t => { t.ok(() => fs.statSync(a)) t.ok(() => fs.statSync(b)) - npm.config.set('prefix', path) + npm.localPrefix = path uninstall.exec(['b'], err => { if (err) @@ -196,7 +197,6 @@ t.test('no args global', t => { npm.localPrefix = resolve(path, 'projects', 'a') npm.globalDir = resolve(path, 'lib', 'node_modules') npm.config.set('global', true) - npm.config.set('prefix', path) const a = resolve(path, 'lib/node_modules/a') t.ok(() => fs.statSync(a)) From dce4960ef6d52af128affe7755b2ca72de913b6c Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 24 Mar 2021 07:40:21 -0700 Subject: [PATCH 2/5] fix(config): flatten savePrefix properly It needs to take save-exact into consideration Closes: https://github.com/npm/cli/issues/2932 PR-URL: https://github.com/npm/cli/pull/2937 Credit: @wraithgar Close: #2937 Reviewed-by: @ruyadorno --- lib/utils/config/definitions.js | 4 +++- test/lib/utils/config/definitions.js | 15 +++++++++++++++ test/lib/utils/config/flatten.js | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/utils/config/definitions.js b/lib/utils/config/definitions.js index a6ecbcd0c40a5..5001efb461b9c 100644 --- a/lib/utils/config/definitions.js +++ b/lib/utils/config/definitions.js @@ -1581,7 +1581,9 @@ define('save-prefix', { \`npm config set save-prefix='~'\` it would be set to \`~1.2.3\` which only allows patch upgrades. `, - flatten, + flatten (key, obj, flatOptions) { + flatOptions.savePrefix = obj['save-exact'] ? '' : obj['save-prefix'] + }, }) define('save-prod', { diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js index 3169feefb8f91..830468c4391ac 100644 --- a/test/lib/utils/config/definitions.js +++ b/test/lib/utils/config/definitions.js @@ -695,3 +695,18 @@ t.test('user-agent', t => { t.equal(flat.userAgent, expectCI) t.end() }) + +t.test('save-prefix', t => { + const obj = { + 'save-exact': true, + 'save-prefix': '~1.2.3', + } + const flat = {} + definitions['save-prefix'] + .flatten('save-prefix', { ...obj, 'save-exact': true }, flat) + t.strictSame(flat, { savePrefix: '' }) + definitions['save-prefix'] + .flatten('save-prefix', { ...obj, 'save-exact': false }, flat) + t.strictSame(flat, { savePrefix: '~1.2.3' }) + t.end() +}) diff --git a/test/lib/utils/config/flatten.js b/test/lib/utils/config/flatten.js index 9fac0820cb0ea..6fc91b4847e38 100644 --- a/test/lib/utils/config/flatten.js +++ b/test/lib/utils/config/flatten.js @@ -6,6 +6,8 @@ delete process.env.NODE process.execPath = '/path/to/node' const obj = { + 'save-exact': true, + 'save-prefix': 'ignored', 'save-dev': true, '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', @@ -15,6 +17,8 @@ const obj = { const flat = flatten(obj) t.strictSame(flat, { saveType: 'dev', + saveExact: true, + savePrefix: '', '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', npmBin: '/path/to/npm', @@ -26,6 +30,8 @@ t.strictSame(flat, { process.env.NODE = '/usr/local/bin/node.exe' flatten({ 'save-dev': false }, flat) t.strictSame(flat, { + saveExact: true, + savePrefix: '', '@foobar:registry': 'https://foo.bar.com/', '//foo.bar.com:_authToken': 'foobarbazquuxasdf', npmBin: '/path/to/npm', From 87fa877c179aa85a07a7bc2882657530b0fdf2db Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Wed, 24 Mar 2021 10:56:12 -0400 Subject: [PATCH 3/5] docs: changelog for v7.7.1 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c11a44734ae8e..4fc9ceb4dbd93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +## v7.7.1 (2021-03-24) + +### BUG FIXES + +* [`543b0e39b`](https://github.com/npm/cli/commit/543b0e39bcb94fc408804b01ca9c0d7b960b2681) + [#2930](https://github.com/npm/cli/issues/2930) + fix(uninstall): use correct local prefix + ([@jameschensmith](https://github.com/jameschensmith)) +* [`dce4960ef`](https://github.com/npm/cli/commit/dce4960ef6d52af128affe7755b2ca72de913b6c) + [#2932](https://github.com/npm/cli/issues/2932) + fix(config): flatten savePrefix properly + ([@wraithgar](https://github.com/wraithgar)) + ## v7.7.0 (2021-03-23) ### FEATURES From 9d0a9533f77f08d8e4aa14a5abf61b1ceaebc4fc Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Wed, 24 Mar 2021 10:56:21 -0400 Subject: [PATCH 4/5] update AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 9c67cf88ef250..0cddb173c2bf5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -765,3 +765,4 @@ Jan Sepke <625043+jansepke@users.noreply.github.com> Augusto Moura Eric Chow kbayrhammer +James Chen-Smith From e32d94b5aa421b9b80a8fcd85f862a8259fb33a9 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Wed, 24 Mar 2021 10:56:21 -0400 Subject: [PATCH 5/5] 7.7.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 983683b4446f3..ae3f1bc4b54b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "npm", - "version": "7.7.0", + "version": "7.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "npm", - "version": "7.7.0", + "version": "7.7.1", "bundleDependencies": [ "@npmcli/arborist", "@npmcli/ci-detect", diff --git a/package.json b/package.json index c4b10a831b610..2380ce20c68ac 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "7.7.0", + "version": "7.7.1", "name": "npm", "description": "a package manager for JavaScript", "keywords": [