Duffer Derek
{"version":3,"sources":["../../src/build/route-bundle-stats.ts"],"sourcesContent":["import path from 'path'\nimport { promises as fs, statSync } from 'fs'\nimport {\n APP_PATHS_MANIFEST,\n CLIENT_REFERENCE_MANIFEST,\n SERVER_DIRECTORY,\n} from '../shared/lib/constants'\nimport type { BuildManifest } from '../server/get-page-files'\nimport { filterAndSortList } from './utils'\n\nconst ROUTE_BUNDLE_STATS_FILE = 'route-bundle-stats.json'\n\ntype RouteBundleStat = {\n route: string\n firstLoadUncompressedJsBytes: number\n firstLoadChunkPaths: string[]\n}\n\nfunction sumFileSizes(\n distDir: string,\n files: string[],\n cache: Map<string, number>\n): number {\n let total = 0\n for (const relPath of files) {\n const cached = cache.get(relPath)\n if (cached !== undefined) {\n total += cached\n continue\n }\n try {\n const size = statSync(path.join(distDir, relPath)).size\n cache.set(relPath, size)\n total += size\n } catch {\n // ignore missing files\n }\n }\n return total\n}\n\nfunction toProjectRelativePaths(\n dir: string,\n distDir: string,\n relPaths: string[]\n): string[] {\n return relPaths.map((f) => path.relative(dir, path.join(distDir, f)))\n}\n\nfunction buildRouteToAppPathsMap(\n appPathsManifest: Record<string, string>\n): Map<string, string[]> {\n const { normalizeAppPath } =\n require('../shared/lib/router/utils/app-paths') as typeof import('../shared/lib/router/utils/app-paths')\n // Keys in appPathsManifest are app paths like /blog/[slug]/page;\n // values are server bundle file paths. Normalize the key to get the route.\n const routeToAppPaths = new Map<string, string[]>()\n for (const appPath of Object.keys(appPathsManifest)) {\n const route = normalizeAppPath(appPath)\n const existing = routeToAppPaths.get(route)\n if (existing) {\n existing.push(appPath)\n } else {\n routeToAppPaths.set(route, [appPath])\n }\n }\n return routeToAppPaths\n}\n\n// Reads the manfiest file and gets the entry JS files. The manifest file is\n// a JavaScript file that sets a global variable (__RSC_MANIFEST). We require()\n// it with a save/restore of the global\nfunction readEntryJSFiles(\n distDir: string,\n pagePath: string,\n appRoute: string\n): Record<string, string[]> | undefined {\n const manifestFile = path.join(\n distDir,\n SERVER_DIRECTORY,\n 'app',\n `${pagePath}_${CLIENT_REFERENCE_MANIFEST}.js`\n )\n try {\n const g = global as Record<string, unknown>\n const prev = g.__RSC_MANIFEST\n g.__RSC_MANIFEST = undefined\n require(manifestFile)\n const rscManifest = g.__RSC_MANIFEST as\n | Record<string, { entryJSFiles?: Record<string, string[]> }>\n | undefined\n g.__RSC_MANIFEST = prev\n\n // The key in __RSC_MANIFEST is the app path (e.g. /blog/[slug]/page)\n const manifestEntry = rscManifest?.[pagePath] ?? rscManifest?.[appRoute]\n return manifestEntry?.entryJSFiles\n } catch {\n return undefined\n }\n}\n\nfunction collectPagesRouterStats(\n pages: ReadonlyArray<string>,\n buildManifest: BuildManifest,\n distDir: string,\n dir: string,\n cache: Map<string, number>\n): RouteBundleStat[] {\n const rows: RouteBundleStat[] = []\n const sharedFiles = buildManifest.pages['/_app'] ?? []\n for (const page of filterAndSortList(pages, 'pages', false)) {\n if (page === '/_app' || page === '/_document' || page === '/_error')\n // Don't report on layouts directly\n continue\n\n const allFiles = (buildManifest.pages[page] ?? []).filter((f) =>\n f.endsWith('.js')\n )\n const sharedJs = sharedFiles.filter((f) => f.endsWith('.js'))\n const chunks = [...new Set([...allFiles, ...sharedJs])]\n const firstLoadUncompressedJsBytes = sumFileSizes(distDir, chunks, cache)\n rows.push({\n route: page,\n firstLoadUncompressedJsBytes,\n firstLoadChunkPaths: toProjectRelativePaths(dir, distDir, chunks),\n })\n }\n return rows\n}\n\nasync function collectAppRouterStats(\n appRoutes: ReadonlyArray<string>,\n buildManifest: BuildManifest,\n distDir: string,\n dir: string,\n cache: Map<string, number>\n): Promise<RouteBundleStat[]> {\n let appPathsManifest: Record<string, string> = {}\n try {\n const manifestPath = path.join(\n distDir,\n SERVER_DIRECTORY,\n APP_PATHS_MANIFEST\n )\n appPathsManifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'))\n } catch {\n // App paths manifest not available; skip app router sizes\n return []\n }\n\n const routeToAppPaths = buildRouteToAppPathsMap(appPathsManifest)\n const sharedFiles = buildManifest.rootMainFiles ?? []\n const rows: RouteBundleStat[] = []\n\n for (const appRoute of filterAndSortList(appRoutes, 'app', false)) {\n const appPaths = routeToAppPaths.get(appRoute) ?? []\n // Find the /page entry (most specific, has the most chunks)\n const pagePath = appPaths.find((p) => p.endsWith('/page'))\n if (!pagePath) continue\n\n const entryJSFiles = readEntryJSFiles(distDir, pagePath, appRoute)\n if (!entryJSFiles) continue\n\n // Union JS files across all segments (page, layout, etc.) so that\n // layout code's contribution is included in the First Load JS total.\n const allFiles = [\n ...new Set(\n Object.values(entryJSFiles)\n .flat()\n .filter((f) => f.endsWith('.js'))\n ),\n ]\n const sharedJs = sharedFiles.filter((f) => f.endsWith('.js'))\n const chunks = [...new Set([...allFiles, ...sharedJs])]\n const firstLoadUncompressedJsBytes = sumFileSizes(distDir, chunks, cache)\n rows.push({\n route: appRoute,\n firstLoadUncompressedJsBytes,\n firstLoadChunkPaths: toProjectRelativePaths(dir, distDir, chunks),\n })\n }\n return rows\n}\n\nexport async function writeRouteBundleStats(\n lists: {\n pages: ReadonlyArray<string>\n app: ReadonlyArray<string> | undefined\n },\n buildManifest: BuildManifest,\n distDir: string,\n dir: string\n): Promise<void> {\n const cache = new Map<string, number>()\n\n const rows = [\n ...(lists.pages.length > 0\n ? collectPagesRouterStats(lists.pages, buildManifest, distDir, dir, cache)\n : []),\n ...(lists.app && lists.app.length > 0\n ? await collectAppRouterStats(\n lists.app,\n buildManifest,\n distDir,\n dir,\n cache\n )\n : []),\n ]\n\n rows.sort(\n (a, b) => b.firstLoadUncompressedJsBytes - a.firstLoadUncompressedJsBytes\n )\n\n const diagnosticsDir = path.join(distDir, 'diagnostics')\n await fs.mkdir(diagnosticsDir, { recursive: true })\n await fs.writeFile(\n path.join(diagnosticsDir, ROUTE_BUNDLE_STATS_FILE),\n JSON.stringify(rows, null, 2)\n )\n}\n"],"names":["writeRouteBundleStats","ROUTE_BUNDLE_STATS_FILE","sumFileSizes","distDir","files","cache","total","relPath","cached","get","undefined","size","statSync","path","join","set","toProjectRelativePaths","dir","relPaths","map","f","relative","buildRouteToAppPathsMap","appPathsManifest","normalizeAppPath","require","routeToAppPaths","Map","appPath","Object","keys","route","existing","push","readEntryJSFiles","pagePath","appRoute","manifestFile","SERVER_DIRECTORY","CLIENT_REFERENCE_MANIFEST","g","global","prev","__RSC_MANIFEST","rscManifest","manifestEntry","entryJSFiles","collectPagesRouterStats","pages","buildManifest","rows","sharedFiles","page","filterAndSortList","allFiles","filter","endsWith","sharedJs","chunks","Set","firstLoadUncompressedJsBytes","firstLoadChunkPaths","collectAppRouterStats","appRoutes","manifestPath","APP_PATHS_MANIFEST","JSON","parse","fs","readFile","rootMainFiles","appPaths","find","p","values","flat","lists","length","app","sort","a","b","diagnosticsDir","mkdir","recursive","writeFile","stringify"],"mappings":";;;;+BAwLsBA;;;eAAAA;;;6DAxLL;oBACwB;2BAKlC;uBAE2B;;;;;;AAElC,MAAMC,0BAA0B;AAQhC,SAASC,aACPC,OAAe,EACfC,KAAe,EACfC,KAA0B;IAE1B,IAAIC,QAAQ;IACZ,KAAK,MAAMC,WAAWH,MAAO;QAC3B,MAAMI,SAASH,MAAMI,GAAG,CAACF;QACzB,IAAIC,WAAWE,WAAW;YACxBJ,SAASE;YACT;QACF;QACA,IAAI;YACF,MAAMG,OAAOC,IAAAA,YAAQ,EAACC,aAAI,CAACC,IAAI,CAACX,SAASI,UAAUI,IAAI;YACvDN,MAAMU,GAAG,CAACR,SAASI;YACnBL,SAASK;QACX,EAAE,OAAM;QACN,uBAAuB;QACzB;IACF;IACA,OAAOL;AACT;AAEA,SAASU,uBACPC,GAAW,EACXd,OAAe,EACfe,QAAkB;IAElB,OAAOA,SAASC,GAAG,CAAC,CAACC,IAAMP,aAAI,CAACQ,QAAQ,CAACJ,KAAKJ,aAAI,CAACC,IAAI,CAACX,SAASiB;AACnE;AAEA,SAASE,wBACPC,gBAAwC;IAExC,MAAM,EAAEC,gBAAgB,EAAE,GACxBC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