Skip to content

Commit

Permalink
fix(uninstall): use correct local prefix
Browse files Browse the repository at this point in the history
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 <jameschensmith@gmail.com>

PR-URL: #2930
Credit: @jameschensmith
Close: #2930
Reviewed-by: @ruyadorno
  • Loading branch information
James Chen-Smith authored and ruyadorno committed Mar 24, 2021
1 parent 581b60b commit 543b0e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/uninstall.js
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/lib/uninstall.js
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 543b0e3

Please sign in to comment.