@@ -127,7 +127,10 @@ class BundleAnalyzerPlugin {
127127
128128 if ( this . opts . generateStatsFile ) {
129129 actions . push ( ( ) =>
130- this . generateStatsFile ( stats . toJson ( this . opts . statsOptions ) ) ,
130+ this . generateStatsFile (
131+ stats . toJson ( this . opts . statsOptions ) ,
132+ compiler ,
133+ ) ,
131134 ) ;
132135 }
133136
@@ -138,15 +141,21 @@ class BundleAnalyzerPlugin {
138141
139142 if ( this . opts . analyzerMode === "server" ) {
140143 actions . push ( ( ) =>
141- this . startAnalyzerServer ( stats . toJson ( analyzerStatsOptions ) ) ,
144+ this . startAnalyzerServer (
145+ stats . toJson ( analyzerStatsOptions ) ,
146+ compiler ,
147+ ) ,
142148 ) ;
143149 } else if ( this . opts . analyzerMode === "static" ) {
144150 actions . push ( ( ) =>
145- this . generateStaticReport ( stats . toJson ( analyzerStatsOptions ) ) ,
151+ this . generateStaticReport (
152+ stats . toJson ( analyzerStatsOptions ) ,
153+ compiler ,
154+ ) ,
146155 ) ;
147156 } else if ( this . opts . analyzerMode === "json" ) {
148157 actions . push ( ( ) =>
149- this . generateJSONReport ( stats . toJson ( analyzerStatsOptions ) ) ,
158+ this . generateJSONReport ( stats . toJson ( analyzerStatsOptions ) , compiler ) ,
150159 ) ;
151160 }
152161
@@ -175,12 +184,12 @@ class BundleAnalyzerPlugin {
175184
176185 /**
177186 * @param {StatsCompilation } stats stats
187+ * @param {Compiler } compiler compiler
178188 * @returns {Promise<void> }
179189 */
180- async generateStatsFile ( stats ) {
190+ async generateStatsFile ( stats , compiler ) {
181191 const statsFilepath = path . resolve (
182- /** @type {Compiler } */
183- ( this . compiler ) . outputPath ,
192+ compiler . outputPath ,
184193 this . opts . statsFilename ,
185194 ) ;
186195 await fs . promises . mkdir ( path . dirname ( statsFilepath ) , { recursive : true } ) ;
@@ -200,19 +209,23 @@ class BundleAnalyzerPlugin {
200209
201210 /**
202211 * @param {StatsCompilation } stats stats
212+ * @param {Compiler } compiler compiler
203213 * @returns {Promise<void> }
204214 */
205- async startAnalyzerServer ( stats ) {
215+ async startAnalyzerServer ( stats , compiler ) {
206216 if ( this . server ) {
207- ( await this . server ) . updateChartData ( stats ) ;
217+ ( await this . server ) . updateChartData (
218+ stats ,
219+ this . getBundleDirFromCompiler ( compiler ) ,
220+ ) ;
208221 } else {
209222 this . server = viewer . startServer ( stats , {
210223 openBrowser : this . opts . openAnalyzer ,
211224 host : this . opts . analyzerHost ,
212225 port : this . opts . analyzerPort ,
213226 reportTitle : this . opts . reportTitle ,
214227 compressionAlgorithm : this . opts . compressionAlgorithm ,
215- bundleDir : this . getBundleDirFromCompiler ( ) ,
228+ bundleDir : this . getBundleDirFromCompiler ( compiler ) ,
216229 logger : this . logger ,
217230 defaultSizes : this . opts . defaultSizes ,
218231 excludeAssets : this . opts . excludeAssets ,
@@ -223,50 +236,54 @@ class BundleAnalyzerPlugin {
223236
224237 /**
225238 * @param {StatsCompilation } stats stats
239+ * @param {Compiler } compiler compiler
226240 * @returns {Promise<void> }
227241 */
228- async generateJSONReport ( stats ) {
242+ async generateJSONReport ( stats , compiler ) {
229243 await viewer . generateJSONReport ( stats , {
230244 reportFilename : path . resolve (
231- /** @type {Compiler } */
232- ( this . compiler ) . outputPath ,
245+ compiler . outputPath ,
233246 this . opts . reportFilename || "report.json" ,
234247 ) ,
235248 compressionAlgorithm : this . opts . compressionAlgorithm ,
236- bundleDir : this . getBundleDirFromCompiler ( ) ,
249+ bundleDir : this . getBundleDirFromCompiler ( compiler ) ,
237250 logger : this . logger ,
238251 excludeAssets : this . opts . excludeAssets ,
239252 } ) ;
240253 }
241254
242255 /**
243256 * @param {StatsCompilation } stats stats
257+ * @param {Compiler } compiler compiler
244258 * @returns {Promise<void> }
245259 */
246- async generateStaticReport ( stats ) {
260+ async generateStaticReport ( stats , compiler ) {
247261 await viewer . generateReport ( stats , {
248262 openBrowser : this . opts . openAnalyzer ,
249263 reportFilename : path . resolve (
250- /** @type {Compiler } */
251- ( this . compiler ) . outputPath ,
264+ compiler . outputPath ,
252265 this . opts . reportFilename || "report.html" ,
253266 ) ,
254267 reportTitle : this . opts . reportTitle ,
255268 compressionAlgorithm : this . opts . compressionAlgorithm ,
256- bundleDir : this . getBundleDirFromCompiler ( ) ,
269+ bundleDir : this . getBundleDirFromCompiler ( compiler ) ,
257270 logger : this . logger ,
258271 defaultSizes : this . opts . defaultSizes ,
259272 excludeAssets : this . opts . excludeAssets ,
260273 } ) ;
261274 }
262275
263- getBundleDirFromCompiler ( ) {
276+ /**
277+ * @param {Compiler } compiler compiler
278+ * @returns {string | null } bundle directory
279+ */
280+ getBundleDirFromCompiler ( compiler ) {
264281 const outputFileSystemConstructor =
265282 /** @type {OutputFileSystem } */
266- ( /** @type { Compiler } */ ( this . compiler ) . outputFileSystem ) . constructor ;
283+ ( compiler . outputFileSystem ) . constructor ;
267284
268285 if ( typeof outputFileSystemConstructor === "undefined" ) {
269- return /** @type { Compiler } */ ( this . compiler ) . outputPath ;
286+ return compiler . outputPath ;
270287 }
271288 switch ( outputFileSystemConstructor . name ) {
272289 case "MemoryFileSystem" :
@@ -276,7 +293,7 @@ class BundleAnalyzerPlugin {
276293 case "AsyncMFS" :
277294 return null ;
278295 default :
279- return /** @type { Compiler } */ ( this . compiler ) . outputPath ;
296+ return compiler . outputPath ;
280297 }
281298 }
282299}
0 commit comments