Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>

PR-URL: #2930
Credit: @jameschensmith
Close: #2930
Reviewed-by: @ruyadorno
  • Loading branch information
James Chen-Smith authored and ruyadorno committed Mar 24, 2021
commit 543b0e39bcb94fc408804b01ca9c0d7b960b2681
5 changes: 3 additions & 2 deletions lib/uninstall.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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