@vercel/next 4.0.9 → 4.0.10

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 +577 -240
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -837,7 +837,7 @@ var require_lib = __commonJS({
837
837
  function defaultInit() {
838
838
  return "1";
839
839
  }
840
- var Sema3 = class {
840
+ var Sema4 = class {
841
841
  constructor(nr, { initFn = defaultInit, pauseFn, resumeFn, capacity = 10 } = {}) {
842
842
  if (isFn(pauseFn) !== isFn(resumeFn)) {
843
843
  throw new Error("pauseFn and resumeFn must be both set for pausing");
@@ -893,9 +893,9 @@ var require_lib = __commonJS({
893
893
  return this.waiting.length;
894
894
  }
895
895
  };
896
- exports.Sema = Sema3;
896
+ exports.Sema = Sema4;
897
897
  function RateLimit(rps, { timeUnit = 1e3, uniformDistribution = false } = {}) {
898
- const sema = new Sema3(uniformDistribution ? 1 : rps);
898
+ const sema = new Sema4(uniformDistribution ? 1 : rps);
899
899
  const delay = uniformDistribution ? timeUnit / rps : timeUnit;
900
900
  return async function rl() {
901
901
  await sema.acquire();
@@ -5870,6 +5870,313 @@ var require_semver = __commonJS({
5870
5870
  }
5871
5871
  });
5872
5872
 
5873
+ // ../../node_modules/.pnpm/buffer-crc32@0.2.13/node_modules/buffer-crc32/index.js
5874
+ var require_buffer_crc32 = __commonJS({
5875
+ "../../node_modules/.pnpm/buffer-crc32@0.2.13/node_modules/buffer-crc32/index.js"(exports, module2) {
5876
+ var Buffer2 = require("buffer").Buffer;
5877
+ var CRC_TABLE = [
5878
+ 0,
5879
+ 1996959894,
5880
+ 3993919788,
5881
+ 2567524794,
5882
+ 124634137,
5883
+ 1886057615,
5884
+ 3915621685,
5885
+ 2657392035,
5886
+ 249268274,
5887
+ 2044508324,
5888
+ 3772115230,
5889
+ 2547177864,
5890
+ 162941995,
5891
+ 2125561021,
5892
+ 3887607047,
5893
+ 2428444049,
5894
+ 498536548,
5895
+ 1789927666,
5896
+ 4089016648,
5897
+ 2227061214,
5898
+ 450548861,
5899
+ 1843258603,
5900
+ 4107580753,
5901
+ 2211677639,
5902
+ 325883990,
5903
+ 1684777152,
5904
+ 4251122042,
5905
+ 2321926636,
5906
+ 335633487,
5907
+ 1661365465,
5908
+ 4195302755,
5909
+ 2366115317,
5910
+ 997073096,
5911
+ 1281953886,
5912
+ 3579855332,
5913
+ 2724688242,
5914
+ 1006888145,
5915
+ 1258607687,
5916
+ 3524101629,
5917
+ 2768942443,
5918
+ 901097722,
5919
+ 1119000684,
5920
+ 3686517206,
5921
+ 2898065728,
5922
+ 853044451,
5923
+ 1172266101,
5924
+ 3705015759,
5925
+ 2882616665,
5926
+ 651767980,
5927
+ 1373503546,
5928
+ 3369554304,
5929
+ 3218104598,
5930
+ 565507253,
5931
+ 1454621731,
5932
+ 3485111705,
5933
+ 3099436303,
5934
+ 671266974,
5935
+ 1594198024,
5936
+ 3322730930,
5937
+ 2970347812,
5938
+ 795835527,
5939
+ 1483230225,
5940
+ 3244367275,
5941
+ 3060149565,
5942
+ 1994146192,
5943
+ 31158534,
5944
+ 2563907772,
5945
+ 4023717930,
5946
+ 1907459465,
5947
+ 112637215,
5948
+ 2680153253,
5949
+ 3904427059,
5950
+ 2013776290,
5951
+ 251722036,
5952
+ 2517215374,
5953
+ 3775830040,
5954
+ 2137656763,
5955
+ 141376813,
5956
+ 2439277719,
5957
+ 3865271297,
5958
+ 1802195444,
5959
+ 476864866,
5960
+ 2238001368,
5961
+ 4066508878,
5962
+ 1812370925,
5963
+ 453092731,
5964
+ 2181625025,
5965
+ 4111451223,
5966
+ 1706088902,
5967
+ 314042704,
5968
+ 2344532202,
5969
+ 4240017532,
5970
+ 1658658271,
5971
+ 366619977,
5972
+ 2362670323,
5973
+ 4224994405,
5974
+ 1303535960,
5975
+ 984961486,
5976
+ 2747007092,
5977
+ 3569037538,
5978
+ 1256170817,
5979
+ 1037604311,
5980
+ 2765210733,
5981
+ 3554079995,
5982
+ 1131014506,
5983
+ 879679996,
5984
+ 2909243462,
5985
+ 3663771856,
5986
+ 1141124467,
5987
+ 855842277,
5988
+ 2852801631,
5989
+ 3708648649,
5990
+ 1342533948,
5991
+ 654459306,
5992
+ 3188396048,
5993
+ 3373015174,
5994
+ 1466479909,
5995
+ 544179635,
5996
+ 3110523913,
5997
+ 3462522015,
5998
+ 1591671054,
5999
+ 702138776,
6000
+ 2966460450,
6001
+ 3352799412,
6002
+ 1504918807,
6003
+ 783551873,
6004
+ 3082640443,
6005
+ 3233442989,
6006
+ 3988292384,
6007
+ 2596254646,
6008
+ 62317068,
6009
+ 1957810842,
6010
+ 3939845945,
6011
+ 2647816111,
6012
+ 81470997,
6013
+ 1943803523,
6014
+ 3814918930,
6015
+ 2489596804,
6016
+ 225274430,
6017
+ 2053790376,
6018
+ 3826175755,
6019
+ 2466906013,
6020
+ 167816743,
6021
+ 2097651377,
6022
+ 4027552580,
6023
+ 2265490386,
6024
+ 503444072,
6025
+ 1762050814,
6026
+ 4150417245,
6027
+ 2154129355,
6028
+ 426522225,
6029
+ 1852507879,
6030
+ 4275313526,
6031
+ 2312317920,
6032
+ 282753626,
6033
+ 1742555852,
6034
+ 4189708143,
6035
+ 2394877945,
6036
+ 397917763,
6037
+ 1622183637,
6038
+ 3604390888,
6039
+ 2714866558,
6040
+ 953729732,
6041
+ 1340076626,
6042
+ 3518719985,
6043
+ 2797360999,
6044
+ 1068828381,
6045
+ 1219638859,
6046
+ 3624741850,
6047
+ 2936675148,
6048
+ 906185462,
6049
+ 1090812512,
6050
+ 3747672003,
6051
+ 2825379669,
6052
+ 829329135,
6053
+ 1181335161,
6054
+ 3412177804,
6055
+ 3160834842,
6056
+ 628085408,
6057
+ 1382605366,
6058
+ 3423369109,
6059
+ 3138078467,
6060
+ 570562233,
6061
+ 1426400815,
6062
+ 3317316542,
6063
+ 2998733608,
6064
+ 733239954,
6065
+ 1555261956,
6066
+ 3268935591,
6067
+ 3050360625,
6068
+ 752459403,
6069
+ 1541320221,
6070
+ 2607071920,
6071
+ 3965973030,
6072
+ 1969922972,
6073
+ 40735498,
6074
+ 2617837225,
6075
+ 3943577151,
6076
+ 1913087877,
6077
+ 83908371,
6078
+ 2512341634,
6079
+ 3803740692,
6080
+ 2075208622,
6081
+ 213261112,
6082
+ 2463272603,
6083
+ 3855990285,
6084
+ 2094854071,
6085
+ 198958881,
6086
+ 2262029012,
6087
+ 4057260610,
6088
+ 1759359992,
6089
+ 534414190,
6090
+ 2176718541,
6091
+ 4139329115,
6092
+ 1873836001,
6093
+ 414664567,
6094
+ 2282248934,
6095
+ 4279200368,
6096
+ 1711684554,
6097
+ 285281116,
6098
+ 2405801727,
6099
+ 4167216745,
6100
+ 1634467795,
6101
+ 376229701,
6102
+ 2685067896,
6103
+ 3608007406,
6104
+ 1308918612,
6105
+ 956543938,
6106
+ 2808555105,
6107
+ 3495958263,
6108
+ 1231636301,
6109
+ 1047427035,
6110
+ 2932959818,
6111
+ 3654703836,
6112
+ 1088359270,
6113
+ 936918e3,
6114
+ 2847714899,
6115
+ 3736837829,
6116
+ 1202900863,
6117
+ 817233897,
6118
+ 3183342108,
6119
+ 3401237130,
6120
+ 1404277552,
6121
+ 615818150,
6122
+ 3134207493,
6123
+ 3453421203,
6124
+ 1423857449,
6125
+ 601450431,
6126
+ 3009837614,
6127
+ 3294710456,
6128
+ 1567103746,
6129
+ 711928724,
6130
+ 3020668471,
6131
+ 3272380065,
6132
+ 1510334235,
6133
+ 755167117
6134
+ ];
6135
+ if (typeof Int32Array !== "undefined") {
6136
+ CRC_TABLE = new Int32Array(CRC_TABLE);
6137
+ }
6138
+ function ensureBuffer(input) {
6139
+ if (Buffer2.isBuffer(input)) {
6140
+ return input;
6141
+ }
6142
+ var hasNewBufferAPI = typeof Buffer2.alloc === "function" && typeof Buffer2.from === "function";
6143
+ if (typeof input === "number") {
6144
+ return hasNewBufferAPI ? Buffer2.alloc(input) : new Buffer2(input);
6145
+ } else if (typeof input === "string") {
6146
+ return hasNewBufferAPI ? Buffer2.from(input) : new Buffer2(input);
6147
+ } else {
6148
+ throw new Error("input must be buffer, number, or string, received " + typeof input);
6149
+ }
6150
+ }
6151
+ function bufferizeInt(num) {
6152
+ var tmp = ensureBuffer(4);
6153
+ tmp.writeInt32BE(num, 0);
6154
+ return tmp;
6155
+ }
6156
+ function _crc32(buf, previous) {
6157
+ buf = ensureBuffer(buf);
6158
+ if (Buffer2.isBuffer(previous)) {
6159
+ previous = previous.readUInt32BE(0);
6160
+ }
6161
+ var crc = ~~previous ^ -1;
6162
+ for (var n = 0; n < buf.length; n++) {
6163
+ crc = CRC_TABLE[(crc ^ buf[n]) & 255] ^ crc >>> 8;
6164
+ }
6165
+ return crc ^ -1;
6166
+ }
6167
+ function crc322() {
6168
+ return bufferizeInt(_crc32.apply(null, arguments));
6169
+ }
6170
+ crc322.signed = function() {
6171
+ return _crc32.apply(null, arguments);
6172
+ };
6173
+ crc322.unsigned = function() {
6174
+ return _crc32.apply(null, arguments) >>> 0;
6175
+ };
6176
+ module2.exports = crc322;
6177
+ }
6178
+ });
6179
+
5873
6180
  // ../../node_modules/.pnpm/text-table@0.2.0/node_modules/text-table/index.js
5874
6181
  var require_text_table = __commonJS({
5875
6182
  "../../node_modules/.pnpm/text-table@0.2.0/node_modules/text-table/index.js"(exports, module2) {
@@ -9078,7 +9385,7 @@ module.exports = __toCommonJS(src_exports);
9078
9385
  var import_build_utils3 = require("@vercel/build-utils");
9079
9386
  var import_superstatic = __toESM(require_superstatic());
9080
9387
  var import_nft2 = require("@vercel/nft");
9081
- var import_async_sema2 = __toESM(require_lib());
9388
+ var import_async_sema3 = __toESM(require_lib());
9082
9389
  var import_escape_string_regexp3 = __toESM(require_escape_string_regexp());
9083
9390
  var import_find_up = __toESM(require_find_up());
9084
9391
  var import_fs_extra6 = __toESM(require_lib2());
@@ -9093,9 +9400,12 @@ var import_semver2 = __toESM(require_semver());
9093
9400
 
9094
9401
  // src/utils.ts
9095
9402
  var import_build_utils = require("@vercel/build-utils");
9403
+ var import_async_sema = __toESM(require_lib());
9404
+ var import_buffer_crc32 = __toESM(require_buffer_crc32());
9096
9405
  var import_fs_extra3 = __toESM(require_lib2());
9097
9406
  var import_path2 = __toESM(require("path"));
9098
9407
  var import_semver = __toESM(require_semver());
9408
+ var import_zlib2 = __toESM(require("zlib"));
9099
9409
  var import_url = __toESM(require("url"));
9100
9410
  var import_module = require("module");
9101
9411
  var import_escape_string_regexp = __toESM(require_escape_string_regexp());
@@ -9174,6 +9484,7 @@ var MIB = 1024 * KIB;
9174
9484
  var EDGE_FUNCTION_SIZE_LIMIT = 4 * MIB;
9175
9485
  var MAX_UNCOMPRESSED_LAMBDA_SIZE = 250 * MIB;
9176
9486
  var LAMBDA_RESERVED_UNCOMPRESSED_SIZE = 2.5 * MIB;
9487
+ var LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * KIB;
9177
9488
 
9178
9489
  // src/edge-function-source/get-edge-function-source.ts
9179
9490
  var import_zlib = __toESM(require("zlib"));
@@ -9582,7 +9893,7 @@ function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
9582
9893
  }
9583
9894
  return parentFilesMap;
9584
9895
  }
9585
- var collectTracedFiles = async (file, baseDir, lstatResults, lstatSema, reasons, files) => {
9896
+ var collectTracedFiles = (baseDir, lstatResults, lstatSema, reasons, files) => async (file) => {
9586
9897
  const reason = reasons.get(file);
9587
9898
  if (reason && reason.type.includes("initial")) {
9588
9899
  return;
@@ -9598,42 +9909,47 @@ var collectTracedFiles = async (file, baseDir, lstatResults, lstatSema, reasons,
9598
9909
  });
9599
9910
  };
9600
9911
  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
- };
9912
+ var compressBuffer = (buf) => {
9913
+ return new Promise((resolve, reject) => {
9914
+ import_zlib2.default.deflateRaw(
9915
+ buf,
9916
+ { level: import_zlib2.default.constants.Z_BEST_COMPRESSION },
9917
+ (err, compBuf) => {
9918
+ if (err)
9919
+ return reject(err);
9920
+ resolve(compBuf);
9631
9921
  }
9632
- lstatSema.release();
9633
- })
9634
- );
9922
+ );
9923
+ });
9924
+ };
9925
+ async function createPseudoLayer(files) {
9926
+ const pseudoLayer = {};
9927
+ let pseudoLayerBytes = 0;
9928
+ for (const fileName of Object.keys(files)) {
9929
+ const file = files[fileName];
9930
+ if ((0, import_build_utils.isSymbolicLink)(file.mode)) {
9931
+ const symlinkTarget = await import_fs_extra3.default.readlink(file.fsPath);
9932
+ pseudoLayer[fileName] = {
9933
+ file,
9934
+ isSymlink: true,
9935
+ symlinkTarget
9936
+ };
9937
+ } else {
9938
+ const origBuffer = await (0, import_build_utils.streamToBuffer)(file.toStream());
9939
+ const compBuffer = await compressBuffer(origBuffer);
9940
+ pseudoLayerBytes += compBuffer.byteLength;
9941
+ pseudoLayer[fileName] = {
9942
+ file,
9943
+ compBuffer,
9944
+ isSymlink: false,
9945
+ crc32: import_buffer_crc32.default.unsigned(origBuffer),
9946
+ uncompressedSize: origBuffer.byteLength
9947
+ };
9948
+ }
9949
+ }
9635
9950
  return { pseudoLayer, pseudoLayerBytes };
9636
9951
  }
9952
+ var createLambdaSema = new import_async_sema.Sema(1);
9637
9953
  async function createLambdaFromPseudoLayers({
9638
9954
  files: baseFiles,
9639
9955
  layers,
@@ -9641,6 +9957,7 @@ async function createLambdaFromPseudoLayers({
9641
9957
  nextVersion,
9642
9958
  ...lambdaOptions
9643
9959
  }) {
9960
+ await createLambdaSema.acquire();
9644
9961
  const files = {};
9645
9962
  const addedFiles = /* @__PURE__ */ new Set();
9646
9963
  for (const layer of layers) {
@@ -9661,6 +9978,7 @@ async function createLambdaFromPseudoLayers({
9661
9978
  files[fileName] = file;
9662
9979
  addedFiles.add(fileName);
9663
9980
  }
9981
+ createLambdaSema.release();
9664
9982
  return new import_build_utils.NodejsLambda({
9665
9983
  ...lambdaOptions,
9666
9984
  ...isStreaming ? {
@@ -10005,6 +10323,8 @@ async function getPageLambdaGroups({
10005
10323
  compressedPages,
10006
10324
  tracedPseudoLayer,
10007
10325
  initialPseudoLayer,
10326
+ initialPseudoLayerUncompressed,
10327
+ lambdaCompressedByteLimit,
10008
10328
  internalPages,
10009
10329
  pageExtensions
10010
10330
  }) {
@@ -10032,18 +10352,22 @@ async function getPageLambdaGroups({
10032
10352
  let matchingGroup = groups.find((group) => {
10033
10353
  const matches = group.maxDuration === opts.maxDuration && group.memory === opts.memory && group.isPrerenders === isPrerenderRoute;
10034
10354
  if (matches) {
10035
- let newTracedFilesUncompressedSize = group.pseudoLayerBytes;
10355
+ let newTracedFilesSize = group.pseudoLayerBytes;
10356
+ let newTracedFilesUncompressedSize = group.pseudoLayerUncompressedBytes;
10036
10357
  for (const newPage of newPages) {
10037
10358
  Object.keys(pageTraces[newPage] || {}).map((file) => {
10038
10359
  if (!group.pseudoLayer[file]) {
10039
10360
  const item = tracedPseudoLayer[file];
10361
+ newTracedFilesSize += item.compBuffer?.byteLength || 0;
10040
10362
  newTracedFilesUncompressedSize += item.uncompressedSize || 0;
10041
10363
  }
10042
10364
  });
10365
+ newTracedFilesSize += compressedPages[newPage].compBuffer.byteLength;
10043
10366
  newTracedFilesUncompressedSize += compressedPages[newPage].uncompressedSize;
10044
10367
  }
10045
10368
  const underUncompressedLimit = newTracedFilesUncompressedSize < MAX_UNCOMPRESSED_LAMBDA_SIZE - LAMBDA_RESERVED_UNCOMPRESSED_SIZE;
10046
- return underUncompressedLimit;
10369
+ const underCompressedLimit = newTracedFilesSize < lambdaCompressedByteLimit - LAMBDA_RESERVED_COMPRESSED_SIZE;
10370
+ return underUncompressedLimit && underCompressedLimit;
10047
10371
  }
10048
10372
  return false;
10049
10373
  });
@@ -10056,6 +10380,7 @@ async function getPageLambdaGroups({
10056
10380
  isPrerenders: isPrerenderRoute,
10057
10381
  isApiLambda: !!isApiPage(page),
10058
10382
  pseudoLayerBytes: initialPseudoLayer.pseudoLayerBytes,
10383
+ pseudoLayerUncompressedBytes: initialPseudoLayerUncompressed,
10059
10384
  pseudoLayer: Object.assign({}, initialPseudoLayer.pseudoLayer)
10060
10385
  };
10061
10386
  groups.push(newGroup);
@@ -10064,24 +10389,31 @@ async function getPageLambdaGroups({
10064
10389
  for (const newPage of newPages) {
10065
10390
  Object.keys(pageTraces[newPage] || {}).map((file) => {
10066
10391
  const pseudoItem = tracedPseudoLayer[file];
10392
+ const compressedSize = pseudoItem?.compBuffer?.byteLength || 0;
10067
10393
  if (!matchingGroup.pseudoLayer[file]) {
10068
10394
  matchingGroup.pseudoLayer[file] = pseudoItem;
10069
- matchingGroup.pseudoLayerBytes += pseudoItem.uncompressedSize || 0;
10395
+ matchingGroup.pseudoLayerBytes += compressedSize;
10396
+ matchingGroup.pseudoLayerUncompressedBytes += pseudoItem.uncompressedSize || 0;
10070
10397
  }
10071
10398
  });
10072
- matchingGroup.pseudoLayerBytes += compressedPages[newPage].uncompressedSize;
10399
+ matchingGroup.pseudoLayerBytes += compressedPages[newPage].compBuffer.byteLength;
10400
+ matchingGroup.pseudoLayerUncompressedBytes += compressedPages[newPage].uncompressedSize;
10073
10401
  }
10074
10402
  }
10075
10403
  return groups;
10076
10404
  }
10077
- var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compressedPages) => {
10405
+ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, pseudoLayerUncompressedBytes, compressedPages) => {
10078
10406
  const exceededLimitOutput = [];
10079
10407
  console.log(
10080
10408
  `Serverless Function's page${pages.length === 1 ? "" : "s"}: ${pages.join(
10081
10409
  ", "
10082
10410
  )}`
10083
10411
  );
10084
- exceededLimitOutput.push(["Large Dependencies", "Uncompressed size"]);
10412
+ exceededLimitOutput.push([
10413
+ "Large Dependencies",
10414
+ "Uncompressed size",
10415
+ "Compressed size"
10416
+ ]);
10085
10417
  const dependencies = {};
10086
10418
  for (const fileKey of Object.keys(pseudoLayer)) {
10087
10419
  if (!pseudoLayer[fileKey].isSymlink) {
@@ -10089,14 +10421,17 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10089
10421
  const depKey = fileKey.split("/").slice(0, 3).join("/");
10090
10422
  if (!dependencies[depKey]) {
10091
10423
  dependencies[depKey] = {
10424
+ compressed: 0,
10092
10425
  uncompressed: 0
10093
10426
  };
10094
10427
  }
10428
+ dependencies[depKey].compressed += fileItem.compBuffer.byteLength;
10095
10429
  dependencies[depKey].uncompressed += fileItem.uncompressedSize;
10096
10430
  }
10097
10431
  }
10098
10432
  for (const page of pages) {
10099
10433
  dependencies[`pages/${page}`] = {
10434
+ compressed: compressedPages[page].compBuffer.byteLength,
10100
10435
  uncompressed: compressedPages[page].uncompressedSize
10101
10436
  };
10102
10437
  }
@@ -10104,19 +10439,23 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10104
10439
  Object.keys(dependencies).sort((a, b) => {
10105
10440
  const aDep = dependencies[a];
10106
10441
  const bDep = dependencies[b];
10107
- if (aDep.uncompressed > bDep.uncompressed) {
10442
+ if (aDep.compressed > bDep.compressed) {
10108
10443
  return -1;
10109
10444
  }
10110
- if (aDep.uncompressed < bDep.uncompressed) {
10445
+ if (aDep.compressed < bDep.compressed) {
10111
10446
  return 1;
10112
10447
  }
10113
10448
  return 0;
10114
10449
  }).forEach((depKey) => {
10115
10450
  const dep = dependencies[depKey];
10116
- if (dep.uncompressed < 500 * KIB) {
10451
+ if (dep.compressed < 100 * KIB && dep.uncompressed < 500 * KIB) {
10117
10452
  return;
10118
10453
  }
10119
- exceededLimitOutput.push([depKey, prettyBytes(dep.uncompressed)]);
10454
+ exceededLimitOutput.push([
10455
+ depKey,
10456
+ prettyBytes(dep.uncompressed),
10457
+ prettyBytes(dep.compressed)
10458
+ ]);
10120
10459
  numLargeDependencies += 1;
10121
10460
  });
10122
10461
  if (numLargeDependencies === 0) {
@@ -10125,21 +10464,26 @@ var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerBytes, compress
10125
10464
  ]);
10126
10465
  }
10127
10466
  exceededLimitOutput.push([]);
10128
- exceededLimitOutput.push(["All dependencies", prettyBytes(pseudoLayerBytes)]);
10467
+ exceededLimitOutput.push([
10468
+ "All dependencies",
10469
+ prettyBytes(pseudoLayerUncompressedBytes),
10470
+ prettyBytes(pseudoLayerBytes)
10471
+ ]);
10129
10472
  console.log(
10130
10473
  (0, import_text_table.default)(exceededLimitOutput, {
10131
10474
  align: ["l", "r", "r"]
10132
10475
  })
10133
10476
  );
10134
10477
  };
10135
- var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10478
+ var detectLambdaLimitExceeding = async (lambdaGroups, compressedSizeLimit, compressedPages) => {
10479
+ const COMPRESSED_SIZE_LIMIT_CLOSE = compressedSizeLimit - 5 * MIB;
10136
10480
  const UNCOMPRESSED_SIZE_LIMIT_CLOSE = MAX_UNCOMPRESSED_LAMBDA_SIZE - 5 * MIB;
10137
10481
  let numExceededLimit = 0;
10138
10482
  let numCloseToLimit = 0;
10139
10483
  let loggedHeadInfo = false;
10140
10484
  const filteredGroups = lambdaGroups.filter((group) => {
10141
- const exceededLimit = group.pseudoLayerBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE;
10142
- const closeToLimit = group.pseudoLayerBytes > UNCOMPRESSED_SIZE_LIMIT_CLOSE;
10485
+ const exceededLimit = group.pseudoLayerBytes > compressedSizeLimit || group.pseudoLayerUncompressedBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE;
10486
+ const closeToLimit = group.pseudoLayerBytes > COMPRESSED_SIZE_LIMIT_CLOSE || group.pseudoLayerUncompressedBytes > UNCOMPRESSED_SIZE_LIMIT_CLOSE;
10143
10487
  if (closeToLimit || exceededLimit || (0, import_build_utils.getPlatformEnv)("BUILDER_DEBUG") || process.env.NEXT_DEBUG_FUNCTION_SIZE) {
10144
10488
  if (exceededLimit) {
10145
10489
  numExceededLimit += 1;
@@ -10155,6 +10499,8 @@ var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10155
10499
  if (numExceededLimit || numCloseToLimit) {
10156
10500
  console.log(
10157
10501
  `Warning: Max serverless function size of ${prettyBytes(
10502
+ compressedSizeLimit
10503
+ )} compressed or ${prettyBytes(
10158
10504
  MAX_UNCOMPRESSED_LAMBDA_SIZE
10159
10505
  )} uncompressed${numExceededLimit ? "" : " almost"} reached`
10160
10506
  );
@@ -10167,6 +10513,7 @@ var detectLambdaLimitExceeding = async (lambdaGroups, compressedPages) => {
10167
10513
  group.pages,
10168
10514
  group.pseudoLayer,
10169
10515
  group.pseudoLayerBytes,
10516
+ group.pseudoLayerUncompressedBytes,
10170
10517
  compressedPages
10171
10518
  );
10172
10519
  }
@@ -10654,13 +11001,13 @@ function normalizeEdgeFunctionPath(shortPath, appPathRoutesManifest) {
10654
11001
  if (shortPath.startsWith("app/") && (shortPath.endsWith("/page") || shortPath.endsWith("/route") || shortPath === "app/_not-found")) {
10655
11002
  const ogRoute = shortPath.replace(/^app\//, "/");
10656
11003
  shortPath = (appPathRoutesManifest[ogRoute] || shortPath.replace(/(^|\/)(page|route)$/, "")).replace(/^\//, "");
11004
+ if (!shortPath || shortPath === "/") {
11005
+ shortPath = "index";
11006
+ }
10657
11007
  }
10658
11008
  if (shortPath.startsWith("pages/")) {
10659
11009
  shortPath = shortPath.replace(/^pages\//, "");
10660
11010
  }
10661
- if (!shortPath || shortPath === "/") {
10662
- shortPath = "index";
10663
- }
10664
11011
  return shortPath;
10665
11012
  }
10666
11013
  async function getMiddlewareBundle({
@@ -11402,7 +11749,7 @@ var legacy_versions_default = [
11402
11749
  // src/server-build.ts
11403
11750
  var import_path4 = __toESM(require("path"));
11404
11751
  var import_semver3 = __toESM(require_semver());
11405
- var import_async_sema = __toESM(require_lib());
11752
+ var import_async_sema2 = __toESM(require_lib());
11406
11753
  var import_build_utils2 = require("@vercel/build-utils");
11407
11754
  var import_nft = require("@vercel/nft");
11408
11755
  var import_resolve_from = __toESM(require_resolve_from());
@@ -11414,7 +11761,7 @@ var CORRECT_MIDDLEWARE_ORDER_VERSION = "v12.1.7-canary.29";
11414
11761
  var NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = "v12.1.7-canary.33";
11415
11762
  var EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = "v12.2.0";
11416
11763
  var CORRECTED_MANIFESTS_VERSION = "v12.2.0";
11417
- var BUNDLED_SERVER_NEXT_VERSION = "13.4.20-canary.26";
11764
+ var BUNDLED_SERVER_NEXT_VERSION = "v13.5.4";
11418
11765
  var BUNDLED_SERVER_NEXT_PATH = "next/dist/compiled/next-server/server.runtime.prod.js";
11419
11766
  async function serverBuild({
11420
11767
  dynamicPages,
@@ -11454,6 +11801,7 @@ async function serverBuild({
11454
11801
  omittedPrerenderRoutes,
11455
11802
  trailingSlashRedirects,
11456
11803
  isCorrectLocaleAPIRoutes,
11804
+ lambdaCompressedByteLimit,
11457
11805
  requiredServerFilesManifest,
11458
11806
  variantsManifest
11459
11807
  }) {
@@ -11521,7 +11869,7 @@ async function serverBuild({
11521
11869
  if (!hasStatic500 && i18n) {
11522
11870
  hasStatic500 = !!staticPages[import_path4.default.posix.join(entryDirectory, i18n.defaultLocale, "500")];
11523
11871
  }
11524
- const lstatSema = new import_async_sema.Sema(25);
11872
+ const lstatSema = new import_async_sema2.Sema(25);
11525
11873
  const lstatResults = {};
11526
11874
  const nonLambdaSsgPages = /* @__PURE__ */ new Set();
11527
11875
  Object.keys(prerenderManifest.staticRoutes).forEach((route) => {
@@ -11646,23 +11994,18 @@ async function serverBuild({
11646
11994
  }
11647
11995
  (0, import_build_utils2.debug)("collecting initial Next.js server files");
11648
11996
  await Promise.all(
11649
- initialFileList.map(async (file) => {
11650
- await collectTracedFiles(
11651
- file,
11997
+ initialFileList.map(
11998
+ collectTracedFiles(
11652
11999
  baseDir,
11653
12000
  lstatResults,
11654
12001
  lstatSema,
11655
12002
  initialFileReasons,
11656
12003
  initialTracedFiles
11657
- );
11658
- })
12004
+ )
12005
+ )
11659
12006
  );
11660
12007
  (0, import_build_utils2.debug)("creating initial pseudo layer");
11661
- const initialPseudoLayer = await createPseudoLayer({
11662
- files: initialTracedFiles,
11663
- lstatResults,
11664
- lstatSema
11665
- });
12008
+ const initialPseudoLayer = await createPseudoLayer(initialTracedFiles);
11666
12009
  console.timeEnd(initialTracingLabel);
11667
12010
  const lambdaCreationLabel = "Created all serverless functions in";
11668
12011
  console.time(lambdaCreationLabel);
@@ -11670,13 +12013,13 @@ async function serverBuild({
11670
12013
  const nonApiPages = [];
11671
12014
  const appRouterPages = [];
11672
12015
  const appRouteHandlers = [];
11673
- for (const page of lambdaPageKeys) {
12016
+ lambdaPageKeys.forEach((page) => {
11674
12017
  if (internalPages.includes(page) && page !== "404.js" && !(page === "_error.js" && !(static404Page || lambdaPages["404.js"]))) {
11675
- continue;
12018
+ return;
11676
12019
  }
11677
12020
  const pathname = page.replace(/\.js$/, "");
11678
12021
  if (nonLambdaSsgPages.has(pathname)) {
11679
- continue;
12022
+ return;
11680
12023
  }
11681
12024
  const normalizedPathname = normalizePage(pathname);
11682
12025
  if (isDynamicRoute(normalizedPathname)) {
@@ -11693,7 +12036,7 @@ async function serverBuild({
11693
12036
  } else {
11694
12037
  nonApiPages.push(page);
11695
12038
  }
11696
- }
12039
+ });
11697
12040
  const requiredFiles = {};
11698
12041
  requiredFiles[import_path4.default.relative(baseDir, nextServerFile)] = new import_build_utils2.FileFsRef({
11699
12042
  mode: (await import_fs_extra5.default.lstat(nextServerFile)).mode,
@@ -11759,28 +12102,33 @@ async function serverBuild({
11759
12102
  });
11760
12103
  })
11761
12104
  );
11762
- const requiredFilesLayer = await createPseudoLayer({
11763
- files: requiredFiles,
11764
- lstatResults,
11765
- lstatSema
11766
- });
12105
+ const requiredFilesLayer = await createPseudoLayer(requiredFiles);
11767
12106
  Object.assign(
11768
12107
  initialPseudoLayer.pseudoLayer,
11769
12108
  requiredFilesLayer.pseudoLayer
11770
12109
  );
11771
12110
  initialPseudoLayer.pseudoLayerBytes += requiredFilesLayer.pseudoLayerBytes;
12111
+ const uncompressedInitialSize = Object.keys(
12112
+ initialPseudoLayer.pseudoLayer
12113
+ ).reduce((prev, cur) => {
12114
+ const file = initialPseudoLayer.pseudoLayer[cur];
12115
+ return prev + file.uncompressedSize || 0;
12116
+ }, 0);
11772
12117
  (0, import_build_utils2.debug)(
11773
12118
  JSON.stringify(
11774
12119
  {
11775
- initializeSizeUncompressed: initialPseudoLayer.pseudoLayerBytes
12120
+ uncompressedInitialSize,
12121
+ compressedInitialSize: initialPseudoLayer.pseudoLayerBytes
11776
12122
  },
11777
12123
  null,
11778
12124
  2
11779
12125
  )
11780
12126
  );
11781
- if (initialPseudoLayer.pseudoLayerBytes > MAX_UNCOMPRESSED_LAMBDA_SIZE) {
12127
+ if (initialPseudoLayer.pseudoLayerBytes > lambdaCompressedByteLimit || uncompressedInitialSize > MAX_UNCOMPRESSED_LAMBDA_SIZE) {
11782
12128
  console.log(
11783
12129
  `Warning: Max serverless function size of ${(0, import_pretty_bytes3.default)(
12130
+ lambdaCompressedByteLimit
12131
+ )} compressed or ${(0, import_pretty_bytes3.default)(
11784
12132
  MAX_UNCOMPRESSED_LAMBDA_SIZE
11785
12133
  )} uncompressed reached`
11786
12134
  );
@@ -11788,10 +12136,11 @@ async function serverBuild({
11788
12136
  [],
11789
12137
  initialPseudoLayer.pseudoLayer,
11790
12138
  initialPseudoLayer.pseudoLayerBytes,
12139
+ uncompressedInitialSize,
11791
12140
  {}
11792
12141
  );
11793
12142
  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`,
12143
+ message: `Required files read using Node.js fs library and node_modules exceed max lambda size of ${lambdaCompressedByteLimit} bytes`,
11795
12144
  code: "NEXT_REQUIRED_FILES_LIMIT",
11796
12145
  link: "https://vercel.com/docs/platform/limits#serverless-function-size"
11797
12146
  });
@@ -11842,22 +12191,17 @@ async function serverBuild({
11842
12191
  }
11843
12192
  return originalPagePath;
11844
12193
  };
11845
- const getBuildTraceFile = (page) => pageBuildTraces[page + ".nft.json"] || appBuildTraces[page + ".nft.json"];
12194
+ const getBuildTraceFile = (page) => {
12195
+ return pageBuildTraces[page + ".nft.json"] || appBuildTraces[page + ".nft.json"];
12196
+ };
11846
12197
  const pathsToTrace = mergedPageKeys.map((page) => {
11847
- const originalPagePath = getOriginalPagePath(page);
11848
- const pageBuildTrace = getBuildTraceFile(originalPagePath);
11849
- if (!pageBuildTrace) {
12198
+ if (!getBuildTraceFile(page)) {
11850
12199
  return lambdaPages[page].fsPath;
11851
12200
  }
11852
12201
  }).filter(Boolean);
11853
12202
  let traceResult;
11854
12203
  let parentFilesMap;
11855
12204
  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
12205
  traceResult = await (0, import_nft.nodeFileTrace)(pathsToTrace, {
11862
12206
  base: baseDir,
11863
12207
  cache: traceCache,
@@ -11923,37 +12267,28 @@ async function serverBuild({
11923
12267
  }
11924
12268
  reasons = traceResult?.reasons || /* @__PURE__ */ new Map();
11925
12269
  }
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,
12270
+ await Promise.all(
12271
+ fileList.map(
12272
+ collectTracedFiles(
11939
12273
  baseDir,
11940
12274
  lstatResults,
11941
12275
  lstatSema,
11942
12276
  reasons,
11943
12277
  tracedFiles
11944
- );
11945
- })
11946
- ]);
12278
+ )
12279
+ )
12280
+ );
11947
12281
  pageTraces[page] = tracedFiles;
12282
+ compressedPages[page] = (await createPseudoLayer({
12283
+ [page]: lambdaPages[page]
12284
+ })).pseudoLayer[page];
11948
12285
  }
11949
- const tracedPseudoLayer = await createPseudoLayer({
11950
- files: mergedPageKeys.reduce((prev, page) => {
12286
+ const tracedPseudoLayer = await createPseudoLayer(
12287
+ mergedPageKeys.reduce((prev, page) => {
11951
12288
  Object.assign(prev, pageTraces[page]);
11952
12289
  return prev;
11953
- }, {}),
11954
- lstatResults,
11955
- lstatSema
11956
- });
12290
+ }, {})
12291
+ );
11957
12292
  const pageExtensions = requiredServerFilesManifest.config?.pageExtensions;
11958
12293
  const pageLambdaGroups = await getPageLambdaGroups({
11959
12294
  entryPath: projectDir,
@@ -11965,6 +12300,8 @@ async function serverBuild({
11965
12300
  compressedPages,
11966
12301
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11967
12302
  initialPseudoLayer,
12303
+ lambdaCompressedByteLimit,
12304
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11968
12305
  internalPages,
11969
12306
  pageExtensions
11970
12307
  });
@@ -11981,6 +12318,8 @@ async function serverBuild({
11981
12318
  compressedPages,
11982
12319
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11983
12320
  initialPseudoLayer,
12321
+ lambdaCompressedByteLimit,
12322
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11984
12323
  internalPages,
11985
12324
  pageExtensions
11986
12325
  });
@@ -11994,6 +12333,8 @@ async function serverBuild({
11994
12333
  compressedPages,
11995
12334
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
11996
12335
  initialPseudoLayer,
12336
+ lambdaCompressedByteLimit,
12337
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
11997
12338
  internalPages,
11998
12339
  pageExtensions
11999
12340
  });
@@ -12020,6 +12361,8 @@ async function serverBuild({
12020
12361
  compressedPages,
12021
12362
  tracedPseudoLayer: tracedPseudoLayer.pseudoLayer,
12022
12363
  initialPseudoLayer,
12364
+ initialPseudoLayerUncompressed: uncompressedInitialSize,
12365
+ lambdaCompressedByteLimit,
12023
12366
  internalPages,
12024
12367
  pageExtensions
12025
12368
  });
@@ -12032,23 +12375,27 @@ async function serverBuild({
12032
12375
  apiLambdaGroups: apiLambdaGroups.map((group) => ({
12033
12376
  pages: group.pages,
12034
12377
  isPrerender: group.isPrerenders,
12035
- pseudoLayerBytes: group.pseudoLayerBytes
12378
+ pseudoLayerBytes: group.pseudoLayerBytes,
12379
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12036
12380
  })),
12037
12381
  pageLambdaGroups: pageLambdaGroups.map((group) => ({
12038
12382
  pages: group.pages,
12039
12383
  isPrerender: group.isPrerenders,
12040
- pseudoLayerBytes: group.pseudoLayerBytes
12384
+ pseudoLayerBytes: group.pseudoLayerBytes,
12385
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12041
12386
  })),
12042
12387
  appRouterLambdaGroups: appRouterLambdaGroups.map((group) => ({
12043
12388
  pages: group.pages,
12044
12389
  isPrerender: group.isPrerenders,
12045
- pseudoLayerBytes: group.pseudoLayerBytes
12390
+ pseudoLayerBytes: group.pseudoLayerBytes,
12391
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12046
12392
  })),
12047
12393
  appRouteHandlersLambdaGroups: appRouteHandlersLambdaGroups.map(
12048
12394
  (group) => ({
12049
12395
  pages: group.pages,
12050
12396
  isPrerender: group.isPrerenders,
12051
- pseudoLayerBytes: group.pseudoLayerBytes
12397
+ pseudoLayerBytes: group.pseudoLayerBytes,
12398
+ uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
12052
12399
  })
12053
12400
  ),
12054
12401
  nextServerLayerSize: initialPseudoLayer.pseudoLayerBytes
@@ -12063,121 +12410,118 @@ async function serverBuild({
12063
12410
  ...apiLambdaGroups,
12064
12411
  ...appRouteHandlersLambdaGroups
12065
12412
  ];
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)
12413
+ await detectLambdaLimitExceeding(
12414
+ combinedGroups,
12415
+ lambdaCompressedByteLimit,
12416
+ compressedPages
12417
+ );
12418
+ for (const group of combinedGroups) {
12419
+ const groupPageFiles = {};
12420
+ for (const page of [...group.pages, ...internalPages]) {
12421
+ const pageFileName = import_path4.default.normalize(
12422
+ import_path4.default.relative(baseDir, lambdaPages[page].fsPath)
12423
+ );
12424
+ groupPageFiles[pageFileName] = compressedPages[page];
12425
+ }
12426
+ const updatedManifestFiles = {};
12427
+ if (isCorrectManifests) {
12428
+ for (const manifest of [
12429
+ "routes-manifest.json",
12430
+ "server/pages-manifest.json"
12431
+ ]) {
12432
+ const fsPath = import_path4.default.join(entryPath, outputDirectory, manifest);
12433
+ const relativePath = import_path4.default.relative(baseDir, fsPath);
12434
+ delete group.pseudoLayer[relativePath];
12435
+ const manifestData = await import_fs_extra5.default.readJSON(fsPath);
12436
+ const normalizedPages = new Set(
12437
+ group.pages.map((page) => {
12438
+ page = `/${page.replace(/\.js$/, "")}`;
12439
+ if (page === "/index")
12440
+ page = "/";
12441
+ return page;
12442
+ })
12073
12443
  );
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
- }
12444
+ switch (manifest) {
12445
+ case "routes-manifest.json": {
12446
+ const filterItem = (item) => normalizedPages.has(item.page);
12447
+ manifestData.dynamicRoutes = manifestData.dynamicRoutes?.filter(filterItem);
12448
+ manifestData.staticRoutes = manifestData.staticRoutes?.filter(filterItem);
12449
+ break;
12450
+ }
12451
+ case "server/pages-manifest.json": {
12452
+ for (const key of Object.keys(manifestData)) {
12453
+ if (isDynamicRoute(key) && !normalizedPages.has(key)) {
12454
+ delete manifestData[key];
12106
12455
  }
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
12456
  }
12457
+ break;
12458
+ }
12459
+ default: {
12460
+ throw new import_build_utils2.NowBuildError({
12461
+ message: `Unexpected manifest value ${manifest}, please contact support if this continues`,
12462
+ code: "NEXT_MANIFEST_INVARIANT"
12463
+ });
12115
12464
  }
12116
- updatedManifestFiles[relativePath] = new import_build_utils2.FileBlob({
12117
- contentType: "application/json",
12118
- data: JSON.stringify(manifestData)
12119
- });
12120
12465
  }
12466
+ updatedManifestFiles[relativePath] = new import_build_utils2.FileBlob({
12467
+ contentType: "application/json",
12468
+ data: JSON.stringify(manifestData)
12469
+ });
12121
12470
  }
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;
12471
+ }
12472
+ const launcherFiles = {
12473
+ [import_path4.default.join(import_path4.default.relative(baseDir, projectDir), "___next_launcher.cjs")]: new import_build_utils2.FileBlob({ data: group.isAppRouter ? appLauncher : launcher })
12474
+ };
12475
+ const operationType = getOperationType({ group, prerenderManifest });
12476
+ const lambda = await createLambdaFromPseudoLayers({
12477
+ files: {
12478
+ ...launcherFiles,
12479
+ ...updatedManifestFiles
12480
+ },
12481
+ layers: [group.pseudoLayer, groupPageFiles],
12482
+ handler: import_path4.default.join(
12483
+ import_path4.default.relative(baseDir, projectDir),
12484
+ "___next_launcher.cjs"
12485
+ ),
12486
+ operationType,
12487
+ memory: group.memory,
12488
+ runtime: nodeVersion.runtime,
12489
+ maxDuration: group.maxDuration,
12490
+ isStreaming: group.isStreaming,
12491
+ nextVersion
12492
+ });
12493
+ for (const page of group.pages) {
12494
+ const pageNoExt = page.replace(/\.js$/, "");
12495
+ let isPrerender = prerenderRoutes.has(
12496
+ import_path4.default.join("/", pageNoExt === "index" ? "" : pageNoExt)
12497
+ );
12498
+ if (!isPrerender && routesManifest?.i18n) {
12499
+ isPrerender = routesManifest.i18n.locales.some((locale) => {
12500
+ return prerenderRoutes.has(
12501
+ import_path4.default.join("/", locale, pageNoExt === "index" ? "" : pageNoExt)
12502
+ );
12503
+ });
12504
+ }
12505
+ const outputName = normalizeIndexOutput(
12506
+ import_path4.default.posix.join(entryDirectory, pageNoExt),
12507
+ true
12508
+ );
12509
+ if (i18n && !isPrerender && !group.isAppRouter && (!isCorrectLocaleAPIRoutes || !(pageNoExt === "api" || pageNoExt.startsWith("api/")))) {
12510
+ for (const locale of i18n.locales) {
12511
+ lambdas[normalizeIndexOutput(
12512
+ import_path4.default.posix.join(
12513
+ entryDirectory,
12514
+ locale,
12515
+ pageNoExt === "index" ? "" : pageNoExt
12516
+ ),
12517
+ true
12518
+ )] = lambda;
12177
12519
  }
12520
+ } else {
12521
+ lambdas[outputName] = lambda;
12178
12522
  }
12179
- })
12180
- );
12523
+ }
12524
+ }
12181
12525
  console.timeEnd(lambdaCreationLabel);
12182
12526
  }
12183
12527
  const prerenderRoute = onPrerenderRoute({
@@ -13955,8 +14299,6 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13955
14299
  let tracedPseudoLayer;
13956
14300
  const apiPages = [];
13957
14301
  const nonApiPages = [];
13958
- const lstatSema = new import_async_sema2.Sema(25);
13959
- const lstatResults = {};
13960
14302
  for (const page of pageKeys) {
13961
14303
  const pagePath = pages[page].fsPath;
13962
14304
  const route = `/${page.replace(/\.js$/, "")}`;
@@ -13968,11 +14310,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13968
14310
  nonApiPages.push(page);
13969
14311
  }
13970
14312
  compressedPages[page] = (await createPseudoLayer({
13971
- files: {
13972
- [page]: pages[page]
13973
- },
13974
- lstatResults,
13975
- lstatSema
14313
+ [page]: pages[page]
13976
14314
  })).pseudoLayer[page];
13977
14315
  }
13978
14316
  const mergedPageKeys = [...nonApiPages, ...apiPages];
@@ -13983,6 +14321,8 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
13983
14321
  console.time(tracingLabel);
13984
14322
  }
13985
14323
  const nftCache = /* @__PURE__ */ Object.create(null);
14324
+ const lstatSema = new import_async_sema3.Sema(25);
14325
+ const lstatResults = {};
13986
14326
  const pathsToTrace = mergedPageKeys.map((page) => pages[page].fsPath);
13987
14327
  const result = await (0, import_nft2.nodeFileTrace)(pathsToTrace, {
13988
14328
  base: baseDir,
@@ -14006,16 +14346,15 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
14006
14346
  }
14007
14347
  const reasons = result.reasons;
14008
14348
  await Promise.all(
14009
- Array.from(fileList).map(async (file) => {
14010
- await collectTracedFiles(
14011
- file,
14349
+ Array.from(fileList).map(
14350
+ collectTracedFiles(
14012
14351
  baseDir,
14013
14352
  lstatResults,
14014
14353
  lstatSema,
14015
14354
  reasons,
14016
14355
  tracedFiles
14017
- );
14018
- })
14356
+ )
14357
+ )
14019
14358
  );
14020
14359
  pageTraces[page] = tracedFiles;
14021
14360
  }
@@ -14026,14 +14365,12 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
14026
14365
  if (hasLambdas) {
14027
14366
  console.time(zippingLabel);
14028
14367
  }
14029
- tracedPseudoLayer = await createPseudoLayer({
14030
- files: mergedPageKeys.reduce((prev, page) => {
14368
+ tracedPseudoLayer = await createPseudoLayer(
14369
+ mergedPageKeys.reduce((prev, page) => {
14031
14370
  Object.assign(prev, pageTraces[page]);
14032
14371
  return prev;
14033
- }, {}),
14034
- lstatResults,
14035
- lstatSema
14036
- });
14372
+ }, {})
14373
+ );
14037
14374
  if (hasLambdas) {
14038
14375
  console.timeEnd(zippingLabel);
14039
14376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.0.9",
3
+ "version": "4.0.10",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",