@vercel/next 4.0.9 → 4.0.11

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/dist/index.js +626 -281
  2. package/package.json +5 -3
package/dist/index.js CHANGED
@@ -514,6 +514,9 @@ var require_superstatic = __commonJS({
514
514
  if (r.missing) {
515
515
  route.missing = r.missing;
516
516
  }
517
+ if (r.statusCode) {
518
+ route.status = r.statusCode;
519
+ }
517
520
  return route;
518
521
  } catch (e) {
519
522
  throw new Error(`Failed to parse rewrite: ${JSON.stringify(r)}`);
@@ -837,7 +840,7 @@ var require_lib = __commonJS({
837
840
  function defaultInit() {
838
841
  return "1";
839
842
  }
840
- var Sema3 = class {
843
+ var Sema4 = class {
841
844
  constructor(nr, { initFn = defaultInit, pauseFn, resumeFn, capacity = 10 } = {}) {
842
845
  if (isFn(pauseFn) !== isFn(resumeFn)) {
843
846
  throw new Error("pauseFn and resumeFn must be both set for pausing");
@@ -893,9 +896,9 @@ var require_lib = __commonJS({
893
896
  return this.waiting.length;
894
897
  }
895
898
  };
896
- exports.Sema = Sema3;
899
+ exports.Sema = Sema4;
897
900
  function RateLimit(rps, { timeUnit = 1e3, uniformDistribution = false } = {}) {
898
- const sema = new Sema3(uniformDistribution ? 1 : rps);
901
+ const sema = new Sema4(uniformDistribution ? 1 : rps);
899
902
  const delay = uniformDistribution ? timeUnit / rps : timeUnit;
900
903
  return async function rl() {
901
904
  await sema.acquire();
@@ -5870,6 +5873,313 @@ var require_semver = __commonJS({
5870
5873
  }
5871
5874
  });
5872
5875
 
5876
+ // ../../node_modules/.pnpm/buffer-crc32@0.2.13/node_modules/buffer-crc32/index.js
5877
+ var require_buffer_crc32 = __commonJS({
5878
+ "../../node_modules/.pnpm/buffer-crc32@0.2.13/node_modules/buffer-crc32/index.js"(exports, module2) {
5879
+ var Buffer2 = require("buffer").Buffer;
5880
+ var CRC_TABLE = [
5881
+ 0,
5882
+ 1996959894,
5883
+ 3993919788,
5884
+ 2567524794,
5885
+ 124634137,
5886
+ 1886057615,
5887
+ 3915621685,
5888
+ 2657392035,
5889
+ 249268274,
5890
+ 2044508324,
5891
+ 3772115230,
5892
+ 2547177864,
5893
+ 162941995,
5894
+ 2125561021,
5895
+ 3887607047,
5896
+ 2428444049,
5897
+ 498536548,
5898
+ 1789927666,
5899
+ 4089016648,
5900
+ 2227061214,
5901
+ 450548861,
5902
+ 1843258603,
5903
+ 4107580753,
5904
+ 2211677639,
5905
+ 325883990,
5906
+ 1684777152,
5907
+ 4251122042,
5908
+ 2321926636,
5909
+ 335633487,
5910
+ 1661365465,
5911
+ 4195302755,
5912
+ 2366115317,
5913
+ 997073096,
5914
+ 1281953886,
5915
+ 3579855332,
5916
+ 2724688242,
5917
+ 1006888145,
5918
+ 1258607687,
5919
+ 3524101629,
5920
+ 2768942443,
5921
+ 901097722,
5922
+ 1119000684,
5923
+ 3686517206,
5924
+ 2898065728,
5925
+ 853044451,
5926
+ 1172266101,
5927
+ 3705015759,
5928
+ 2882616665,
5929
+ 651767980,
5930
+ 1373503546,
5931
+ 3369554304,
5932
+ 3218104598,
5933
+ 565507253,
5934
+ 1454621731,
5935
+ 3485111705,
5936
+ 3099436303,
5937
+ 671266974,
5938
+ 1594198024,
5939
+ 3322730930,
5940
+ 2970347812,
5941
+ 795835527,
5942
+ 1483230225,
5943
+ 3244367275,
5944
+ 3060149565,
5945
+ 1994146192,
5946
+ 31158534,
5947
+ 2563907772,
5948
+ 4023717930,
5949
+ 1907459465,
5950
+ 112637215,
5951
+ 2680153253,
5952
+ 3904427059,
5953
+ 2013776290,
5954
+ 251722036,
5955
+ 2517215374,
5956
+ 3775830040,
5957
+ 2137656763,
5958
+ 141376813,
5959
+ 2439277719,
5960
+ 3865271297,
5961
+ 1802195444,
5962
+ 476864866,
5963
+ 2238001368,
5964
+ 4066508878,
5965
+ 1812370925,
5966
+ 453092731,
5967
+ 2181625025,
5968
+ 4111451223,
5969
+ 1706088902,
5970
+ 314042704,
5971
+ 2344532202,
5972
+ 4240017532,
5973
+ 1658658271,
5974
+ 366619977,
5975
+ 2362670323,
5976
+ 4224994405,
5977
+ 1303535960,
5978
+ 984961486,
5979
+ 2747007092,
5980
+ 3569037538,
5981
+ 1256170817,
5982
+ 1037604311,
5983
+ 2765210733,
5984
+ 3554079995,
5985
+ 1131014506,
5986
+ 879679996,
5987
+ 2909243462,
5988
+ 3663771856,
5989
+ 1141124467,
5990
+ 855842277,
5991
+ 2852801631,
5992
+ 3708648649,
5993
+ 1342533948,
5994
+ 654459306,
5995
+ 3188396048,
5996
+ 3373015174,
5997
+ 1466479909,
5998
+ 544179635,
5999
+ 3110523913,
6000
+ 3462522015,
6001
+ 1591671054,
6002
+ 702138776,
6003
+ 2966460450,
6004
+ 3352799412,
6005
+ 1504918807,
6006
+ 783551873,
6007
+ 3082640443,
6008
+ 3233442989,
6009
+ 3988292384,
6010
+ 2596254646,
6011
+ 62317068,
6012
+ 1957810842,
6013
+ 3939845945,
6014
+ 2647816111,
6015
+ 81470997,
6016
+ 1943803523,
6017
+ 3814918930,
6018
+ 2489596804,
6019
+ 225274430,
6020
+ 2053790376,
6021
+ 3826175755,
6022
+ 2466906013,
6023
+ 167816743,
6024
+ 2097651377,
6025
+ 4027552580,
6026
+ 2265490386,
6027
+ 503444072,
6028
+ 1762050814,
6029
+ 4150417245,
6030
+ 2154129355,
6031
+ 426522225,
6032
+ 1852507879,
6033
+ 4275313526,
6034
+ 2312317920,
6035
+ 282753626,
6036
+ 1742555852,
6037
+ 4189708143,
6038
+ 2394877945,
6039
+ 397917763,
6040
+ 1622183637,
6041
+ 3604390888,
6042
+ 2714866558,
6043
+ 953729732,
6044
+ 1340076626,
6045
+ 3518719985,
6046
+ 2797360999,
6047
+ 1068828381,
6048
+ 1219638859,
6049
+ 3624741850,
6050
+ 2936675148,
6051
+ 906185462,
6052
+ 1090812512,
6053
+ 3747672003,
6054
+ 2825379669,
6055
+ 829329135,
6056
+ 1181335161,
6057
+ 3412177804,
6058
+ 3160834842,
6059
+ 628085408,
6060
+ 1382605366,
6061
+ 3423369109,
6062
+ 3138078467,
6063
+ 570562233,
6064
+ 1426400815,
6065
+ 3317316542,
6066
+ 2998733608,
6067
+ 733239954,
6068
+ 1555261956,
6069
+ 3268935591,
6070
+ 3050360625,
6071
+ 752459403,
6072
+ 1541320221,
6073
+ 2607071920,
6074
+ 3965973030,
6075
+ 1969922972,
6076
+ 40735498,
6077
+ 2617837225,
6078
+ 3943577151,
6079
+ 1913087877,
6080
+ 83908371,
6081
+ 2512341634,
6082
+ 3803740692,
6083
+ 2075208622,
6084
+ 213261112,
6085
+ 2463272603,
6086
+ 3855990285,
6087
+ 2094854071,
6088
+ 198958881,
6089
+ 2262029012,
6090
+ 4057260610,
6091
+ 1759359992,
6092
+ 534414190,
6093
+ 2176718541,
6094
+ 4139329115,
6095
+ 1873836001,
6096
+ 414664567,
6097
+ 2282248934,
6098
+ 4279200368,
6099
+ 1711684554,
6100
+ 285281116,
6101
+ 2405801727,
6102
+ 4167216745,
6103
+ 1634467795,
6104
+ 376229701,
6105
+ 2685067896,
6106
+ 3608007406,
6107
+ 1308918612,
6108
+ 956543938,
6109
+ 2808555105,
6110
+ 3495958263,
6111
+ 1231636301,
6112
+ 1047427035,
6113
+ 2932959818,
6114
+ 3654703836,
6115
+ 1088359270,
6116
+ 936918e3,
6117
+ 2847714899,
6118
+ 3736837829,
6119
+ 1202900863,
6120
+ 817233897,
6121
+ 3183342108,
6122
+ 3401237130,
6123
+ 1404277552,
6124
+ 615818150,
6125
+ 3134207493,
6126
+ 3453421203,
6127
+ 1423857449,
6128
+ 601450431,
6129
+ 3009837614,
6130
+ 3294710456,
6131
+ 1567103746,
6132
+ 711928724,
6133
+ 3020668471,
6134
+ 3272380065,
6135
+ 1510334235,
6136
+ 755167117
6137
+ ];
6138
+ if (typeof Int32Array !== "undefined") {
6139
+ CRC_TABLE = new Int32Array(CRC_TABLE);
6140
+ }
6141
+ function ensureBuffer(input) {
6142
+ if (Buffer2.isBuffer(input)) {
6143
+ return input;
6144
+ }
6145
+ var hasNewBufferAPI = typeof Buffer2.alloc === "function" && typeof Buffer2.from === "function";
6146
+ if (typeof input === "number") {
6147
+ return hasNewBufferAPI ? Buffer2.alloc(input) : new Buffer2(input);
6148
+ } else if (typeof input === "string") {
6149
+ return hasNewBufferAPI ? Buffer2.from(input) : new Buffer2(input);
6150
+ } else {
6151
+ throw new Error("input must be buffer, number, or string, received " + typeof input);
6152
+ }
6153
+ }
6154
+ function bufferizeInt(num) {
6155
+ var tmp = ensureBuffer(4);
6156
+ tmp.writeInt32BE(num, 0);
6157
+ return tmp;
6158
+ }
6159
+ function _crc32(buf, previous) {
6160
+ buf = ensureBuffer(buf);
6161
+ if (Buffer2.isBuffer(previous)) {
6162
+ previous = previous.readUInt32BE(0);
6163
+ }
6164
+ var crc = ~~previous ^ -1;
6165
+ for (var n = 0; n < buf.length; n++) {
6166
+ crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
6167
+ }
6168
+ return crc ^ -1;
6169
+ }
6170
+ function crc322() {
6171
+ return bufferizeInt(_crc32.apply(null, arguments));
6172
+ }
6173
+ crc322.signed = function() {
6174
+ return _crc32.apply(null, arguments);
6175
+ };
6176
+ crc322.unsigned = function() {
6177
+ return _crc32.apply(null, arguments) >>> 0;
6178
+ };
6179
+ module2.exports = crc322;
6180
+ }
6181
+ });
6182
+
5873
6183
  // ../../node_modules/.pnpm/text-table@0.2.0/node_modules/text-table/index.js
5874
6184
  var require_text_table = __commonJS({
5875
6185
  "../../node_modules/.pnpm/text-table@0.2.0/node_modules/text-table/index.js"(exports, module2) {
@@ -9078,7 +9388,7 @@ module.exports = __toCommonJS(src_exports);
9078
9388
  var import_build_utils3 = require("@vercel/build-utils");
9079
9389
  var import_superstatic = __toESM(require_superstatic());
9080
9390
  var import_nft2 = require("@vercel/nft");
9081
- var import_async_sema2 = __toESM(require_lib());
9391
+ var import_async_sema3 = __toESM(require_lib());
9082
9392
  var import_escape_string_regexp3 = __toESM(require_escape_string_regexp());
9083
9393
  var import_find_up = __toESM(require_find_up());
9084
9394
  var import_fs_extra6 = __toESM(require_lib2());
@@ -9093,9 +9403,12 @@ var import_semver2 = __toESM(require_semver());
9093
9403
 
9094
9404
  // src/utils.ts
9095
9405
  var import_build_utils = require("@vercel/build-utils");
9406
+ var import_async_sema = __toESM(require_lib());
9407
+ var import_buffer_crc32 = __toESM(require_buffer_crc32());
9096
9408
  var import_fs_extra3 = __toESM(require_lib2());
9097
9409
  var import_path2 = __toESM(require("path"));
9098
9410
  var import_semver = __toESM(require_semver());
9411
+ var import_zlib2 = __toESM(require("zlib"));
9099
9412
  var import_url = __toESM(require("url"));
9100
9413
  var import_module = require("module");
9101
9414
  var import_escape_string_regexp = __toESM(require_escape_string_regexp());
@@ -9174,6 +9487,7 @@ var MIB = 1024 * KIB;
9174
9487
  var EDGE_FUNCTION_SIZE_LIMIT = 4 * MIB;
9175
9488
  var MAX_UNCOMPRESSED_LAMBDA_SIZE = 250 * MIB;
9176
9489
  var LAMBDA_RESERVED_UNCOMPRESSED_SIZE = 2.5 * MIB;
9490
+ var LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * KIB;
9177
9491
 
9178
9492
  // src/edge-function-source/get-edge-function-source.ts
9179
9493
  var import_zlib = __toESM(require("zlib"));
@@ -9582,7 +9896,7 @@ function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
9582
9896
  }
9583
9897
  return parentFilesMap;
9584
9898
  }
9585
- var collectTracedFiles = async (file, baseDir, lstatResults, lstatSema, reasons, files) => {
9899
+ var collectTracedFiles = (baseDir, lstatResults, lstatSema, reasons, files) => async (file) => {
9586
9900
  const reason = reasons.get(file);
9587
9901
  if (reason && reason.type.includes("initial")) {
9588
9902
  return;
@@ -9598,42 +9912,47 @@ var collectTracedFiles = async (file, baseDir, lstatResults, lstatSema, reasons,
9598
9912
  });
9599
9913
  };
9600
9914
  var ExperimentalTraceVersion = `9.0.4-canary.1`;
9601
- async function createPseudoLayer({
9602
- files,
9603
- lstatSema,
9604
- lstatResults
9605
- }) {
9606
- let pseudoLayerBytes = 0;
9607
- const pseudoLayer = {};
9608
- const fileNames = Object.keys(files);
9609
- await Promise.all(
9610
- fileNames.map(async (fileName) => {
9611
- await lstatSema.acquire();
9612
- const file = files[fileName];
9613
- if ((0, import_build_utils.isSymbolicLink)(file.mode)) {
9614
- const symlinkTarget = await import_fs_extra3.default.readlink(file.fsPath);
9615
- pseudoLayer[fileName] = {
9616
- file,
9617
- isSymlink: true,
9618
- symlinkTarget
9619
- };
9620
- } else {
9621
- if (!lstatResults[file.fsPath]) {
9622
- lstatResults[file.fsPath] = lstatSema.acquire().then(() => (0, import_fs_extra3.lstat)(file.fsPath)).finally(() => lstatSema.release());
9623
- }
9624
- const { size } = await lstatResults[file.fsPath];
9625
- pseudoLayerBytes += size;
9626
- pseudoLayer[fileName] = {
9627
- file,
9628
- isSymlink: false,
9629
- uncompressedSize: size
9630
- };
9915
+ var compressBuffer = (buf) => {
9916
+ return new Promise((resolve, reject) => {
9917
+ import_zlib2.default.deflateRaw(
9918
+ buf,
9919
+ { level: import_zlib2.default.constants.Z_BEST_COMPRESSION },
9920
+ (err, compBuf) => {
9921
+ if (err)
9922
+ return reject(err);
9923
+ resolve(compBuf);
9631
9924
  }
9632
- lstatSema.release();
9633
- })
9634
- );
9925
+ );
9926
+ });
9927
+ };
9928
+ async function createPseudoLayer(files) {
9929
+ const pseudoLayer = {};
9930
+ let pseudoLayerBytes = 0;
9931
+ for (const fileName of Object.keys(files)) {
9932
+ const file = files[fileName];
9933
+ if ((0, import_build_utils.isSymbolicLink)(file.mode)) {
9934
+ const symlinkTarget = await import_fs_extra3.default.readlink(file.fsPath);
9935
+ pseudoLayer[fileName] = {
9936
+ file,
9937
+ isSymlink: true,
9938
+ symlinkTarget
9939
+ };
9940
+ } else {
9941
+ const origBuffer = await (0, import_build_utils.streamToBuffer)(file.toStream());
9942
+ const compBuffer = await compressBuffer(origBuffer);
9943
+ pseudoLayerBytes += compBuffer.byteLength;
9944
+ pseudoLayer[fileName] = {
9945
+ file,
9946
+ compBuffer,
9947
+ isSymlink: false,
9948
+ crc32: import_buffer_crc32.default.unsigned(origBuffer),
9949
+ uncompressedSize: origBuffer.byteLength
9950
+ };
9951
+ }
9952
+ }
9635
9953
  return { pseudoLayer, pseudoLayerBytes };
9636
9954
  }
9955
+ var createLambdaSema = new import_async_sema.Sema(1);
9637
9956
  async function createLambdaFromPseudoLayers({
9638
9957
  files: baseFiles,
9639
9958
  layers,
@@ -9641,6 +9960,7 @@ async function createLambdaFromPseudoLayers({
9641
9960
  nextVersion,
9642
9961
  ...lambdaOptions
9643
9962
  }) {
9963
+ await createLambdaSema.acquire();
9644
9964
  const files = {};
9645
9965
  const addedFiles = /* @__PURE__ */ new Set();
9646
9966
  for (const layer of layers) {
@@ -9661,6 +9981,7 @@ async function createLambdaFromPseudoLayers({
9661
9981
  files[fileName] = file;
9662
9982
  addedFiles.add(fileName);
9663
9983
  }
9984
+ createLambdaSema.release();
9664
9985
  return new import_build_utils.NodejsLambda({
9665
9986
  ...lambdaOptions,
9666
9987
  ...isStreaming ? {
@@ -10005,6 +10326,8 @@ async function getPageLambdaGroups({
10005
10326
  compressedPages,
10006
10327
  tracedPseudoLayer,
10007
10328
  initialPseudoLayer,
10329
+ initialPseudoLayerUncompressed,
10330
+ lambdaCompressedByteLimit,
10008
10331
  internalPages,
10009
10332
  pageExtensions
10010
10333
  }) {
@@ -10032,18 +10355,22 @@ async function getPageLambdaGroups({
10032
10355
  let matchingGroup = groups.find((group) => {
10033
10356
  const matches = group.maxDuration === opts.maxDuration && group.memory === opts.memory && group.isPrerenders === isPrerenderRoute;
10034
10357
  if (matches) {
10035
- let newTracedFilesUncompressedSize = group.pseudoLayerBytes;
10358
+ let newTracedFilesSize = group.pseudoLayerBytes;
10359
+ let newTracedFilesUncompressedSize = group.pseudoLayerUncompressedBytes;
10036
10360
  for (const newPage of newPages) {
10037
10361
  Object.keys(pageTraces[newPage] || {}).map((file) => {
10038
10362
  if (!group.pseudoLayer[file]) {
10039
10363
  const item = tracedPseudoLayer[file];
10364
+ newTracedFilesSize += item.compBuffer?.byteLength || 0;
10040
10365
  newTracedFilesUncompressedSize += item.uncompressedSize || 0;
10041
10366
  }
10042
10367
  });
10368
+ newTracedFilesSize += compressedPages[newPage].compBuffer.byteLength;
10043
10369
  newTracedFilesUncompressedSize += compressedPages[newPage].uncompressedSize;
10044
10370
  }
10045
10371
  const underUncompressedLimit = newTracedFilesUncompressedSize < MAX_UNCOMPRESSED_LAMBDA_SIZE - LAMBDA_RESERVED_UNCOMPRESSED_SIZE;
10046
- return underUncompressedLimit;
10372
+ const underCompressedLimit = newTracedFilesSize < lambdaCompressedByteLimit - LAMBDA_RESERVED_COMPRESSED_SIZE;
10373
+ return underUncompressedLimit && underCompressedLimit;
10047
10374
  }
10048
10375
  return false;
10049
10376
  });
@@ -10056,6 +10383,7 @@ async function getPageLambdaGroups({
10056
10383
  isPrerenders: isPrerenderRoute,
10057
10384
  isApiLambda: !!isApiPage(page),
10058
10385
  pseudoLayerBytes: initialPseudoLayer.pseudoLayerBytes,
10386
+ pseudoLayerUncompressedBytes: initialPseudoLayerUncompressed,
10059
10387
  pseudoLayer: Object.assign({}, initialPseudoLayer.pseudoLayer)
10060
10388
  };
10061
10389
  groups.push(newGroup);
@@ -10064,24 +10392,31 @@ async function getPageLambdaGroups({
10064
10392
  for (const newPage of newPages) {
10065
10393
  Object.keys(pageTraces[newPage] || {}).map((file) => {
10066
10394
  const pseudoItem = tracedPseudoLayer[file];
10395
+ const compressedSize = pseudoItem?.compBuffer?.byteLength || 0;
10067
10396
  if (!matchingGroup.pseudoLayer[file]) {
10068
10397
  matchingGroup.pseudoLayer[file] = pseudoItem;
10069
- matchingGroup.pseudoLayerBytes += pseudoItem.uncompressedSize || 0;
10398
+ matchingGroup.pseudoLayerBytes += compressedSize;
10399
+ matchingGroup.pseudoLayerUncompressedBytes += pseudoItem.uncompressedSize || 0;
10070
10400
  }
10071
10401
  });
10072
- matchingGroup.pseudoLayerBytes += compressedPages[newPage].uncompressedSize;
10402
+ matchingGroup.pseudoLayerBytes += compressedPages[newPage].compBuffer.byteLength;
10403
+ matchingGroup.pseudoLayerUncompressedBytes += compressedPages[newPage].uncompressedSize;
10073
10404
  }
10074
10405
  }
10075
10406
  return groups;
10076
10407
  }
10077
- var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compressedPages) => {
10408
+ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, pseudoLayerUncompressedBytes, compressedPages) => {
10078
10409
  const exceededLimitOutput = [];
10079
10410
  console.log(
10080
10411
  `Serverless Function's page${pages.length === 1 ? "" : "s"}: ${pages.join(
10081
10412
  ", "
10082
10413
  )}`
10083
10414
  );
10084
- exceededLimitOutput.push(["Large Dependencies", "Uncompressed size"]);
10415
+ exceededLimitOutput.push([
10416
+ "Large Dependencies",
10417
+ "Uncompressed size",
10418
+ "Compressed size"
10419
+ ]);
10085
10420
  const dependencies = {};
10086
10421
  for (const fileKey of Object.keys(pseudoLayer)) {
10087
10422
  if (!pseudoLayer[fileKey].isSymlink) {
@@ -10089,14 +10424,17 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10089
10424
  const depKey = fileKey.split("/").slice(0, 3).join("/");
10090
10425
  if (!dependencies[depKey]) {
10091
10426
  dependencies[depKey] = {
10427
+ compressed: 0,
10092
10428
  uncompressed: 0
10093
10429
  };
10094
10430
  }
10431
+ dependencies[depKey].compressed += fileItem.compBuffer.byteLength;
10095
10432
  dependencies[depKey].uncompressed += fileItem.uncompressedSize;
10096
10433
  }
10097
10434
  }
10098
10435
  for (const page of pages) {
10099
10436
  dependencies[`pages/${page}`] = {
10437
+ compressed: compressedPages[page].compBuffer.byteLength,
10100
10438
  uncompressed: compressedPages[page].uncompressedSize
10101
10439
  };
10102
10440
  }
@@ -10104,19 +10442,23 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10104
10442
  Object.keys(dependencies).sort((a, b) => {
10105
10443
  const aDep = dependencies[a];
10106
10444
  const bDep = dependencies[b];
10107
- if (aDep.uncompressed > bDep.uncompressed) {
10445
+ if (aDep.compressed > bDep.compressed) {
10108
10446
  return -1;
10109
10447
  }
10110
- if (aDep.uncompressed < bDep.uncompressed) {
10448
+ if (aDep.compressed < bDep.compressed) {
10111
10449
  return 1;
10112
10450
  }
10113
10451
  return 0;
10114
10452
  }).forEach((depKey) => {
10115
10453
  const dep = dependencies[depKey];
10116
- if (dep.uncompressed < 500 * KIB) {
10454
+ if (dep.compressed < 100 * KIB && dep.uncompressed < 500 * KIB) {
10117
10455
  return;
10118
10456
  }
10119
- exceededLimitOutput.push([depKey, prettyBytes(dep.uncompressed)]);
10457
+ exceededLimitOutput.push([
10458
+ depKey,
10459
+ prettyBytes(dep.uncompressed),
10460
+ prettyBytes(dep.compressed)
10461
+ ]);
10120
10462
  numLargeDependencies += 1;
10121
10463
  });
10122
10464
  if (numLargeDependencies === 0) {
@@ -10125,21 +10467,26 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10125
10467
  ]);
10126
10468
  }
10127
10469
  exceededLimitOutput.push([]);
10128
- exceededLimitOutput.push(["All dependencies", prettyBytes(pseudoLayerBytes)]);
10470
+ exceededLimitOutput.push([
10471
+ "All dependencies",
10472
+ prettyBytes(pseudoLayerUncompressedBytes),
10473
+ prettyBytes(pseudoLayerBytes)
10474
+ ]);
10129
10475
  console.log(
10130
10476
  (0, import_text_table.default)(exceededLimitOutput, {
10131
10477
  align: ["l", "r", "r"]
10132
10478
  })
10133
10479
  );
10134
10480
  };
10135
- var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10481
+ var detectLambdaLimitExceeding = async (lambdaGroups, compressedSizeLimit, compressedPages) => {
10482
+ const COMPRESSED_SIZE_LIMIT_CLOSE = compressedSizeLimit - 5 * MIB;
10136
10483
  const UNCOMPRESSED_SIZE_LIMIT_CLOSE = MAX_UNCOMPRESSED_LAMBDA_SIZE - 5 * MIB;
10137
10484
  let numExceededLimit = 0;
10138
10485
  let numCloseToLimit = 0;
10139
10486
  let loggedHeadInfo = false;
10140
10487
  const filteredGroups = lambdaGroups.filter((group) => {
10141
- const exceededLimit = group.pseudoLayerBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE;
10142
- const closeToLimit = group.pseudoLayerBytes > UNCOMPRESSED_SIZE_LIMIT_CLOSE;
10488
+ const exceededLimit = group.pseudoLayerBytes > compressedSizeLimit || group.pseudoLayerUncompressedBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE;
10489
+ const closeToLimit = group.pseudoLayerBytes > COMPRESSED_SIZE_LIMIT_CLOSE || group.pseudoLayerUncompressedBytes > UNCOMPRESSED_SIZE_LIMIT_CLOSE;
10143
10490
  if (closeToLimit || exceededLimit || (0, import_build_utils.getPlatformEnv)("BUILDER_DEBUG") || process.env.NEXT_DEBUG_FUNCTION_SIZE) {
10144
10491
  if (exceededLimit) {
10145
10492
  numExceededLimit += 1;
@@ -10155,6 +10502,8 @@ var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10155
10502
  if (numExceededLimit || numCloseToLimit) {
10156
10503
  console.log(
10157
10504
  `Warning: Max serverless function size of ${prettyBytes(
10505
+ compressedSizeLimit
10506
+ )} compressed or ${prettyBytes(
10158
10507
  MAX_UNCOMPRESSED_LAMBDA_SIZE
10159
10508
  )} uncompressed${numExceededLimit ? "" : " almost"} reached`
10160
10509
  );
@@ -10167,6 +10516,7 @@ var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10167
10516
  group.pages,
10168
10517
  group.pseudoLayer,
10169
10518
  group.pseudoLayerBytes,
10519
+ group.pseudoLayerUncompressedBytes,
10170
10520
  compressedPages
10171
10521
  );
10172
10522
  }
@@ -10654,13 +11004,13 @@ function normalizeEdgeFunctionPath(shortPath, appPathRoutesManifest) {
10654
11004
  if (shortPath.startsWith("app/") && (shortPath.endsWith("/page") || shortPath.endsWith("/route") || shortPath === "app/_not-found")) {
10655
11005
  const ogRoute = shortPath.replace(/^app\//, "/");
10656
11006
  shortPath = (appPathRoutesManifest[ogRoute] || shortPath.replace(/(^|\/)(page|route)$/, "")).replace(/^\//, "");
11007
+ if (!shortPath || shortPath === "/") {
11008
+ shortPath = "index";
11009
+ }
10657
11010
  }
10658
11011
  if (shortPath.startsWith("pages/")) {
10659
11012
  shortPath = shortPath.replace(/^pages\//, "");
10660
11013
  }
10661
- if (!shortPath || shortPath === "/") {
10662
- shortPath = "index";
10663
- }
10664
11014
  return shortPath;
10665
11015
  }
10666
11016
  async function getMiddlewareBundle({
@@ -10985,6 +11335,46 @@ async function getVariantsManifest(entryPath, outputDirectory) {
10985
11335
  );
10986
11336
  return variantsManifest;
10987
11337
  }
11338
+ async function getServerlessPages(params) {
11339
+ const appDir = import_path2.default.join(params.pagesDir, "../app");
11340
+ const [pages, appPaths, middlewareManifest] = await Promise.all([
11341
+ (0, import_build_utils.glob)("**/!(_middleware).js", params.pagesDir),
11342
+ params.appPathRoutesManifest ? Promise.all([
11343
+ (0, import_build_utils.glob)("**/page.js", appDir),
11344
+ (0, import_build_utils.glob)("**/route.js", appDir),
11345
+ (0, import_build_utils.glob)("**/_not-found.js", appDir)
11346
+ ]).then((items) => Object.assign(...items)) : Promise.resolve({}),
11347
+ getMiddlewareManifest(params.entryPath, params.outputDirectory)
11348
+ ]);
11349
+ const normalizedAppPaths = {};
11350
+ if (params.appPathRoutesManifest) {
11351
+ for (const [entry, normalizedEntry] of Object.entries(
11352
+ params.appPathRoutesManifest
11353
+ )) {
11354
+ const normalizedPath = `${import_path2.default.join(
11355
+ ".",
11356
+ normalizedEntry === "/" ? "/index" : normalizedEntry
11357
+ )}.js`;
11358
+ const globPath = `${import_path2.default.posix.join(".", entry)}.js`;
11359
+ if (appPaths[globPath]) {
11360
+ normalizedAppPaths[normalizedPath] = appPaths[globPath];
11361
+ }
11362
+ }
11363
+ }
11364
+ for (const edgeFunctionFile of Object.keys(
11365
+ middlewareManifest?.functions ?? {}
11366
+ )) {
11367
+ let edgePath = middlewareManifest?.functions?.[edgeFunctionFile].name || edgeFunctionFile;
11368
+ edgePath = normalizeEdgeFunctionPath(
11369
+ edgePath,
11370
+ params.appPathRoutesManifest || {}
11371
+ );
11372
+ edgePath = (edgePath || "index") + ".js";
11373
+ delete normalizedAppPaths[edgePath];
11374
+ delete pages[edgePath];
11375
+ }
11376
+ return { pages, appPaths: normalizedAppPaths };
11377
+ }
10988
11378
 
10989
11379
  // src/create-serverless-config.ts
10990
11380
  function getCustomData(importName, target) {
@@ -11402,7 +11792,7 @@ var legacy_versions_default = [
11402
11792
  // src/server-build.ts
11403
11793
  var import_path4 = __toESM(require("path"));
11404
11794
  var import_semver3 = __toESM(require_semver());
11405
- var import_async_sema = __toESM(require_lib());
11795
+ var import_async_sema2 = __toESM(require_lib());
11406
11796
  var import_build_utils2 = require("@vercel/build-utils");
11407
11797
  var import_nft = require("@vercel/nft");
11408
11798
  var import_resolve_from = __toESM(require_resolve_from());
@@ -11414,7 +11804,7 @@ var CORRECT_MIDDLEWARE_ORDER_VERSION = "v12.1.7-canary.29";
11414
11804
  var NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = "v12.1.7-canary.33";
11415
11805
  var EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = "v12.2.0";
11416
11806
  var CORRECTED_MANIFESTS_VERSION = "v12.2.0";
11417
- var BUNDLED_SERVER_NEXT_VERSION = "13.4.20-canary.26";
11807
+ var BUNDLED_SERVER_NEXT_VERSION = "v13.5.4";
11418
11808
  var BUNDLED_SERVER_NEXT_PATH = "next/dist/compiled/next-server/server.runtime.prod.js";
11419
11809
  async function serverBuild({
11420
11810
  dynamicPages,
@@ -11454,6 +11844,7 @@ async function serverBuild({
11454
11844
  omittedPrerenderRoutes,
11455
11845
  trailingSlashRedirects,
11456
11846
  isCorrectLocaleAPIRoutes,
11847
+ lambdaCompressedByteLimit,
11457
11848
  requiredServerFilesManifest,
11458
11849
  variantsManifest
11459
11850
  }) {
@@ -11482,6 +11873,10 @@ async function serverBuild({
11482
11873
  appBuildTraces = await (0, import_build_utils2.glob)("**/*.js.nft.json", appDir);
11483
11874
  appRscPrefetches = await (0, import_build_utils2.glob)(`**/*${RSC_PREFETCH_SUFFIX}`, appDir);
11484
11875
  const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || RSC_CONTENT_TYPE;
11876
+ if (appRscPrefetches["index.prefetch.rsc"]) {
11877
+ appRscPrefetches["__index.prefetch.rsc"] = appRscPrefetches["index.prefetch.rsc"];
11878
+ delete appRscPrefetches["index.prefetch.rsc"];
11879
+ }
11485
11880
  for (const value of Object.values(appRscPrefetches)) {
11486
11881
  if (!value.contentType) {
11487
11882
  value.contentType = rscContentTypeHeader;
@@ -11521,7 +11916,7 @@ async function serverBuild({
11521
11916
  if (!hasStatic500 && i18n) {
11522
11917
  hasStatic500 = !!staticPages[import_path4.default.posix.join(entryDirectory, i18n.defaultLocale, "500")];
11523
11918
  }
11524
- const lstatSema = new import_async_sema.Sema(25);
11919
+ const lstatSema = new import_async_sema2.Sema(25);
11525
11920
  const lstatResults = {};
11526
11921
  const nonLambdaSsgPages = /* @__PURE__ */ new Set();
11527
11922
  Object.keys(prerenderManifest.staticRoutes).forEach((route) => {
@@ -11646,23 +12041,18 @@ async function serverBuild({
11646
12041
  }
11647
12042
  (0, import_build_utils2.debug)("collecting initial Next.js server files");
11648
12043
  await Promise.all(
11649
- initialFileList.map(async (file) => {
11650
- await collectTracedFiles(
11651
- file,
12044
+ initialFileList.map(
12045
+ collectTracedFiles(
11652
12046
  baseDir,
11653
12047
  lstatResults,
11654
12048
  lstatSema,
11655
12049
  initialFileReasons,
11656
12050
  initialTracedFiles
11657
- );
11658
- })
12051
+ )
12052
+ )
11659
12053
  );
11660
12054
  (0, import_build_utils2.debug)("creating initial pseudo layer");
11661
- const initialPseudoLayer = await createPseudoLayer({
11662
- files: initialTracedFiles,
11663
- lstatResults,
11664
- lstatSema
11665
- });
12055
+ const initialPseudoLayer = await createPseudoLayer(initialTracedFiles);
11666
12056
  console.timeEnd(initialTracingLabel);
11667
12057
  const lambdaCreationLabel = "Created all serverless functions in";
11668
12058
  console.time(lambdaCreationLabel);
@@ -11670,13 +12060,13 @@ async function serverBuild({
11670
12060
  const nonApiPages = [];
11671
12061
  const appRouterPages = [];
11672
12062
  const appRouteHandlers = [];
11673
- for (const page of lambdaPageKeys) {
12063
+ lambdaPageKeys.forEach((page) => {
11674
12064
  if (internalPages.includes(page) && page !== "404.js" && !(page === "_error.js" && !(static404Page || lambdaPages["404.js"]))) {
11675
- continue;
12065
+ return;
11676
12066
  }
11677
12067
  const pathname = page.replace(/\.js$/, "");
11678
12068
  if (nonLambdaSsgPages.has(pathname)) {
11679
- continue;
12069
+ return;
11680
12070
  }
11681
12071
  const normalizedPathname = normalizePage(pathname);
11682
12072
  if (isDynamicRoute(normalizedPathname)) {
@@ -11693,7 +12083,7 @@ async function serverBuild({
11693
12083
  } else {
11694
12084
  nonApiPages.push(page);
11695
12085
  }
11696
- }
12086
+ });
11697
12087
  const requiredFiles = {};
11698
12088
  requiredFiles[import_path4.default.relative(baseDir, nextServerFile)] = new import_build_utils2.FileFsRef({
11699
12089
  mode: (await import_fs_extra5.default.lstat(nextServerFile)).mode,
@@ -11759,28 +12149,33 @@ async function serverBuild({
11759
12149
  });
11760
12150
  })
11761
12151
  );
11762
- const requiredFilesLayer = await createPseudoLayer({
11763
- files: requiredFiles,
11764
- lstatResults,
11765
- lstatSema
11766
- });
12152
+ const requiredFilesLayer = await createPseudoLayer(requiredFiles);
11767
12153
  Object.assign(
11768
12154
  initialPseudoLayer.pseudoLayer,
11769
12155
  requiredFilesLayer.pseudoLayer
11770
12156
  );
11771
12157
  initialPseudoLayer.pseudoLayerBytes += requiredFilesLayer.pseudoLayerBytes;
12158
+ const uncompressedInitialSize = Object.keys(
12159
+ initialPseudoLayer.pseudoLayer
12160
+ ).reduce((prev, cur) => {
12161
+ const file = initialPseudoLayer.pseudoLayer[cur];
12162
+ return prev + file.uncompressedSize || 0;
12163
+ }, 0);
11772
12164
  (0, import_build_utils2.debug)(
11773
12165
  JSON.stringify(
11774
12166
  {
11775
- initializeSizeUncompressed: initialPseudoLayer.pseudoLayerBytes
12167
+ uncompressedInitialSize,
12168
+ compressedInitialSize: initialPseudoLayer.pseudoLayerBytes
11776
12169
  },
11777
12170
  null,
11778
12171
  2
11779
12172
  )
11780
12173
  );
11781
- if (initialPseudoLayer.pseudoLayerBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE) {
12174
+ if (initialPseudoLayer.pseudoLayerBytes > lambdaCompressedByteLimit || uncompressedInitialSize > MAX_UNCOMPRESSED_LAMBDA_SIZE) {
11782
12175
  console.log(
11783
12176
  `Warning: Max serverless function size of ${(0, import_pretty_bytes3.default)(
12177
+ lambdaCompressedByteLimit
12178
+ )} compressed or ${(0, import_pretty_bytes3.default)(
11784
12179
  MAX_UNCOMPRESSED_LAMBDA_SIZE
11785
12180
  )} uncompressed reached`
11786
12181
  );
@@ -11788,10 +12183,11 @@ async function serverBuild({
11788
12183
  [],
11789
12184
  initialPseudoLayer.pseudoLayer,
11790
12185
  initialPseudoLayer.pseudoLayerBytes,
12186
+ uncompressedInitialSize,
11791
12187
  {}
11792
12188
  );
11793
12189
  throw new import_build_utils2.NowBuildError({
11794
- message: `Required files read using Node.js fs library and node_modules exceed max lambda size of ${MAX_UNCOMPRESSED_LAMBDA_SIZE} bytes`,
12190
+ message: `Required files read using Node.js fs library and node_modules exceed max lambda size of ${lambdaCompressedByteLimit} bytes`,
11795
12191
  code: "NEXT_REQUIRED_FILES_LIMIT",
11796
12192
  link: "https://vercel.com/docs/platform/limits#serverless-function-size"
11797
12193
  });
@@ -11842,22 +12238,17 @@ async function serverBuild({
11842
12238
  }
11843
12239
  return originalPagePath;
11844
12240
  };
11845
- const getBuildTraceFile = (page) => pageBuildTraces[page + ".nft.json"] || appBuildTraces[page + ".nft.json"];
12241
+ const getBuildTraceFile = (page) => {
12242
+ return pageBuildTraces[page + ".nft.json"] || appBuildTraces[page + ".nft.json"];
12243
+ };
11846
12244
  const pathsToTrace = mergedPageKeys.map((page) => {
11847
- const originalPagePath = getOriginalPagePath(page);
11848
- const pageBuildTrace = getBuildTraceFile(originalPagePath);
11849
- if (!pageBuildTrace) {
12245
+ if (!getBuildTraceFile(page)) {
11850
12246
  return lambdaPages[page].fsPath;
11851
12247
  }
11852
12248
  }).filter(Boolean);
11853
12249
  let traceResult;
11854
12250
  let parentFilesMap;
11855
12251
  if (pathsToTrace.length > 0) {
11856
- console.warn(
11857
- `Warning: running tracing as trace files were not present for:
11858
- `,
11859
- JSON.stringify(pathsToTrace, null, 2)
11860
- );
11861
12252
  traceResult = await (0, import_nft.nodeFileTrace)(pathsToTrace, {
11862
12253
  base: baseDir,
11863
12254
  cache: traceCache,
@@ -11923,37 +12314,28 @@ async function serverBuild({
11923
12314
  }
11924
12315
  reasons = traceResult?.reasons || /* @__PURE__ */ new Map();
11925
12316
  }
11926
- await Promise.all([
11927
- createPseudoLayer({
11928
- files: {
11929
- [page]: lambdaPages[page]
11930
- },
11931
- lstatResults,
11932
- lstatSema
11933
- }).then((res) => {
11934
- compressedPages[page] = res.pseudoLayer[page];
11935
- }),
11936
- ...fileList.map(async (file) => {
11937
- await collectTracedFiles(
11938
- file,
12317
+ await Promise.all(
12318
+ fileList.map(
12319
+ collectTracedFiles(
11939
12320
  baseDir,
11940
12321
  lstatResults,
11941
12322
  lstatSema,
11942
12323
  reasons,
11943
12324
  tracedFiles
11944
- );
11945
- })
11946
- ]);
12325
+ )
12326
+ )
12327
+ );
11947
12328
  pageTraces[page] = tracedFiles;
12329
+ compressedPages[page] = (await createPseudoLayer({
12330
+ [page]: lambdaPages[page]
12331
+ })).pseudoLayer[page];
11948
12332
  }
11949
- const tracedPseudoLayer = await createPseudoLayer({
11950
- files: mergedPageKeys.reduce((prev, page) => {
12333
+ const tracedPseudoLayer = await createPseudoLayer(
12334
+ mergedPageKeys.reduce((prev, page) => {
11951
12335
  Object.assign(prev, pageTraces[page]);
11952
12336
  return prev;
11953
- }, {}),
11954
- lstatResults,
11955
- lstatSema
11956
- });
12337
+ }, {})
12338
+ );
11957
12339
  const pageExtensions = requiredServerFilesManifest.config?.pageExtensions;
11958
12340
  const pageLambdaGroups = await getPageLambdaGroups({
11959
12341
  entryPath: projectDir,
@@ -11965,6 +12347,8 @@ async function serverBuild({
11965
12347
  compressedPages,
11966
12348
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11967
12349
  initialPseudoLayer,
12350
+ lambdaCompressedByteLimit,
12351
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11968
12352
  internalPages,
11969
12353
  pageExtensions
11970
12354
  });
@@ -11981,6 +12365,8 @@ async function serverBuild({
11981
12365
  compressedPages,
11982
12366
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11983
12367
  initialPseudoLayer,
12368
+ lambdaCompressedByteLimit,
12369
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11984
12370
  internalPages,
11985
12371
  pageExtensions
11986
12372
  });
@@ -11994,6 +12380,8 @@ async function serverBuild({
11994
12380
  compressedPages,
11995
12381
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11996
12382
  initialPseudoLayer,
12383
+ lambdaCompressedByteLimit,
12384
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11997
12385
  internalPages,
11998
12386
  pageExtensions
11999
12387
  });
@@ -12020,6 +12408,8 @@ async function serverBuild({
12020
12408
  compressedPages,
12021
12409
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
12022
12410
  initialPseudoLayer,
12411
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
12412
+ lambdaCompressedByteLimit,
12023
12413
  internalPages,
12024
12414
  pageExtensions
12025
12415
  });
@@ -12032,23 +12422,27 @@ async function serverBuild({
12032
12422
  apiLambdaGroups: apiLambdaGroups.map((group) => ({
12033
12423
  pages: group.pages,
12034
12424
  isPrerender: group.isPrerenders,
12035
- pseudoLayerBytes: group.pseudoLayerBytes
12425
+ pseudoLayerBytes: group.pseudoLayerBytes,
12426
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12036
12427
  })),
12037
12428
  pageLambdaGroups: pageLambdaGroups.map((group) => ({
12038
12429
  pages: group.pages,
12039
12430
  isPrerender: group.isPrerenders,
12040
- pseudoLayerBytes: group.pseudoLayerBytes
12431
+ pseudoLayerBytes: group.pseudoLayerBytes,
12432
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12041
12433
  })),
12042
12434
  appRouterLambdaGroups: appRouterLambdaGroups.map((group) => ({
12043
12435
  pages: group.pages,
12044
12436
  isPrerender: group.isPrerenders,
12045
- pseudoLayerBytes: group.pseudoLayerBytes
12437
+ pseudoLayerBytes: group.pseudoLayerBytes,
12438
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12046
12439
  })),
12047
12440
  appRouteHandlersLambdaGroups: appRouteHandlersLambdaGroups.map(
12048
12441
  (group) => ({
12049
12442
  pages: group.pages,
12050
12443
  isPrerender: group.isPrerenders,
12051
- pseudoLayerBytes: group.pseudoLayerBytes
12444
+ pseudoLayerBytes: group.pseudoLayerBytes,
12445
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12052
12446
  })
12053
12447
  ),
12054
12448
  nextServerLayerSize: initialPseudoLayer.pseudoLayerBytes
@@ -12063,121 +12457,118 @@ async function serverBuild({
12063
12457
  ...apiLambdaGroups,
12064
12458
  ...appRouteHandlersLambdaGroups
12065
12459
  ];
12066
- await detectLambdaLimitExceeding(combinedGroups, compressedPages);
12067
- await Promise.all(
12068
- combinedGroups.map(async (group) => {
12069
- const groupPageFiles = {};
12070
- for (const page of [...group.pages, ...internalPages]) {
12071
- const pageFileName = import_path4.default.normalize(
12072
- import_path4.default.relative(baseDir, lambdaPages[page].fsPath)
12460
+ await detectLambdaLimitExceeding(
12461
+ combinedGroups,
12462
+ lambdaCompressedByteLimit,
12463
+ compressedPages
12464
+ );
12465
+ for (const group of combinedGroups) {
12466
+ const groupPageFiles = {};
12467
+ for (const page of [...group.pages, ...internalPages]) {
12468
+ const pageFileName = import_path4.default.normalize(
12469
+ import_path4.default.relative(baseDir, lambdaPages[page].fsPath)
12470
+ );
12471
+ groupPageFiles[pageFileName] = compressedPages[page];
12472
+ }
12473
+ const updatedManifestFiles = {};
12474
+ if (isCorrectManifests) {
12475
+ for (const manifest of [
12476
+ "routes-manifest.json",
12477
+ "server/pages-manifest.json"
12478
+ ]) {
12479
+ const fsPath = import_path4.default.join(entryPath, outputDirectory, manifest);
12480
+ const relativePath = import_path4.default.relative(baseDir, fsPath);
12481
+ delete group.pseudoLayer[relativePath];
12482
+ const manifestData = await import_fs_extra5.default.readJSON(fsPath);
12483
+ const normalizedPages = new Set(
12484
+ group.pages.map((page) => {
12485
+ page = `/${page.replace(/\.js$/, "")}`;
12486
+ if (page === "/index")
12487
+ page = "/";
12488
+ return page;
12489
+ })
12073
12490
  );
12074
- groupPageFiles[pageFileName] = compressedPages[page];
12075
- }
12076
- const updatedManifestFiles = {};
12077
- if (isCorrectManifests) {
12078
- for (const manifest of [
12079
- "routes-manifest.json",
12080
- "server/pages-manifest.json"
12081
- ]) {
12082
- const fsPath = import_path4.default.join(entryPath, outputDirectory, manifest);
12083
- const relativePath = import_path4.default.relative(baseDir, fsPath);
12084
- delete group.pseudoLayer[relativePath];
12085
- const manifestData = await import_fs_extra5.default.readJSON(fsPath);
12086
- const normalizedPages = new Set(
12087
- group.pages.map((page) => {
12088
- page = `/${page.replace(/\.js$/, "")}`;
12089
- if (page === "/index")
12090
- page = "/";
12091
- return page;
12092
- })
12093
- );
12094
- switch (manifest) {
12095
- case "routes-manifest.json": {
12096
- const filterItem = (item) => normalizedPages.has(item.page);
12097
- manifestData.dynamicRoutes = manifestData.dynamicRoutes?.filter(filterItem);
12098
- manifestData.staticRoutes = manifestData.staticRoutes?.filter(filterItem);
12099
- break;
12100
- }
12101
- case "server/pages-manifest.json": {
12102
- for (const key of Object.keys(manifestData)) {
12103
- if (isDynamicRoute(key) && !normalizedPages.has(key)) {
12104
- delete manifestData[key];
12105
- }
12491
+ switch (manifest) {
12492
+ case "routes-manifest.json": {
12493
+ const filterItem = (item) => normalizedPages.has(item.page);
12494
+ manifestData.dynamicRoutes = manifestData.dynamicRoutes?.filter(filterItem);
12495
+ manifestData.staticRoutes = manifestData.staticRoutes?.filter(filterItem);
12496
+ break;
12497
+ }
12498
+ case "server/pages-manifest.json": {
12499
+ for (const key of Object.keys(manifestData)) {
12500
+ if (isDynamicRoute(key) && !normalizedPages.has(key)) {
12501
+ delete manifestData[key];
12106
12502
  }
12107
- break;
12108
- }
12109
- default: {
12110
- throw new import_build_utils2.NowBuildError({
12111
- message: `Unexpected manifest value ${manifest}, please contact support if this continues`,
12112
- code: "NEXT_MANIFEST_INVARIANT"
12113
- });
12114
12503
  }
12504
+ break;
12505
+ }
12506
+ default: {
12507
+ throw new import_build_utils2.NowBuildError({
12508
+ message: `Unexpected manifest value ${manifest}, please contact support if this continues`,
12509
+ code: "NEXT_MANIFEST_INVARIANT"
12510
+ });
12115
12511
  }
12116
- updatedManifestFiles[relativePath] = new import_build_utils2.FileBlob({
12117
- contentType: "application/json",
12118
- data: JSON.stringify(manifestData)
12119
- });
12120
12512
  }
12513
+ updatedManifestFiles[relativePath] = new import_build_utils2.FileBlob({
12514
+ contentType: "application/json",
12515
+ data: JSON.stringify(manifestData)
12516
+ });
12121
12517
  }
12122
- const launcherFiles = {
12123
- [import_path4.default.join(
12124
- import_path4.default.relative(baseDir, projectDir),
12125
- "___next_launcher.cjs"
12126
- )]: new import_build_utils2.FileBlob({
12127
- data: group.isAppRouter ? appLauncher : launcher
12128
- })
12129
- };
12130
- const operationType = getOperationType({ group, prerenderManifest });
12131
- const lambda = await createLambdaFromPseudoLayers({
12132
- files: {
12133
- ...launcherFiles,
12134
- ...updatedManifestFiles
12135
- },
12136
- layers: [group.pseudoLayer, groupPageFiles],
12137
- handler: import_path4.default.join(
12138
- import_path4.default.relative(baseDir, projectDir),
12139
- "___next_launcher.cjs"
12140
- ),
12141
- operationType,
12142
- memory: group.memory,
12143
- runtime: nodeVersion.runtime,
12144
- maxDuration: group.maxDuration,
12145
- isStreaming: group.isStreaming,
12146
- nextVersion
12147
- });
12148
- for (const page of group.pages) {
12149
- const pageNoExt = page.replace(/\.js$/, "");
12150
- let isPrerender = prerenderRoutes.has(
12151
- import_path4.default.join("/", pageNoExt === "index" ? "" : pageNoExt)
12152
- );
12153
- if (!isPrerender && routesManifest?.i18n) {
12154
- isPrerender = routesManifest.i18n.locales.some((locale) => {
12155
- return prerenderRoutes.has(
12156
- import_path4.default.join("/", locale, pageNoExt === "index" ? "" : pageNoExt)
12157
- );
12158
- });
12159
- }
12160
- const outputName = normalizeIndexOutput(
12161
- import_path4.default.posix.join(entryDirectory, pageNoExt),
12162
- true
12163
- );
12164
- if (i18n && !isPrerender && !group.isAppRouter && (!isCorrectLocaleAPIRoutes || !(pageNoExt === "api" || pageNoExt.startsWith("api/")))) {
12165
- for (const locale of i18n.locales) {
12166
- lambdas[normalizeIndexOutput(
12167
- import_path4.default.posix.join(
12168
- entryDirectory,
12169
- locale,
12170
- pageNoExt === "index" ? "" : pageNoExt
12171
- ),
12172
- true
12173
- )] = lambda;
12174
- }
12175
- } else {
12176
- lambdas[outputName] = lambda;
12518
+ }
12519
+ const launcherFiles = {
12520
+ [import_path4.default.join(import_path4.default.relative(baseDir, projectDir), "___next_launcher.cjs")]: new import_build_utils2.FileBlob({ data: group.isAppRouter ? appLauncher : launcher })
12521
+ };
12522
+ const operationType = getOperationType({ group, prerenderManifest });
12523
+ const lambda = await createLambdaFromPseudoLayers({
12524
+ files: {
12525
+ ...launcherFiles,
12526
+ ...updatedManifestFiles
12527
+ },
12528
+ layers: [group.pseudoLayer, groupPageFiles],
12529
+ handler: import_path4.default.join(
12530
+ import_path4.default.relative(baseDir, projectDir),
12531
+ "___next_launcher.cjs"
12532
+ ),
12533
+ operationType,
12534
+ memory: group.memory,
12535
+ runtime: nodeVersion.runtime,
12536
+ maxDuration: group.maxDuration,
12537
+ isStreaming: group.isStreaming,
12538
+ nextVersion
12539
+ });
12540
+ for (const page of group.pages) {
12541
+ const pageNoExt = page.replace(/\.js$/, "");
12542
+ let isPrerender = prerenderRoutes.has(
12543
+ import_path4.default.join("/", pageNoExt === "index" ? "" : pageNoExt)
12544
+ );
12545
+ if (!isPrerender && routesManifest?.i18n) {
12546
+ isPrerender = routesManifest.i18n.locales.some((locale) => {
12547
+ return prerenderRoutes.has(
12548
+ import_path4.default.join("/", locale, pageNoExt === "index" ? "" : pageNoExt)
12549
+ );
12550
+ });
12551
+ }
12552
+ const outputName = normalizeIndexOutput(
12553
+ import_path4.default.posix.join(entryDirectory, pageNoExt),
12554
+ true
12555
+ );
12556
+ if (i18n && !isPrerender && !group.isAppRouter && (!isCorrectLocaleAPIRoutes || !(pageNoExt === "api" || pageNoExt.startsWith("api/")))) {
12557
+ for (const locale of i18n.locales) {
12558
+ lambdas[normalizeIndexOutput(
12559
+ import_path4.default.posix.join(
12560
+ entryDirectory,
12561
+ locale,
12562
+ pageNoExt === "index" ? "" : pageNoExt
12563
+ ),
12564
+ true
12565
+ )] = lambda;
12177
12566
  }
12567
+ } else {
12568
+ lambdas[outputName] = lambda;
12178
12569
  }
12179
- })
12180
- );
12570
+ }
12571
+ }
12181
12572
  console.timeEnd(lambdaCreationLabel);
12182
12573
  }
12183
12574
  const prerenderRoute = onPrerenderRoute({
@@ -12606,7 +12997,7 @@ async function serverBuild({
12606
12997
  dest: import_path4.default.posix.join(
12607
12998
  "/",
12608
12999
  entryDirectory,
12609
- `/index${RSC_PREFETCH_SUFFIX}`
13000
+ `/__index${RSC_PREFETCH_SUFFIX}`
12610
13001
  ),
12611
13002
  headers: { vary: rscVaryHeader },
12612
13003
  continue: true,
@@ -12693,7 +13084,7 @@ async function serverBuild({
12693
13084
  src: import_path4.default.posix.join(
12694
13085
  "/",
12695
13086
  entryDirectory,
12696
- `/index${RSC_PREFETCH_SUFFIX}`
13087
+ `/__index${RSC_PREFETCH_SUFFIX}`
12697
13088
  ),
12698
13089
  dest: import_path4.default.posix.join("/", entryDirectory, "/index.rsc"),
12699
13090
  has: [
@@ -13955,8 +14346,6 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13955
14346
  let tracedPseudoLayer;
13956
14347
  const apiPages = [];
13957
14348
  const nonApiPages = [];
13958
- const lstatSema = new import_async_sema2.Sema(25);
13959
- const lstatResults = {};
13960
14349
  for (const page of pageKeys) {
13961
14350
  const pagePath = pages[page].fsPath;
13962
14351
  const route = `/${page.replace(/\.js$/, "")}`;
@@ -13968,11 +14357,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13968
14357
  nonApiPages.push(page);
13969
14358
  }
13970
14359
  compressedPages[page] = (await createPseudoLayer({
13971
- files: {
13972
- [page]: pages[page]
13973
- },
13974
- lstatResults,
13975
- lstatSema
14360
+ [page]: pages[page]
13976
14361
  })).pseudoLayer[page];
13977
14362
  }
13978
14363
  const mergedPageKeys = [...nonApiPages, ...apiPages];
@@ -13983,6 +14368,8 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13983
14368
  console.time(tracingLabel);
13984
14369
  }
13985
14370
  const nftCache = /* @__PURE__ */ Object.create(null);
14371
+ const lstatSema = new import_async_sema3.Sema(25);
14372
+ const lstatResults = {};
13986
14373
  const pathsToTrace = mergedPageKeys.map((page) => pages[page].fsPath);
13987
14374
  const result = await (0, import_nft2.nodeFileTrace)(pathsToTrace, {
13988
14375
  base: baseDir,
@@ -14006,16 +14393,15 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
14006
14393
  }
14007
14394
  const reasons = result.reasons;
14008
14395
  await Promise.all(
14009
- Array.from(fileList).map(async (file) => {
14010
- await collectTracedFiles(
14011
- file,
14396
+ Array.from(fileList).map(
14397
+ collectTracedFiles(
14012
14398
  baseDir,
14013
14399
  lstatResults,
14014
14400
  lstatSema,
14015
14401
  reasons,
14016
14402
  tracedFiles
14017
- );
14018
- })
14403
+ )
14404
+ )
14019
14405
  );
14020
14406
  pageTraces[page] = tracedFiles;
14021
14407
  }
@@ -14026,14 +14412,12 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
14026
14412
  if (hasLambdas) {
14027
14413
  console.time(zippingLabel);
14028
14414
  }
14029
- tracedPseudoLayer = await createPseudoLayer({
14030
- files: mergedPageKeys.reduce((prev, page) => {
14415
+ tracedPseudoLayer = await createPseudoLayer(
14416
+ mergedPageKeys.reduce((prev, page) => {
14031
14417
  Object.assign(prev, pageTraces[page]);
14032
14418
  return prev;
14033
- }, {}),
14034
- lstatResults,
14035
- lstatSema
14036
- });
14419
+ }, {})
14420
+ );
14037
14421
  if (hasLambdas) {
14038
14422
  console.timeEnd(zippingLabel);
14039
14423
  }
@@ -14929,45 +15313,6 @@ var prepareCache = async ({
14929
15313
  (0, import_build_utils3.debug)("Cache file manifest produced");
14930
15314
  return cache;
14931
15315
  };
14932
- async function getServerlessPages(params) {
14933
- const [pages, appPaths, middlewareManifest] = await Promise.all([
14934
- (0, import_build_utils3.glob)("**/!(_middleware).js", params.pagesDir),
14935
- params.appPathRoutesManifest ? Promise.all([
14936
- (0, import_build_utils3.glob)("**/page.js", import_path5.default.join(params.pagesDir, "../app")),
14937
- (0, import_build_utils3.glob)("**/route.js", import_path5.default.join(params.pagesDir, "../app")),
14938
- (0, import_build_utils3.glob)("**/_not-found.js", import_path5.default.join(params.pagesDir, "../app"))
14939
- ]).then((items) => Object.assign(...items)) : Promise.resolve({}),
14940
- getMiddlewareManifest(params.entryPath, params.outputDirectory)
14941
- ]);
14942
- const normalizedAppPaths = {};
14943
- if (params.appPathRoutesManifest) {
14944
- for (const [entry, normalizedEntry] of Object.entries(
14945
- params.appPathRoutesManifest
14946
- )) {
14947
- const normalizedPath = `${import_path5.default.join(
14948
- ".",
14949
- normalizedEntry === "/" ? "/index" : normalizedEntry
14950
- )}.js`;
14951
- const globPath = `${import_path5.default.join(".", entry)}.js`;
14952
- if (appPaths[globPath]) {
14953
- normalizedAppPaths[normalizedPath] = appPaths[globPath];
14954
- }
14955
- }
14956
- }
14957
- for (const edgeFunctionFile of Object.keys(
14958
- middlewareManifest?.functions ?? {}
14959
- )) {
14960
- let edgePath = middlewareManifest?.functions?.[edgeFunctionFile].name || edgeFunctionFile;
14961
- edgePath = normalizeEdgeFunctionPath(
14962
- edgePath,
14963
- params.appPathRoutesManifest || {}
14964
- );
14965
- edgePath = (edgePath || "index") + ".js";
14966
- delete normalizedAppPaths[edgePath];
14967
- delete pages[edgePath];
14968
- }
14969
- return { pages, appPaths: normalizedAppPaths };
14970
- }
14971
15316
  // Annotate the CommonJS export names for ESM import in node:
14972
15317
  0 && (module.exports = {
14973
15318
  MAX_AGE_ONE_YEAR,