MCPcopy Create free account
hub / github.com/vercel/vercel / outputFunctionFileSizeInfo

Function outputFunctionFileSizeInfo

packages/next/src/utils.ts:2246–2333  ·  view source on GitHub ↗
(
  pages: string[],
  pseudoLayer: PseudoLayer,
  pseudoLayerUncompressedBytes: number,
  compressedPages: {
    [page: string]: PseudoFile;
  }
)

Source from the content-addressed store, hash-verified

2244}
2245
2246export const outputFunctionFileSizeInfo = (
2247 pages: string[],
2248 pseudoLayer: PseudoLayer,
2249 pseudoLayerUncompressedBytes: number,
2250 compressedPages: {
2251 [page: string]: PseudoFile;
2252 }
2253) => {
2254 const exceededLimitOutput: Array<string[]> = [];
2255
2256 console.log(
2257 `Serverless Function's page${pages.length === 1 ? '' : 's'}: ${pages.join(
2258 ', '
2259 )}`
2260 );
2261 exceededLimitOutput.push(['Large Dependencies', 'Uncompressed size']);
2262
2263 const dependencies: {
2264 [key: string]: {
2265 uncompressed: number;
2266 };
2267 } = {};
2268
2269 for (const fileKey of Object.keys(pseudoLayer)) {
2270 if (!pseudoLayer[fileKey].isSymlink) {
2271 const fileItem = pseudoLayer[fileKey] as PseudoFile;
2272 const depKey = fileKey.split('/').slice(0, 3).join('/');
2273
2274 if (!dependencies[depKey]) {
2275 dependencies[depKey] = {
2276 uncompressed: 0,
2277 };
2278 }
2279
2280 dependencies[depKey].uncompressed += fileItem.uncompressedSize;
2281 }
2282 }
2283
2284 for (const page of pages) {
2285 dependencies[`pages/${page}`] = {
2286 uncompressed: compressedPages[page].uncompressedSize,
2287 };
2288 }
2289 let numLargeDependencies = 0;
2290
2291 Object.keys(dependencies)
2292 .sort((a, b) => {
2293 // move largest dependencies to the top
2294 const aDep = dependencies[a];
2295 const bDep = dependencies[b];
2296
2297 if (aDep.uncompressed > bDep.uncompressed) {
2298 return -1;
2299 }
2300 if (aDep.uncompressed < bDep.uncompressed) {
2301 return 1;
2302 }
2303 return 0;

Callers 2

serverBuildFunction · 0.90

Calls 7

prettyBytesFunction · 0.90
splitMethod · 0.80
sortMethod · 0.80
pushMethod · 0.65
logMethod · 0.45
joinMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected