Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw an error when trying to dedupe in global mode #2716

Merged
merged 1 commit into from Feb 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/dedupe.js
Expand Up @@ -10,6 +10,12 @@ const completion = require('./utils/completion/none.js')
const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb)

const dedupe = async (args) => {
if (npm.flatOptions.global) {
const er = new Error('`npm dedupe` does not work in global mode.')
er.code = 'EDEDUPEGLOBAL'
throw er
}

const dryRun = (args && args.dryRun) || npm.flatOptions.dryRun
const where = npm.prefix
const arb = new Arborist({
Expand Down
15 changes: 15 additions & 0 deletions test/lib/dedupe.js
@@ -1,6 +1,21 @@
const { test } = require('tap')
const requireInject = require('require-inject')

test('should throw in global mode', (t) => {
const dedupe = requireInject('../../lib/dedupe.js', {
'../../lib/npm.js': {
flatOptions: {
global: true,
},
},
})

dedupe([], er => {
t.match(er, { code: 'EDEDUPEGLOBAL' }, 'throws EDEDUPEGLOBAL')
t.end()
})
})

test('should remove dupes using Arborist', (t) => {
const dedupe = requireInject('../../lib/dedupe.js', {
'../../lib/npm.js': {
Expand Down