@mui/internal-bundle-size-checker 1.0.9-canary.10 → 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.
- package/package.json +4 -3
- package/src/github.js +5 -1
- 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.
|
|
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",
|
|
@@ -22,9 +22,10 @@
|
|
|
22
22
|
"@aws-sdk/client-s3": "^3.515.0",
|
|
23
23
|
"@aws-sdk/credential-providers": "^3.787.0",
|
|
24
24
|
"@babel/core": "^7.27.4",
|
|
25
|
-
"@octokit/rest": "^22.0.0",
|
|
26
25
|
"@babel/preset-react": "^7.18.6",
|
|
27
26
|
"@babel/preset-typescript": "^7.27.1",
|
|
27
|
+
"@octokit/auth-action": "^6.0.1",
|
|
28
|
+
"@octokit/rest": "^22.0.0",
|
|
28
29
|
"babel-loader": "^10.0.0",
|
|
29
30
|
"chalk": "^5.4.1",
|
|
30
31
|
"compression-webpack-plugin": "^10.0.0",
|
|
@@ -50,7 +51,7 @@
|
|
|
50
51
|
"@types/webpack-bundle-analyzer": "^4.7.0",
|
|
51
52
|
"@types/yargs": "^17.0.33"
|
|
52
53
|
},
|
|
53
|
-
"gitSha": "
|
|
54
|
+
"gitSha": "1d64cc06f2a0e0c7120343aacb1effa270adc2ae",
|
|
54
55
|
"scripts": {
|
|
55
56
|
"typescript": "tsc -p tsconfig.json",
|
|
56
57
|
"test": "pnpm -w test --project @mui/internal-bundle-size-checker"
|
package/src/github.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
import { Octokit } from '@octokit/rest';
|
|
4
|
+
import { createActionAuth } from '@octokit/auth-action';
|
|
4
5
|
|
|
5
6
|
// Create and export Octokit instance
|
|
6
7
|
/** @type {import('@octokit/rest').Octokit} */
|
|
7
|
-
export const octokit = new Octokit(
|
|
8
|
+
export const octokit = new Octokit({
|
|
9
|
+
authStrategy: process.env.GITHUB_TOKEN ? createActionAuth : undefined,
|
|
10
|
+
userAgent: 'bundle-size-checker',
|
|
11
|
+
});
|
package/src/viteBuilder.js
CHANGED
|
@@ -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 {
|
|
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(
|
|
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
|
|
183
|
-
|
|
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
|
|
201
|
-
|
|
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(
|
|
248
|
+
return processBundleSizes(output, entry.id);
|
|
233
249
|
}
|