Skip to content

Commit f1c6024

Browse files
committed
throw an error when trying to dedupe in global mode
1 parent e703362 commit f1c6024

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/dedupe.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ const completion = require('./utils/completion/none.js')
1010
const cmd = (args, cb) => dedupe(args).then(() => cb()).catch(cb)
1111

1212
const dedupe = async (args) => {
13+
if (npm.flatOptions.global) {
14+
const er = new Error('`npm dedupe` does not work in global mode.')
15+
er.code = 'EDEDUPEGLOBAL'
16+
throw er
17+
}
18+
1319
const dryRun = (args && args.dryRun) || npm.flatOptions.dryRun
1420
const where = npm.prefix
1521
const arb = new Arborist({

test/lib/dedupe.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
const { test } = require('tap')
22
const requireInject = require('require-inject')
33

4+
test('should throw in global mode', (t) => {
5+
const dedupe = requireInject('../../lib/dedupe.js', {
6+
'../../lib/npm.js': {
7+
flatOptions: {
8+
global: true,
9+
},
10+
},
11+
})
12+
13+
dedupe([], er => {
14+
t.match(er, { code: 'EDEDUPEGLOBAL' }, 'throws EDEDUPEGLOBAL')
15+
t.end()
16+
})
17+
})
18+
419
test('should remove dupes using Arborist', (t) => {
520
const dedupe = requireInject('../../lib/dedupe.js', {
621
'../../lib/npm.js': {

0 commit comments

Comments
 (0)