Skip to content

Commit 983d218

Browse files
kumaviswraithgar
authored andcommitted
fix(explain): mark when dependency is bundled
When using `npm explain <package>` it's useful to see if the package has been bundled. This is especially useful when trying to understand the provenance of a package's content PR-URL: #2750 Credit: @kumavis Close: #2750 Reviewed-by: @nlf
1 parent 28d036a commit 983d218

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

lib/explain.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const explain = async (args) => {
3030

3131
const expls = []
3232
for (const node of nodes) {
33-
const { extraneous, dev, optional, devOptional, peer } = node
33+
const { extraneous, dev, optional, devOptional, peer, inBundle } = node
3434
const expl = node.explain()
3535
if (extraneous)
3636
expl.extraneous = true
@@ -39,6 +39,7 @@ const explain = async (args) => {
3939
expl.optional = optional
4040
expl.devOptional = devOptional
4141
expl.peer = peer
42+
expl.bundled = inBundle
4243
}
4344
expls.push(expl)
4445
}

lib/utils/explain-dep.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ const nocolor = {
66
yellow: s => s,
77
cyan: s => s,
88
magenta: s => s,
9+
blue: s => s,
910
}
1011

1112
const explainNode = (node, depth, color) =>
1213
printNode(node, color) +
1314
explainDependents(node, depth, color)
1415

1516
const colorType = (type, color) => {
16-
const { red, yellow, cyan, magenta } = color ? chalk : nocolor
17+
const { red, yellow, cyan, magenta, blue } = color ? chalk : nocolor
1718
const style = type === 'extraneous' ? red
1819
: type === 'dev' ? yellow
1920
: type === 'optional' ? cyan
2021
: type === 'peer' ? magenta
22+
: type === 'bundled' ? blue
2123
: /* istanbul ignore next */ s => s
2224
return style(type)
2325
}
@@ -31,6 +33,7 @@ const printNode = (node, color) => {
3133
dev,
3234
optional,
3335
peer,
36+
bundled,
3437
} = node
3538
const { bold, dim } = color ? chalk : nocolor
3639
const extra = []
@@ -46,6 +49,9 @@ const printNode = (node, color) => {
4649
if (peer)
4750
extra.push(' ' + bold(colorType('peer', color)))
4851

52+
if (bundled)
53+
extra.push(' ' + bold(colorType('bundled', color)))
54+
4955
return `${bold(name)}@${bold(version)}${extra.join('')}` +
5056
(location ? dim(`\n${location}`) : '')
5157
}

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

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ manydep@1.0.0
2121
6 more (optdep, extra-neos, deep-dev, peer, the root project, a package with a pretty long name)
2222
`
2323

24+
exports[`test/lib/utils/explain-dep.js TAP bundled > explain color deep 1`] = `
25+
bundle-of-joy@1.0.0 bundled
26+
node_modules/bundle-of-joy
27+
prod-dep@"1.x" from the root project
28+
`
29+
30+
exports[`test/lib/utils/explain-dep.js TAP bundled > explain nocolor shallow 1`] = `
31+
bundle-of-joy@1.0.0 bundled
32+
node_modules/bundle-of-joy
33+
prod-dep@"1.x" from the root project
34+
`
35+
36+
exports[`test/lib/utils/explain-dep.js TAP bundled > print color 1`] = `
37+
bundle-of-joy@1.0.0 bundled
38+
node_modules/bundle-of-joy
39+
`
40+
41+
exports[`test/lib/utils/explain-dep.js TAP bundled > print nocolor 1`] = `
42+
bundle-of-joy@1.0.0 bundled
43+
node_modules/bundle-of-joy
44+
`
45+
2446
exports[`test/lib/utils/explain-dep.js TAP deepDev > explain color deep 1`] = `
2547
deep-dev@2.3.4 dev
2648
node_modules/deep-dev

test/lib/utils/explain-dep.js

+17
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ const cases = {
9797
],
9898
},
9999

100+
bundled: {
101+
name: 'bundle-of-joy',
102+
version: '1.0.0',
103+
location: 'node_modules/bundle-of-joy',
104+
bundled: true,
105+
dependents: [
106+
{
107+
type: 'prod',
108+
name: 'prod-dep',
109+
spec: '1.x',
110+
from: {
111+
location: '/path/to/project',
112+
},
113+
},
114+
],
115+
},
116+
100117
extraneous: {
101118
name: 'extra-neos',
102119
version: '1337.420.69-lol',

0 commit comments

Comments
 (0)