@@ -143,8 +143,9 @@ const reporter = (analysis, opts) => {
143143} ;
144144
145145const analyzer = ( bundle , opts = { } ) => {
146- let { root, limit, filter } = opts ;
146+ let { root, limit, filter, transformModuleId } = opts ;
147147 root = root || ( process && process . cwd ? process . cwd ( ) : null ) ;
148+ if ( typeof transformModuleId !== 'function' ) transformModuleId = undefined ;
148149 let deps = { } ;
149150 let bundleSize = 0 ;
150151 let bundleOrigSize = 0 ;
@@ -161,6 +162,7 @@ const analyzer = (bundle, opts = {}) => {
161162 unusedExports
162163 } = m ;
163164 id = id . replace ( root , '' ) ;
165+ if ( transformModuleId ) id = transformModuleId ( id ) ;
164166 let size = renderedLength ;
165167 if ( ! size && size !== 0 ) size = code ? Buffer . byteLength ( code , 'utf8' ) : 0 ;
166168 bundleSize += size ;
@@ -171,11 +173,12 @@ const analyzer = (bundle, opts = {}) => {
171173
172174 m . dependencies . forEach ( ( d ) => {
173175 d = d . replace ( root , '' ) ;
176+ if ( transformModuleId ) d = transformModuleId ( d ) ;
174177 deps [ d ] = deps [ d ] || [ ] ;
175178 deps [ d ] . push ( id ) ;
176179 } ) ;
177180
178- return { id, size, origSize, usedExports, unusedExports}
181+ return { id, size, origSize, usedExports, unusedExports }
179182 } ) . filter ( ( m ) => m ) ;
180183
181184 modules . sort ( ( a , b ) => b . size - a . size ) ;
@@ -189,7 +192,7 @@ const analyzer = (bundle, opts = {}) => {
189192
190193 let bundleReduction = shakenPct ( bundleSize , bundleOrigSize ) ;
191194
192- return { bundleSize, bundleOrigSize, bundleReduction, modules, moduleCount}
195+ return { bundleSize, bundleOrigSize, bundleReduction, modules, moduleCount }
193196} ;
194197
195198const analyze = ( bundle , opts ) => new Promise ( ( resolve , reject ) => {
@@ -212,7 +215,9 @@ const plugin = (opts = {}) => {
212215
213216 let onAnalysis = ( analysis ) => {
214217 if ( typeof opts . onAnalysis === 'function' ) opts . onAnalysis ( analysis ) ;
215- if ( typeof opts . htmlReportPath === 'string' ) writeHtmlReport ( analysis . modules , opts . htmlReportPath ) ;
218+ if ( typeof opts . htmlReportPath === 'string' ) {
219+ writeHtmlReport ( analysis . modules , opts . htmlReportPath ) ;
220+ }
216221 if ( ! opts . skipFormatted ) writeTo ( reporter ( analysis , opts ) ) ;
217222 } ;
218223
@@ -222,7 +227,7 @@ const plugin = (opts = {}) => {
222227 let modules = bundle . modules ;
223228
224229 if ( Array . isArray ( modules ) ) {
225- return analyze ( { modules} , opts ) . then ( onAnalysis ) . catch ( console . error )
230+ return analyze ( { modules } , opts ) . then ( onAnalysis ) . catch ( console . error )
226231 }
227232
228233 modules = Object . keys ( modules ) . map ( ( k ) => {
@@ -231,16 +236,16 @@ const plugin = (opts = {}) => {
231236 module . unusedExports = module . removedExports ;
232237 return module
233238 } ) ;
234- return analyze ( { modules} , opts ) . then ( onAnalysis ) . catch ( console . error )
239+ return analyze ( { modules } , opts ) . then ( onAnalysis ) . catch ( console . error )
235240 } ) ;
236241
237242 return {
238243 name : 'rollup-plugin-analyzer' ,
239244 transformChunk : ( _a , _b , chunk ) => new Promise ( ( resolve , reject ) => {
240245 resolve ( null ) ;
241246 if ( ! chunk || ! chunk . orderedModules ) return
242- chunk . orderedModules . forEach ( ( { id, dependencies} ) => {
243- depMap [ id ] = { id, dependencies : dependencies . map ( ( d ) => d . id ) } ;
247+ chunk . orderedModules . forEach ( ( { id, dependencies } ) => {
248+ depMap [ id ] = { id, dependencies : dependencies . map ( ( d ) => d . id ) } ;
244249 } ) ;
245250 } ) ,
246251 generateBundle : runAnalysis ,
0 commit comments