Skip to content

Commit 25afadd

Browse files
isaacsdarcyclarke
authored andcommitted
explain-dep: handle shortening edge from root project
Fixes: #2134 Credit: @isaacs Close: #2156 Reviewed-by: @ruyadorno
1 parent 6d8d3cc commit 25afadd

File tree

3 files changed

+53
-45
lines changed

3 files changed

+53
-45
lines changed

lib/utils/explain-dep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const explainDependents = ({ name, dependents }, depth, color) => {
6464
const maxLen = 50
6565
const showNames = []
6666
for (let i = max; i < dependents.length; i++) {
67-
const { from: { name } } = dependents[i]
67+
const { from: { name = 'the root project' } } = dependents[i]
6868
len += name.length
6969
if (len >= maxLen && i < dependents.length - 1) {
7070
showNames.push('...')

tap-snapshots/test-lib-utils-explain-dep.js-TAP.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ [email protected]
1010
manydep@"1.0.0" from [email protected]
1111
node_modules/prod-dep
1212
prod-dep@"1.x" from the root project
13-
6 more (optdep, extra-neos, deep-dev, peer, ...)
13+
7 more (optdep, extra-neos, deep-dev, peer, the root project, ...)
1414
`
1515

1616
exports[`test/lib/utils/explain-dep.js TAP > ellipses test two 1`] = `
1717
1818
manydep@"1.0.0" from [email protected]
1919
node_modules/prod-dep
2020
prod-dep@"1.x" from the root project
21-
5 more (optdep, extra-neos, deep-dev, peer, a package with a pretty long name)
21+
6 more (optdep, extra-neos, deep-dev, peer, the root project, a package with a pretty long name)
2222
`
2323

2424
exports[`test/lib/utils/explain-dep.js TAP deepDev > explain color deep 1`] = `
@@ -90,6 +90,7 @@ exports[`test/lib/utils/explain-dep.js TAP manyDeps > explain color deep 1`] = `
9090
peer manydep@">1.0.0-beta <1.0.1" from peer@1.0.0 peer
9191
node_modules/peer
9292
peer peer@"1.0.0" from the root project
93+
manydep@">1.0.0-beta <1.0.1" from the root project
9394
manydep@"1" from a package with a pretty long name@1.2.3
9495
manydep@"1" from another package with a pretty long name@1.2.3
9596
manydep@"1" from yet another a package with a pretty long name@1.2.3
@@ -100,7 +101,7 @@ [email protected]
100101
manydep@"1.0.0" from [email protected]
101102
node_modules/prod-dep
102103
prod-dep@"1.x" from the root project
103-
7 more (optdep, extra-neos, deep-dev, peer, ...)
104+
8 more (optdep, extra-neos, deep-dev, peer, the root project, ...)
104105
`
105106

106107
exports[`test/lib/utils/explain-dep.js TAP manyDeps > print color 1`] = `

test/lib/utils/explain-dep.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const t = require('tap')
22
const requireInject = require('require-inject')
33
const npm = {}
44
const { explainNode, printNode } = requireInject('../../../lib/utils/explain-dep.js', {
5-
'../../../lib/npm.js': npm
5+
'../../../lib/npm.js': npm,
66
})
77

88
const cases = {
@@ -16,10 +16,10 @@ const cases = {
1616
name: 'prod-dep',
1717
spec: '1.x',
1818
from: {
19-
location: '/path/to/project'
20-
}
21-
}
22-
]
19+
location: '/path/to/project',
20+
},
21+
},
22+
],
2323
},
2424

2525
deepDev: {
@@ -51,16 +51,16 @@ const cases = {
5151
name: 'topdev',
5252
spec: '4.x',
5353
from: {
54-
location: '/path/to/project'
55-
}
56-
}
57-
]
58-
}
59-
}
60-
]
61-
}
62-
}
63-
]
54+
location: '/path/to/project',
55+
},
56+
},
57+
],
58+
},
59+
},
60+
],
61+
},
62+
},
63+
],
6464
},
6565

6666
optional: {
@@ -74,10 +74,10 @@ const cases = {
7474
name: 'optdep',
7575
spec: '1.0.0',
7676
from: {
77-
location: '/path/to/project'
78-
}
79-
}
80-
]
77+
location: '/path/to/project',
78+
},
79+
},
80+
],
8181
},
8282

8383
peer: {
@@ -91,19 +91,19 @@ const cases = {
9191
name: 'peer',
9292
spec: '1.0.0',
9393
from: {
94-
location: '/path/to/project'
95-
}
96-
}
97-
]
94+
location: '/path/to/project',
95+
},
96+
},
97+
],
9898
},
9999

100100
extraneous: {
101101
name: 'extra-neos',
102102
version: '1337.420.69-lol',
103103
location: 'node_modules/extra-neos',
104104
dependents: [],
105-
extraneous: true
106-
}
105+
extraneous: true,
106+
},
107107
}
108108

109109
cases.manyDeps = {
@@ -114,31 +114,39 @@ cases.manyDeps = {
114114
type: 'prod',
115115
name: 'manydep',
116116
spec: '1.0.0',
117-
from: cases.prodDep
117+
from: cases.prodDep,
118118
},
119119
{
120120
type: 'optional',
121121
name: 'manydep',
122122
spec: '1.x',
123-
from: cases.optional
123+
from: cases.optional,
124124
},
125125
{
126126
type: 'prod',
127127
name: 'manydep',
128128
spec: '1.0.x',
129-
from: cases.extraneous
129+
from: cases.extraneous,
130130
},
131131
{
132132
type: 'dev',
133133
name: 'manydep',
134134
spec: '*',
135-
from: cases.deepDev
135+
from: cases.deepDev,
136136
},
137137
{
138138
type: 'peer',
139139
name: 'manydep',
140140
spec: '>1.0.0-beta <1.0.1',
141-
from: cases.peer
141+
from: cases.peer,
142+
},
143+
{
144+
type: 'prod',
145+
name: 'manydep',
146+
spec:'>1.0.0-beta <1.0.1',
147+
from: {
148+
location: '/path/to/project',
149+
},
142150
},
143151
{
144152
type: 'prod',
@@ -148,9 +156,9 @@ cases.manyDeps = {
148156
name: 'a package with a pretty long name',
149157
version: '1.2.3',
150158
dependents: {
151-
location: '/path/to/project'
152-
}
153-
}
159+
location: '/path/to/project',
160+
},
161+
},
154162
},
155163
{
156164
type: 'prod',
@@ -160,9 +168,9 @@ cases.manyDeps = {
160168
name: 'another package with a pretty long name',
161169
version: '1.2.3',
162170
dependents: {
163-
location: '/path/to/project'
164-
}
165-
}
171+
location: '/path/to/project',
172+
},
173+
},
166174
},
167175
{
168176
type: 'prod',
@@ -172,14 +180,13 @@ cases.manyDeps = {
172180
name: 'yet another a package with a pretty long name',
173181
version: '1.2.3',
174182
dependents: {
175-
location: '/path/to/project'
176-
}
177-
}
183+
location: '/path/to/project',
184+
},
185+
},
178186
},
179-
]
187+
],
180188
}
181189

182-
183190
for (const [name, expl] of Object.entries(cases)) {
184191
t.test(name, t => {
185192
npm.color = true

0 commit comments

Comments
 (0)