@@ -6,6 +6,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
66const buf = ' ' ;
77const tab = ' ' ;
88const borderX = `${ Array ( 30 ) . join ( '-' ) } \n` ;
9+ let proc = process ;
10+ let root = proc && proc . cwd ? proc . cwd ( ) : null ;
911let limit ;
1012
1113// Helpers
@@ -22,6 +24,7 @@ const formatBytes = (bytes) => {
2224function init ( opts ) {
2325 opts = opts || { } ;
2426 limit = opts . limit ;
27+ root = opts . root || root ;
2528}
2629
2730function formatted ( bndl ) { return analyze ( bndl , true ) }
@@ -30,9 +33,9 @@ function analyze (bundle, format) {
3033 let deps = { } ;
3134 return new Promise ( ( resolve , reject ) => {
3235 let modules = bundle . modules . map ( ( m , i ) => {
33- let id = m . id . replace ( __dirname , '' ) ;
36+ let id = m . id . replace ( root , '' ) ;
3437 m . dependencies . forEach ( ( d ) => {
35- d = d . replace ( __dirname , '' ) ;
38+ d = d . replace ( root , '' ) ;
3639 deps [ d ] = deps [ d ] || [ ] ;
3740 deps [ d ] . push ( id ) ;
3841 } ) ;
@@ -49,7 +52,7 @@ function analyze (bundle, format) {
4952 formatted += `size:${ buf } ${ formatBytes ( m . size ) } \n` ;
5053 formatted += `dependents:${ buf } ${ m . dependents . length } \n` ;
5154 m . dependents . forEach ( ( d ) => {
52- formatted += `${ tab } -${ buf } ${ d . replace ( __dirname , '' ) } \n` ;
55+ formatted += `${ tab } -${ buf } ${ d . replace ( root , '' ) } \n` ;
5356 } ) ;
5457 formatted += `${ borderX } ` ;
5558 } ) ;
0 commit comments