@@ -21,6 +21,7 @@ const { open } = require("./utils");
2121/** @typedef {import("./BundleAnalyzerPlugin").ExcludeAssets } ExcludeAssets */
2222/** @typedef {import("./analyzer").ViewerDataOptions } ViewerDataOptions */
2323/** @typedef {import("./analyzer").ChartData } ChartData */
24+ /** @typedef {{ readFileSync: (path: string, encoding: string) => string } } BundleDirFs */
2425
2526const projectRoot = path . resolve ( __dirname , ".." ) ;
2627
@@ -107,6 +108,7 @@ function getChartData(analyzerOpts, bundleStats, bundleDir) {
107108 * @property {string } host host
108109 * @property {boolean } openBrowser true when need to open browser, otherwise false
109110 * @property {string | null } bundleDir bundle dir
111+ * @property {BundleDirFs | null } bundleDirFs filesystem for reading bundle files
110112 * @property {Logger } logger logger
111113 * @property {Sizes } defaultSizes default sizes
112114 * @property {CompressionAlgorithm } compressionAlgorithm compression algorithm
@@ -128,6 +130,7 @@ async function startServer(bundleStats, opts) {
128130 host = "127.0.0.1" ,
129131 openBrowser = true ,
130132 bundleDir = null ,
133+ bundleDirFs = null ,
131134 logger = new Logger ( ) ,
132135 defaultSizes = "parsed" ,
133136 compressionAlgorithm,
@@ -136,7 +139,12 @@ async function startServer(bundleStats, opts) {
136139 analyzerUrl,
137140 } = opts || { } ;
138141
139- const analyzerOpts = { logger, excludeAssets, compressionAlgorithm } ;
142+ const analyzerOpts = {
143+ logger,
144+ excludeAssets,
145+ compressionAlgorithm,
146+ bundleDirFs,
147+ } ;
140148
141149 let chartData = getChartData ( analyzerOpts , bundleStats , bundleDir ) ;
142150
@@ -240,6 +248,7 @@ async function startServer(bundleStats, opts) {
240248 * @property {string } reportFilename report filename
241249 * @property {ReportTitle } reportTitle report title
242250 * @property {string | null } bundleDir bundle dir
251+ * @property {BundleDirFs | null } bundleDirFs filesystem for reading bundle files
243252 * @property {Logger } logger logger
244253 * @property {Sizes } defaultSizes default sizes
245254 * @property {CompressionAlgorithm } compressionAlgorithm compression algorithm
@@ -257,14 +266,15 @@ async function generateReport(bundleStats, opts) {
257266 reportFilename,
258267 reportTitle,
259268 bundleDir = null ,
269+ bundleDirFs = null ,
260270 logger = new Logger ( ) ,
261271 defaultSizes = "parsed" ,
262272 compressionAlgorithm,
263273 excludeAssets = null ,
264274 } = opts || { } ;
265275
266276 const chartData = getChartData (
267- { logger, excludeAssets, compressionAlgorithm } ,
277+ { logger, excludeAssets, compressionAlgorithm, bundleDirFs } ,
268278 bundleStats ,
269279 bundleDir ,
270280 ) ;
@@ -302,6 +312,7 @@ async function generateReport(bundleStats, opts) {
302312 * @typedef {object } GenerateJSONReportOptions
303313 * @property {string } reportFilename report filename
304314 * @property {string | null } bundleDir bundle dir
315+ * @property {BundleDirFs | null } bundleDirFs filesystem for reading bundle files
305316 * @property {Logger } logger logger
306317 * @property {ExcludeAssets } excludeAssets exclude assets
307318 * @property {CompressionAlgorithm } compressionAlgorithm compression algorithm
@@ -316,13 +327,14 @@ async function generateJSONReport(bundleStats, opts) {
316327 const {
317328 reportFilename,
318329 bundleDir = null ,
330+ bundleDirFs = null ,
319331 logger = new Logger ( ) ,
320332 excludeAssets = null ,
321333 compressionAlgorithm,
322334 } = opts || { } ;
323335
324336 const chartData = getChartData (
325- { logger, excludeAssets, compressionAlgorithm } ,
337+ { logger, excludeAssets, compressionAlgorithm, bundleDirFs } ,
326338 bundleStats ,
327339 bundleDir ,
328340 ) ;
0 commit comments