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

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.
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.13",
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": "f17b92d918a4979325ae9ee8259bb35dd83ca510",
55
55
  "scripts": {
56
56
  "typescript": "tsc -p tsconfig.json",
57
57
  "test": "pnpm -w test --project @mui/internal-bundle-size-checker"
@@ -97,11 +97,13 @@ function formatMarkdownTable(columns, data) {
97
97
  const separators = alignments.map((align) => {
98
98
  switch (align) {
99
99
  case 'center':
100
- return ':----------:';
100
+ return ':---------:';
101
101
  case 'right':
102
102
  return '----------:';
103
+ case 'left':
104
+ return ':----------';
103
105
  default:
104
- return '----------';
106
+ return '-----------';
105
107
  }
106
108
  });
107
109
  table += `|${separators.join('|')}|\n`;
@@ -141,9 +143,9 @@ export function renderMarkdownReportContent(
141
143
 
142
144
  markdownContent += formatMarkdownTable(
143
145
  [
144
- { field: 'id', header: 'Bundle' },
145
- { field: 'parsed', header: 'Parsed Size', align: 'right' },
146
- { field: 'gzip', header: 'Gzip Size', align: 'right' },
146
+ { field: 'id', header: 'Bundle', align: 'left' },
147
+ { field: 'parsed', header: 'Parsed size', align: 'right' },
148
+ { field: 'gzip', header: 'Gzip size', align: 'right' },
147
149
  ],
148
150
  trackedEntries.map(({ id, parsed, gzip }) => ({
149
151
  id,
@@ -353,8 +353,8 @@ describe('renderMarkdownReport', () => {
353
353
  });
354
354
 
355
355
  expect(result).toMatchInlineSnapshot(`
356
- "| Bundle | Parsed Size | Gzip Size |
357
- |----------|----------:|----------:|
356
+ "| Bundle | Parsed size | Gzip size |
357
+ |:----------|----------:|----------:|
358
358
  | @mui/material/Button/index.js | 🔺+400B<sup>(+2.67%)</sup> | 🔺+100B<sup>(+2.22%)</sup> |
359
359
  | @mui/material/TextField/index.js | 🔺+200B<sup>(+0.91%)</sup> | 🔺+100B<sup>(+1.54%)</sup> |
360
360
 
@@ -388,8 +388,8 @@ describe('renderMarkdownReport', () => {
388
388
  });
389
389
 
390
390
  expect(result).toMatchInlineSnapshot(`
391
- "| Bundle | Parsed Size | Gzip Size |
392
- |----------|----------:|----------:|
391
+ "| Bundle | Parsed size | Gzip size |
392
+ |:----------|----------:|----------:|
393
393
  | @mui/material/Button/index.js | 🔺+500B<sup>(+3.33%)</sup> | 🔺+150B<sup>(+3.33%)</sup> |
394
394
  | @mui/material/TextField/index.js | 🔺+300B<sup>(+1.36%)</sup> | 🔺+150B<sup>(+2.31%)</sup> |
395
395
 
@@ -423,8 +423,8 @@ describe('renderMarkdownReport', () => {
423
423
  });
424
424
 
425
425
  expect(result).toMatchInlineSnapshot(`
426
- "| Bundle | Parsed Size | Gzip Size |
427
- |----------|----------:|----------:|
426
+ "| Bundle | Parsed size | Gzip size |
427
+ |:----------|----------:|----------:|
428
428
  | @mui/material/Button/index.js | 🔺+400B<sup>(+2.67%)</sup> | 🔺+100B<sup>(+2.22%)</sup> |
429
429
 
430
430
 
@@ -457,8 +457,8 @@ describe('renderMarkdownReport', () => {
457
457
  });
458
458
 
459
459
  expect(result).toMatchInlineSnapshot(`
460
- "| Bundle | Parsed Size | Gzip Size |
461
- |----------|----------:|----------:|
460
+ "| Bundle | Parsed size | Gzip size |
461
+ |:----------|----------:|----------:|
462
462
  | @mui/material/Button/index.js | 0B<sup>(0.00%)</sup> | 0B<sup>(0.00%)</sup> |
463
463
  | @mui/material/TextField/index.js | 0B<sup>(0.00%)</sup> | 0B<sup>(0.00%)</sup> |
464
464
 
@@ -490,8 +490,8 @@ describe('renderMarkdownReport', () => {
490
490
  });
491
491
 
492
492
  expect(result).toMatchInlineSnapshot(`
493
- "| Bundle | Parsed Size | Gzip Size |
494
- |----------|----------:|----------:|
493
+ "| Bundle | Parsed size | Gzip size |
494
+ |:----------|----------:|----------:|
495
495
  | @mui/material/Button/index.js | 🔺+400B<sup>(+2.67%)</sup> | 🔺+100B<sup>(+2.22%)</sup> |
496
496
 
497
497
 
@@ -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
  }