From 543b0e39bcb94fc408804b01ca9c0d7b960b2681 Mon Sep 17 00:00:00 2001 From: James Chen-Smith Date: Tue, 23 Mar 2021 21:15:39 -0500 Subject: [PATCH] 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))