Skip to content

Commit 0eec360

Browse files
committed
docs: update readme
1 parent b967c12 commit 0eec360

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Answer to "Why that package is in the bundle"
99

1010
<img src="media/screenshot.jpg" alt="screenshot" width="450" />
1111

12+
Show the whole `issuer chain` and tell you why that package is in your bundle
13+
1214
## Installation
1315

1416
```bash

lib/analyze.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ module.exports = function analyze( stats = {} ) {
7777
const packageName = getPkgName( mod.name )
7878
const relativePathInPackage = getRelativePathInPackage( mod.name )
7979
const issuerPackageName = getPkgName( mod.issuerName )
80+
const issuerPath = ( mod.issuerPath || [] )
81+
.map( path => normalizePath( path.name ) )
82+
.filter( ( name, i, issuers ) => {
83+
const nextName = issuers[ i + 1 ]
84+
if ( name === nextName ) {
85+
return false
86+
}
87+
88+
return true
89+
} )
90+
issuerPath.reverse()
8091

8192
return {
8293
name: mod.name,
@@ -89,7 +100,7 @@ module.exports = function analyze( stats = {} ) {
89100
isSelfIssued: packageName && ( packageName === issuerPackageName ),
90101
issuer: mod.issuer,
91102
issuerName: normalizePath( mod.issuerName ),
92-
issuerPath: mod.issuerPath,
103+
issuerPath,
93104
}
94105
} )
95106
}

lib/format.js

+25-20
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,13 @@ module.exports = function format( assets ) {
2525
out = out + ` ${ chalk.blue( pkg.name ) } ${ chalk.dim( 'is issued by' ) }\n`
2626

2727
if ( pkg.externalIssuers.length > 0 ) {
28-
pkg.externalIssuers.sort( ( a, b ) => {
29-
if ( containsNodeModules( a.name ) && !containsNodeModules( b.name ) ) {
30-
return 1
31-
}
32-
33-
if ( !containsNodeModules( a.name ) && containsNodeModules( b.name ) ) {
34-
return -1
35-
}
36-
37-
if ( containsAt( a.name ) && !containsAt( b.name ) ) {
38-
return -1
39-
}
40-
41-
if ( !containsAt( a.name ) && containsAt( b.name ) ) {
42-
return 1
43-
}
44-
45-
return a.name.replace( atReg, '' ).localeCompare( b.name.replace( atReg, '' ) )
46-
} )
28+
pkg.externalIssuers.sort( ( a, b ) => sortIssuer( a.name, b.name ) )
4729

4830
out = out + pkg.externalIssuers.map( issuer => {
49-
return `\n → ${ prettyPath( issuer.name ) }`
31+
return `\n → ` + prettyPath( issuer.trace[ 0 ] ) +
32+
issuer.trace.slice( 1 ).map( ( parentIssuer, i ) => {
33+
return '\n\n' + ' '.repeat( i * 2 + 5 ) + chalk.dim( ' ↳ ' ) + prettyPath( parentIssuer )
34+
} ).join( '' )
5035
} ).join( '\n' )
5136
} else {
5237
out = out + `\n → ${ chalk.bold( 'Self' ) } ${ chalk.dim( '( As Entrypoint )' ) }`
@@ -74,3 +59,23 @@ function containsNodeModules( path ) {
7459
function containsAt( path ) {
7560
return path.includes( '@' )
7661
}
62+
63+
function sortIssuer( aName, bName ) {
64+
if ( containsNodeModules( aName ) && !containsNodeModules( bName ) ) {
65+
return 1
66+
}
67+
68+
if ( !containsNodeModules( aName ) && containsNodeModules( bName ) ) {
69+
return -1
70+
}
71+
72+
if ( containsAt( aName ) && !containsAt( bName ) ) {
73+
return -1
74+
}
75+
76+
if ( !containsAt( aName ) && containsAt( bName ) ) {
77+
return 1
78+
}
79+
80+
return aName.replace( atReg, '' ).localeCompare( bName.replace( atReg, '' ) )
81+
}

lib/shared.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function prettyPath( path ) {
3131
if ( nodeModulesReg.test( path ) ) {
3232
const packageName = getPackageName( path )
3333
path = path.replace( nodeModulesReg, '' )
34-
path = chalk.bold( `${ packageName }` ) + path.slice( packageName.length )
34+
path = chalk.bold( `${ packageName }` ) + chalk.dim( path.slice( packageName.length ) )
3535
}
3636

3737
return path

media/screenshot.jpg

137 KB
Loading

0 commit comments

Comments
 (0)