Skip to content

Commit e37c0cd

Browse files
larsgwaeschright
authored andcommitted
ls: show installed but unmet peer deps (#145)
PR-URL: #145 Fixes: https://npm.community/t/4770 Credit: @larsgw Reviewed-By: @aeschright
1 parent 88cc4fc commit e37c0cd

File tree

2 files changed

+124
-1
lines changed

2 files changed

+124
-1
lines changed

lib/ls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ function filterFound (root, args) {
305305
if (!markDeps) continue
306306
Object.keys(markDeps).forEach(function (depName) {
307307
var dep = markDeps[depName]
308-
if (dep.peerMissing) return
308+
if (dep.peerMissing && !dep._from) return
309309
dep._parent = markPkg
310310
for (var ii = 0; ii < args.length; ii++) {
311311
var argName = args[ii][0]

test/tap/ls-peer.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
'use strict'
2+
const path = require('path')
3+
const test = require('tap').test
4+
const Tacks = require('tacks')
5+
const File = Tacks.File
6+
const Dir = Tacks.Dir
7+
const common = require('../common-tap.js')
8+
9+
const basedir = path.join(__dirname, path.basename(__filename, '.js'))
10+
const testdir = path.join(basedir, 'testdir')
11+
const cachedir = path.join(basedir, 'cache')
12+
const globaldir = path.join(basedir, 'global')
13+
const tmpdir = path.join(basedir, 'tmp')
14+
15+
const conf = {
16+
cwd: testdir,
17+
env: common.newEnv().extend({
18+
npm_config_cache: cachedir,
19+
npm_config_tmp: tmpdir,
20+
npm_config_prefix: globaldir,
21+
npm_config_registry: common.registry,
22+
npm_config_loglevel: 'warn'
23+
})
24+
}
25+
26+
const fixture = new Tacks(Dir({
27+
cache: Dir(),
28+
global: Dir(),
29+
tmp: Dir(),
30+
testdir: Dir({
31+
'package.json': File({
32+
name: 'fixture',
33+
version: '1.0.0',
34+
dependencies: {
35+
dep: 'file:dep-1.0.0.tgz',
36+
'peer-dep': 'file:peer-dep-2.0.0.tgz'
37+
}
38+
}),
39+
// Source dir
40+
// dep: Dir({
41+
// 'package.json': File({
42+
// name: 'dep',
43+
// version: '1.0.0',
44+
// peerDependencies: {
45+
// 'peer-dep': 'file:peer-dep-1.0.0.tgz'
46+
// }
47+
// })
48+
// }),
49+
'dep-1.0.0.tgz': File(Buffer.from(
50+
'1f8b0800000000000003ed8f3d0ec2300c853be71451661a1cd166e8cc45' +
51+
'a2d654e1278d92c200eadd491a60ea462584946fb1f5fc9e655bd59e548f' +
52+
'5b9b2a3ffac1142b0300b2aae8921e1152d062574b10424a08bed0d4d10f' +
53+
'6b1fb2c4d58fca8553bedd937ea19ffa273c08a5cca80bb286b20e2ddb44' +
54+
'e186ceebc1444d70e090548be8f668d174685a8d3e8c63fc3529633a040e' +
55+
'fa8ccd5b28e7381ffb3b0bce894ce4d70f6732994c66e60975aec5690008' +
56+
'0000',
57+
'hex'
58+
)),
59+
// Source dir
60+
// 'peer-dep': Dir({
61+
// 'package.json': File({
62+
// name: 'peer-dep',
63+
// version: '2.0.0'
64+
// })
65+
// }),
66+
'peer-dep-1.0.0.tgz': File(Buffer.from(
67+
'1f8b08000000000000032b484cce4e4c4fd52f80d07a59c5f9790c540606' +
68+
'06066626260ad8c4c1c0d45c81c1d8d4ccc0d0d0cccc00a80ec830353500' +
69+
'd2d4760836505a5c925804740aa5e640bca200a78708a8e6525050ca4bcc' +
70+
'4d55b252502a484d2dd24d492d50d2018996a5161567e6e781240cf50cf4' +
71+
'0c94b86ab906dab9a360148c8251300aa80400c1c67f6300080000',
72+
'hex'
73+
)),
74+
'peer-dep-2.0.0.tgz': File(Buffer.from(
75+
'1f8b08000000000000032b484cce4e4c4fd52f80d07a59c5f9790c540606' +
76+
'06066626260ad8c4c1c0d45c81c1d8d4ccc0d0d0cccc00a80ec830353500' +
77+
'd2d4760836505a5c925804740aa5e640bca200a78708a8e6525050ca4bcc' +
78+
'4d55b252502a484d2dd24d492d50d2018996a5161567e6e781248cf40cf4' +
79+
'0c94b86ab906dab9a360148c8251300aa80400cb30060800080000',
80+
'hex'
81+
))
82+
})
83+
}))
84+
85+
function setup () {
86+
cleanup()
87+
fixture.create(basedir)
88+
}
89+
90+
function cleanup () {
91+
fixture.remove(basedir)
92+
}
93+
94+
test('setup', t => {
95+
setup()
96+
return common.fakeRegistry.listen().then(() => common.npm(['install'], conf))
97+
})
98+
99+
test('list warns about unmet peer dependency', t => {
100+
return common.npm(['ls'], conf).then(([code, stdout, stderr]) => {
101+
t.is(code, 1, 'command ran not ok')
102+
t.comment(stdout.trim())
103+
t.comment(stderr.trim())
104+
t.match(stdout, 'UNMET PEER DEPENDENCY [email protected]')
105+
t.match(stderr, 'npm ERR! peer dep missing: peer-dep@file:peer-dep-1.0.0.tgz, required by [email protected]')
106+
})
107+
})
108+
109+
test('list shows installed but unmet peer dependency', t => {
110+
return common.npm(['ls', 'peer-dep'], conf).then(([code, stdout, stderr]) => {
111+
t.is(code, 1, 'command ran not ok')
112+
t.comment(stdout.trim())
113+
t.comment(stderr.trim())
114+
t.match(stdout, 'UNMET PEER DEPENDENCY [email protected]')
115+
t.match(stderr, 'npm ERR! peer dep missing: peer-dep@file:peer-dep-1.0.0.tgz, required by [email protected]')
116+
})
117+
})
118+
119+
test('cleanup', t => {
120+
common.fakeRegistry.close()
121+
cleanup()
122+
t.done()
123+
})

0 commit comments

Comments
 (0)