Skip to content

Commit

Permalink
explain-dep: handle shortening edge from root project
Browse files Browse the repository at this point in the history
Fixes: #2134
Credit: @isaacs
Close: #2156
Reviewed-by: @ruyadorno
  • Loading branch information
isaacs authored and darcyclarke committed Nov 13, 2020
1 parent 6d8d3cc commit 25afadd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
2 changes: 1 addition & 1 deletion lib/utils/explain-dep.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const explainDependents = ({ name, dependents }, depth, color) => {
const maxLen = 50
const showNames = []
for (let i = max; i < dependents.length; i++) {
const { from: { name } } = dependents[i]
const { from: { name = 'the root project' } } = dependents[i]
len += name.length
if (len >= maxLen && i < dependents.length - 1) {
showNames.push('...')
Expand Down
7 changes: 4 additions & 3 deletions tap-snapshots/test-lib-utils-explain-dep.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ manydep@1.0.0
manydep@"1.0.0" from prod-dep@1.2.3
node_modules/prod-dep
prod-dep@"1.x" from the root project
6 more (optdep, extra-neos, deep-dev, peer, ...)
7 more (optdep, extra-neos, deep-dev, peer, the root project, ...)
`

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

exports[`test/lib/utils/explain-dep.js TAP deepDev > explain color deep 1`] = `
Expand Down Expand Up @@ -90,6 +90,7 @@ exports[`test/lib/utils/explain-dep.js TAP manyDeps > explain color deep 1`] = `
peer manydep@">1.0.0-beta <1.0.1" from peer@1.0.0 peer
node_modules/peer
peer peer@"1.0.0" from the root project
manydep@">1.0.0-beta <1.0.1" from the root project
manydep@"1" from a package with a pretty long name@1.2.3
manydep@"1" from another package with a pretty long name@1.2.3
manydep@"1" from yet another a package with a pretty long name@1.2.3
Expand All @@ -100,7 +101,7 @@ manydep@1.0.0
manydep@"1.0.0" from prod-dep@1.2.3
node_modules/prod-dep
prod-dep@"1.x" from the root project
7 more (optdep, extra-neos, deep-dev, peer, ...)
8 more (optdep, extra-neos, deep-dev, peer, the root project, ...)
`

exports[`test/lib/utils/explain-dep.js TAP manyDeps > print color 1`] = `
Expand Down
89 changes: 48 additions & 41 deletions test/lib/utils/explain-dep.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const t = require('tap')
const requireInject = require('require-inject')
const npm = {}
const { explainNode, printNode } = requireInject('../../../lib/utils/explain-dep.js', {
'../../../lib/npm.js': npm
'../../../lib/npm.js': npm,
})

const cases = {
Expand All @@ -16,10 +16,10 @@ const cases = {
name: 'prod-dep',
spec: '1.x',
from: {
location: '/path/to/project'
}
}
]
location: '/path/to/project',
},
},
],
},

deepDev: {
Expand Down Expand Up @@ -51,16 +51,16 @@ const cases = {
name: 'topdev',
spec: '4.x',
from: {
location: '/path/to/project'
}
}
]
}
}
]
}
}
]
location: '/path/to/project',
},
},
],
},
},
],
},
},
],
},

optional: {
Expand All @@ -74,10 +74,10 @@ const cases = {
name: 'optdep',
spec: '1.0.0',
from: {
location: '/path/to/project'
}
}
]
location: '/path/to/project',
},
},
],
},

peer: {
Expand All @@ -91,19 +91,19 @@ const cases = {
name: 'peer',
spec: '1.0.0',
from: {
location: '/path/to/project'
}
}
]
location: '/path/to/project',
},
},
],
},

extraneous: {
name: 'extra-neos',
version: '1337.420.69-lol',
location: 'node_modules/extra-neos',
dependents: [],
extraneous: true
}
extraneous: true,
},
}

cases.manyDeps = {
Expand All @@ -114,31 +114,39 @@ cases.manyDeps = {
type: 'prod',
name: 'manydep',
spec: '1.0.0',
from: cases.prodDep
from: cases.prodDep,
},
{
type: 'optional',
name: 'manydep',
spec: '1.x',
from: cases.optional
from: cases.optional,
},
{
type: 'prod',
name: 'manydep',
spec: '1.0.x',
from: cases.extraneous
from: cases.extraneous,
},
{
type: 'dev',
name: 'manydep',
spec: '*',
from: cases.deepDev
from: cases.deepDev,
},
{
type: 'peer',
name: 'manydep',
spec: '>1.0.0-beta <1.0.1',
from: cases.peer
from: cases.peer,
},
{
type: 'prod',
name: 'manydep',
spec:'>1.0.0-beta <1.0.1',
from: {
location: '/path/to/project',
},
},
{
type: 'prod',
Expand All @@ -148,9 +156,9 @@ cases.manyDeps = {
name: 'a package with a pretty long name',
version: '1.2.3',
dependents: {
location: '/path/to/project'
}
}
location: '/path/to/project',
},
},
},
{
type: 'prod',
Expand All @@ -160,9 +168,9 @@ cases.manyDeps = {
name: 'another package with a pretty long name',
version: '1.2.3',
dependents: {
location: '/path/to/project'
}
}
location: '/path/to/project',
},
},
},
{
type: 'prod',
Expand All @@ -172,14 +180,13 @@ cases.manyDeps = {
name: 'yet another a package with a pretty long name',
version: '1.2.3',
dependents: {
location: '/path/to/project'
}
}
location: '/path/to/project',
},
},
},
]
],
}


for (const [name, expl] of Object.entries(cases)) {
t.test(name, t => {
npm.color = true
Expand Down

0 comments on commit 25afadd

Please sign in to comment.