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

explain-dep: handle shortening edge from root project #2156

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const errorHandler = (er) => {
detail: messageText(msg.detail),
},
}
console.log(JSON.stringify(error, null, 2))
console.error(JSON.stringify(error, null, 2))
}

exit(typeof er.errno === 'number' ? er.errno : typeof er.code === 'number' ? er.code : 1)
Expand Down
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 @@ [email protected]
manydep@"1.0.0" from [email protected]
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`] = `
[email protected]
manydep@"1.0.0" from [email protected]
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 @@ [email protected]
manydep@"1.0.0" from [email protected]
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
6 changes: 3 additions & 3 deletions test/lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ t.test('console.log output using --json', (t) => {

config.values.json = true

const _log = console.log
console.log = (jsonOutput) => {
const _error = console.error
console.error = (jsonOutput) => {
t.deepEqual(
JSON.parse(jsonOutput),
{
Expand All @@ -236,7 +236,7 @@ t.test('console.log output using --json', (t) => {
errorHandler(new Error('Error: EBADTHING Something happened'))

t.teardown(() => {
console.log = _log
console.error = _error
delete config.values.json
})
})
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