@mui/internal-bundle-size-checker 1.0.9-canary.11 → 1.0.9-canary.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/viteBuilder.js +25 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-bundle-size-checker",
3
- "version": "1.0.9-canary.11",
3
+ "version": "1.0.9-canary.12",
4
4
  "description": "Bundle size checker for MUI packages.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -51,7 +51,7 @@
51
51
  "@types/webpack-bundle-analyzer": "^4.7.0",
52
52
  "@types/yargs": "^17.0.33"
53
53
  },
54
- "gitSha": "ad63edcb005175f8a6087a828e52648c7b4f1635",
54
+ "gitSha": "1d64cc06f2a0e0c7120343aacb1effa270adc2ae",
55
55
  "scripts": {
56
56
  "typescript": "tsc -p tsconfig.json",
57
57
  "test": "pnpm -w test --project @mui/internal-bundle-size-checker"
@@ -173,14 +173,24 @@ function walkDependencyTree(chunkKey, manifest, visited = new Set()) {
173
173
 
174
174
  /**
175
175
  * Process vite output to extract bundle sizes
176
- * @param {string} outDir - The output directory
176
+ * @param {import('vite').Rollup.RollupOutput['output']} output - The Vite output
177
177
  * @param {string} entryName - The entry name
178
178
  * @returns {Promise<Map<string, { parsed: number, gzip: number }>>} - Map of bundle names to size information
179
179
  */
180
- async function processBundleSizes(outDir, entryName) {
180
+ async function processBundleSizes(output, entryName) {
181
+ const chunksByFileName = new Map(output.map((chunk) => [chunk.fileName, chunk]));
182
+
181
183
  // Read the manifest file to find the generated chunks
182
- const manifestPath = path.join(outDir, '.vite/manifest.json');
183
- const manifestContent = await fs.readFile(manifestPath, 'utf8');
184
+ const manifestChunk = chunksByFileName.get('.vite/manifest.json');
185
+ if (manifestChunk?.type !== 'asset') {
186
+ throw new Error(`Manifest file not found in output for entry: ${entryName}`);
187
+ }
188
+
189
+ const manifestContent =
190
+ typeof manifestChunk.source === 'string'
191
+ ? manifestChunk.source
192
+ : new TextDecoder().decode(manifestChunk.source);
193
+
184
194
  /** @type {Manifest} */
185
195
  const manifest = JSON.parse(manifestContent);
186
196
 
@@ -197,8 +207,11 @@ async function processBundleSizes(outDir, entryName) {
197
207
  // Process each chunk in the dependency tree in parallel
198
208
  const chunkPromises = Array.from(allChunks, async (chunkKey) => {
199
209
  const chunk = manifest[chunkKey];
200
- const filePath = path.join(outDir, chunk.file);
201
- const fileContent = await fs.readFile(filePath, 'utf8');
210
+ const outputChunk = chunksByFileName.get(chunk.file);
211
+ if (outputChunk?.type !== 'chunk') {
212
+ throw new Error(`Output chunk not found for ${chunk.file}`);
213
+ }
214
+ const fileContent = outputChunk.code;
202
215
 
203
216
  // Calculate sizes
204
217
  const parsed = Buffer.byteLength(fileContent);
@@ -223,11 +236,14 @@ async function processBundleSizes(outDir, entryName) {
223
236
  export async function getViteSizes(entry, args) {
224
237
  // Create vite configuration
225
238
  const { configuration } = await createViteConfig(entry, args);
226
- const outDir = path.join(rootDir, 'build', entry.id);
227
239
 
228
240
  // Run vite build
229
- await build(configuration);
241
+ const { output } = /** @type {import('vite').Rollup.RollupOutput} */ (await build(configuration));
242
+ const manifestChunk = output.find((chunk) => chunk.fileName === '.vite/manifest.json');
243
+ if (!manifestChunk) {
244
+ throw new Error(`Manifest file not found in output for entry: ${entry.id}`);
245
+ }
230
246
 
231
247
  // Process the output to get bundle sizes
232
- return processBundleSizes(outDir, entry.id);
248
+ return processBundleSizes(output, entry.id);
233
249
  }