@vercel/next 4.4.2 → 4.4.5

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 +613 -73
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -400,6 +400,396 @@ var require_dist = __commonJS({
400
400
  }
401
401
  });
402
402
 
403
+ // ../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js
404
+ var require_dist2 = __commonJS({
405
+ "../../node_modules/.pnpm/path-to-regexp@6.3.0/node_modules/path-to-regexp/dist/index.js"(exports) {
406
+ "use strict";
407
+ Object.defineProperty(exports, "__esModule", { value: true });
408
+ exports.pathToRegexp = exports.tokensToRegexp = exports.regexpToFunction = exports.match = exports.tokensToFunction = exports.compile = exports.parse = void 0;
409
+ function lexer(str) {
410
+ var tokens = [];
411
+ var i = 0;
412
+ while (i < str.length) {
413
+ var char = str[i];
414
+ if (char === "*" || char === "+" || char === "?") {
415
+ tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
416
+ continue;
417
+ }
418
+ if (char === "\\") {
419
+ tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
420
+ continue;
421
+ }
422
+ if (char === "{") {
423
+ tokens.push({ type: "OPEN", index: i, value: str[i++] });
424
+ continue;
425
+ }
426
+ if (char === "}") {
427
+ tokens.push({ type: "CLOSE", index: i, value: str[i++] });
428
+ continue;
429
+ }
430
+ if (char === ":") {
431
+ var name = "";
432
+ var j = i + 1;
433
+ while (j < str.length) {
434
+ var code = str.charCodeAt(j);
435
+ if (
436
+ // `0-9`
437
+ code >= 48 && code <= 57 || // `A-Z`
438
+ code >= 65 && code <= 90 || // `a-z`
439
+ code >= 97 && code <= 122 || // `_`
440
+ code === 95
441
+ ) {
442
+ name += str[j++];
443
+ continue;
444
+ }
445
+ break;
446
+ }
447
+ if (!name)
448
+ throw new TypeError("Missing parameter name at ".concat(i));
449
+ tokens.push({ type: "NAME", index: i, value: name });
450
+ i = j;
451
+ continue;
452
+ }
453
+ if (char === "(") {
454
+ var count = 1;
455
+ var pattern = "";
456
+ var j = i + 1;
457
+ if (str[j] === "?") {
458
+ throw new TypeError('Pattern cannot start with "?" at '.concat(j));
459
+ }
460
+ while (j < str.length) {
461
+ if (str[j] === "\\") {
462
+ pattern += str[j++] + str[j++];
463
+ continue;
464
+ }
465
+ if (str[j] === ")") {
466
+ count--;
467
+ if (count === 0) {
468
+ j++;
469
+ break;
470
+ }
471
+ } else if (str[j] === "(") {
472
+ count++;
473
+ if (str[j + 1] !== "?") {
474
+ throw new TypeError("Capturing groups are not allowed at ".concat(j));
475
+ }
476
+ }
477
+ pattern += str[j++];
478
+ }
479
+ if (count)
480
+ throw new TypeError("Unbalanced pattern at ".concat(i));
481
+ if (!pattern)
482
+ throw new TypeError("Missing pattern at ".concat(i));
483
+ tokens.push({ type: "PATTERN", index: i, value: pattern });
484
+ i = j;
485
+ continue;
486
+ }
487
+ tokens.push({ type: "CHAR", index: i, value: str[i++] });
488
+ }
489
+ tokens.push({ type: "END", index: i, value: "" });
490
+ return tokens;
491
+ }
492
+ function parse(str, options) {
493
+ if (options === void 0) {
494
+ options = {};
495
+ }
496
+ var tokens = lexer(str);
497
+ var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
498
+ var result = [];
499
+ var key = 0;
500
+ var i = 0;
501
+ var path5 = "";
502
+ var tryConsume = function(type) {
503
+ if (i < tokens.length && tokens[i].type === type)
504
+ return tokens[i++].value;
505
+ };
506
+ var mustConsume = function(type) {
507
+ var value2 = tryConsume(type);
508
+ if (value2 !== void 0)
509
+ return value2;
510
+ var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
511
+ throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
512
+ };
513
+ var consumeText = function() {
514
+ var result2 = "";
515
+ var value2;
516
+ while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
517
+ result2 += value2;
518
+ }
519
+ return result2;
520
+ };
521
+ var isSafe = function(value2) {
522
+ for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
523
+ var char2 = delimiter_1[_i];
524
+ if (value2.indexOf(char2) > -1)
525
+ return true;
526
+ }
527
+ return false;
528
+ };
529
+ var safePattern = function(prefix2) {
530
+ var prev = result[result.length - 1];
531
+ var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
532
+ if (prev && !prevText) {
533
+ throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
534
+ }
535
+ if (!prevText || isSafe(prevText))
536
+ return "[^".concat(escapeString(delimiter), "]+?");
537
+ return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
538
+ };
539
+ while (i < tokens.length) {
540
+ var char = tryConsume("CHAR");
541
+ var name = tryConsume("NAME");
542
+ var pattern = tryConsume("PATTERN");
543
+ if (name || pattern) {
544
+ var prefix = char || "";
545
+ if (prefixes.indexOf(prefix) === -1) {
546
+ path5 += prefix;
547
+ prefix = "";
548
+ }
549
+ if (path5) {
550
+ result.push(path5);
551
+ path5 = "";
552
+ }
553
+ result.push({
554
+ name: name || key++,
555
+ prefix,
556
+ suffix: "",
557
+ pattern: pattern || safePattern(prefix),
558
+ modifier: tryConsume("MODIFIER") || ""
559
+ });
560
+ continue;
561
+ }
562
+ var value = char || tryConsume("ESCAPED_CHAR");
563
+ if (value) {
564
+ path5 += value;
565
+ continue;
566
+ }
567
+ if (path5) {
568
+ result.push(path5);
569
+ path5 = "";
570
+ }
571
+ var open = tryConsume("OPEN");
572
+ if (open) {
573
+ var prefix = consumeText();
574
+ var name_1 = tryConsume("NAME") || "";
575
+ var pattern_1 = tryConsume("PATTERN") || "";
576
+ var suffix = consumeText();
577
+ mustConsume("CLOSE");
578
+ result.push({
579
+ name: name_1 || (pattern_1 ? key++ : ""),
580
+ pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
581
+ prefix,
582
+ suffix,
583
+ modifier: tryConsume("MODIFIER") || ""
584
+ });
585
+ continue;
586
+ }
587
+ mustConsume("END");
588
+ }
589
+ return result;
590
+ }
591
+ exports.parse = parse;
592
+ function compile(str, options) {
593
+ return tokensToFunction(parse(str, options), options);
594
+ }
595
+ exports.compile = compile;
596
+ function tokensToFunction(tokens, options) {
597
+ if (options === void 0) {
598
+ options = {};
599
+ }
600
+ var reFlags = flags(options);
601
+ var _a = options.encode, encode = _a === void 0 ? function(x) {
602
+ return x;
603
+ } : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
604
+ var matches = tokens.map(function(token) {
605
+ if (typeof token === "object") {
606
+ return new RegExp("^(?:".concat(token.pattern, ")$"), reFlags);
607
+ }
608
+ });
609
+ return function(data) {
610
+ var path5 = "";
611
+ for (var i = 0; i < tokens.length; i++) {
612
+ var token = tokens[i];
613
+ if (typeof token === "string") {
614
+ path5 += token;
615
+ continue;
616
+ }
617
+ var value = data ? data[token.name] : void 0;
618
+ var optional = token.modifier === "?" || token.modifier === "*";
619
+ var repeat = token.modifier === "*" || token.modifier === "+";
620
+ if (Array.isArray(value)) {
621
+ if (!repeat) {
622
+ throw new TypeError('Expected "'.concat(token.name, '" to not repeat, but got an array'));
623
+ }
624
+ if (value.length === 0) {
625
+ if (optional)
626
+ continue;
627
+ throw new TypeError('Expected "'.concat(token.name, '" to not be empty'));
628
+ }
629
+ for (var j = 0; j < value.length; j++) {
630
+ var segment = encode(value[j], token);
631
+ if (validate && !matches[i].test(segment)) {
632
+ throw new TypeError('Expected all "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
633
+ }
634
+ path5 += token.prefix + segment + token.suffix;
635
+ }
636
+ continue;
637
+ }
638
+ if (typeof value === "string" || typeof value === "number") {
639
+ var segment = encode(String(value), token);
640
+ if (validate && !matches[i].test(segment)) {
641
+ throw new TypeError('Expected "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
642
+ }
643
+ path5 += token.prefix + segment + token.suffix;
644
+ continue;
645
+ }
646
+ if (optional)
647
+ continue;
648
+ var typeOfMessage = repeat ? "an array" : "a string";
649
+ throw new TypeError('Expected "'.concat(token.name, '" to be ').concat(typeOfMessage));
650
+ }
651
+ return path5;
652
+ };
653
+ }
654
+ exports.tokensToFunction = tokensToFunction;
655
+ function match(str, options) {
656
+ var keys = [];
657
+ var re = pathToRegexp(str, keys, options);
658
+ return regexpToFunction(re, keys, options);
659
+ }
660
+ exports.match = match;
661
+ function regexpToFunction(re, keys, options) {
662
+ if (options === void 0) {
663
+ options = {};
664
+ }
665
+ var _a = options.decode, decode = _a === void 0 ? function(x) {
666
+ return x;
667
+ } : _a;
668
+ return function(pathname) {
669
+ var m = re.exec(pathname);
670
+ if (!m)
671
+ return false;
672
+ var path5 = m[0], index = m.index;
673
+ var params = /* @__PURE__ */ Object.create(null);
674
+ var _loop_1 = function(i2) {
675
+ if (m[i2] === void 0)
676
+ return "continue";
677
+ var key = keys[i2 - 1];
678
+ if (key.modifier === "*" || key.modifier === "+") {
679
+ params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
680
+ return decode(value, key);
681
+ });
682
+ } else {
683
+ params[key.name] = decode(m[i2], key);
684
+ }
685
+ };
686
+ for (var i = 1; i < m.length; i++) {
687
+ _loop_1(i);
688
+ }
689
+ return { path: path5, index, params };
690
+ };
691
+ }
692
+ exports.regexpToFunction = regexpToFunction;
693
+ function escapeString(str) {
694
+ return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
695
+ }
696
+ function flags(options) {
697
+ return options && options.sensitive ? "" : "i";
698
+ }
699
+ function regexpToRegexp(path5, keys) {
700
+ if (!keys)
701
+ return path5;
702
+ var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
703
+ var index = 0;
704
+ var execResult = groupsRegex.exec(path5.source);
705
+ while (execResult) {
706
+ keys.push({
707
+ // Use parenthesized substring match if available, index otherwise
708
+ name: execResult[1] || index++,
709
+ prefix: "",
710
+ suffix: "",
711
+ modifier: "",
712
+ pattern: ""
713
+ });
714
+ execResult = groupsRegex.exec(path5.source);
715
+ }
716
+ return path5;
717
+ }
718
+ function arrayToRegexp(paths, keys, options) {
719
+ var parts = paths.map(function(path5) {
720
+ return pathToRegexp(path5, keys, options).source;
721
+ });
722
+ return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
723
+ }
724
+ function stringToRegexp(path5, keys, options) {
725
+ return tokensToRegexp(parse(path5, options), keys, options);
726
+ }
727
+ function tokensToRegexp(tokens, keys, options) {
728
+ if (options === void 0) {
729
+ options = {};
730
+ }
731
+ var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
732
+ return x;
733
+ } : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
734
+ var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
735
+ var delimiterRe = "[".concat(escapeString(delimiter), "]");
736
+ var route = start ? "^" : "";
737
+ for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
738
+ var token = tokens_1[_i];
739
+ if (typeof token === "string") {
740
+ route += escapeString(encode(token));
741
+ } else {
742
+ var prefix = escapeString(encode(token.prefix));
743
+ var suffix = escapeString(encode(token.suffix));
744
+ if (token.pattern) {
745
+ if (keys)
746
+ keys.push(token);
747
+ if (prefix || suffix) {
748
+ if (token.modifier === "+" || token.modifier === "*") {
749
+ var mod = token.modifier === "*" ? "?" : "";
750
+ route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
751
+ } else {
752
+ route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
753
+ }
754
+ } else {
755
+ if (token.modifier === "+" || token.modifier === "*") {
756
+ throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
757
+ }
758
+ route += "(".concat(token.pattern, ")").concat(token.modifier);
759
+ }
760
+ } else {
761
+ route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
762
+ }
763
+ }
764
+ }
765
+ if (end) {
766
+ if (!strict)
767
+ route += "".concat(delimiterRe, "?");
768
+ route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
769
+ } else {
770
+ var endToken = tokens[tokens.length - 1];
771
+ var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
772
+ if (!strict) {
773
+ route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
774
+ }
775
+ if (!isEndDelimited) {
776
+ route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
777
+ }
778
+ }
779
+ return new RegExp(route, flags(options));
780
+ }
781
+ exports.tokensToRegexp = tokensToRegexp;
782
+ function pathToRegexp(path5, keys, options) {
783
+ if (path5 instanceof RegExp)
784
+ return regexpToRegexp(path5, keys);
785
+ if (Array.isArray(path5))
786
+ return arrayToRegexp(path5, keys, options);
787
+ return stringToRegexp(path5, keys, options);
788
+ }
789
+ exports.pathToRegexp = pathToRegexp;
790
+ }
791
+ });
792
+
403
793
  // ../routing-utils/dist/superstatic.js
404
794
  var require_superstatic = __commonJS({
405
795
  "../routing-utils/dist/superstatic.js"(exports, module2) {
@@ -433,8 +823,39 @@ var require_superstatic = __commonJS({
433
823
  sourceToRegex: () => sourceToRegex
434
824
  });
435
825
  module2.exports = __toCommonJS2(superstatic_exports);
436
- var import_url3 = require("url");
826
+ var import_url4 = require("url");
437
827
  var import_path_to_regexp = require_dist();
828
+ var import_path_to_regexp_updated = require_dist2();
829
+ function pathToRegexp(callerId, path5, keys, options) {
830
+ const currentRegExp = (0, import_path_to_regexp.pathToRegexp)(path5, keys, options);
831
+ try {
832
+ const currentKeys = keys;
833
+ const newKeys = [];
834
+ const newRegExp = (0, import_path_to_regexp_updated.pathToRegexp)(path5, newKeys, options);
835
+ const isDiffRegExp = currentRegExp.toString() !== newRegExp.toString();
836
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffRegExp) {
837
+ const message = JSON.stringify({
838
+ path: path5,
839
+ currentRegExp: currentRegExp.toString(),
840
+ newRegExp: newRegExp.toString()
841
+ });
842
+ console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${callerId}: ${message}`);
843
+ }
844
+ const isDiffKeys = keys?.toString() !== newKeys?.toString();
845
+ if (process.env.FORCE_PATH_TO_REGEXP_LOG || isDiffKeys) {
846
+ const message = JSON.stringify({
847
+ isDiffKeys,
848
+ currentKeys,
849
+ newKeys
850
+ });
851
+ console.error(`[vc] PATH TO REGEXP KEYS DIFF @ #${callerId}: ${message}`);
852
+ }
853
+ } catch (err) {
854
+ const error = err;
855
+ console.error(`[vc] PATH TO REGEXP ERROR @ #${callerId}: ${error.message}`);
856
+ }
857
+ return currentRegExp;
858
+ }
438
859
  var UN_NAMED_SEGMENT = "__UN_NAMED_SEGMENT__";
439
860
  function getCleanUrls(filePaths) {
440
861
  const htmlFiles = filePaths.map(toRoute).filter((f) => f.endsWith(".html")).map((f) => ({
@@ -590,7 +1011,7 @@ var require_superstatic = __commonJS({
590
1011
  }
591
1012
  function sourceToRegex(source) {
592
1013
  const keys = [];
593
- const r = (0, import_path_to_regexp.pathToRegexp)(source, keys, {
1014
+ const r = pathToRegexp("632", source, keys, {
594
1015
  strict: true,
595
1016
  sensitive: true,
596
1017
  delimiter: "/"
@@ -649,7 +1070,7 @@ var require_superstatic = __commonJS({
649
1070
  indexes[name] = "$" + name;
650
1071
  escapedDestination = escapeSegment(escapedDestination, name);
651
1072
  });
652
- const parsedDestination = (0, import_url3.parse)(escapedDestination, true);
1073
+ const parsedDestination = (0, import_url4.parse)(escapedDestination, true);
653
1074
  delete parsedDestination.href;
654
1075
  delete parsedDestination.path;
655
1076
  delete parsedDestination.search;
@@ -663,9 +1084,9 @@ var require_superstatic = __commonJS({
663
1084
  const hashKeys = [];
664
1085
  const hostnameKeys = [];
665
1086
  try {
666
- (0, import_path_to_regexp.pathToRegexp)(pathname, pathnameKeys);
667
- (0, import_path_to_regexp.pathToRegexp)(hash || "", hashKeys);
668
- (0, import_path_to_regexp.pathToRegexp)(hostname || "", hostnameKeys);
1087
+ pathToRegexp("528", pathname, pathnameKeys);
1088
+ pathToRegexp("834", hash || "", hashKeys);
1089
+ pathToRegexp("712", hostname || "", hostnameKeys);
669
1090
  } catch (_) {
670
1091
  }
671
1092
  destParams = new Set(
@@ -701,7 +1122,7 @@ var require_superstatic = __commonJS({
701
1122
  }
702
1123
  }
703
1124
  }
704
- destination = (0, import_url3.format)({
1125
+ destination = (0, import_url4.format)({
705
1126
  ...rest,
706
1127
  hostname,
707
1128
  pathname,
@@ -7736,24 +8157,24 @@ var require_util = __commonJS({
7736
8157
  }
7737
8158
  exports.urlParse = urlParse;
7738
8159
  function urlGenerate(aParsedUrl) {
7739
- let url3 = "";
8160
+ let url4 = "";
7740
8161
  if (aParsedUrl.scheme) {
7741
- url3 += aParsedUrl.scheme + ":";
8162
+ url4 += aParsedUrl.scheme + ":";
7742
8163
  }
7743
- url3 += "//";
8164
+ url4 += "//";
7744
8165
  if (aParsedUrl.auth) {
7745
- url3 += aParsedUrl.auth + "@";
8166
+ url4 += aParsedUrl.auth + "@";
7746
8167
  }
7747
8168
  if (aParsedUrl.host) {
7748
- url3 += aParsedUrl.host;
8169
+ url4 += aParsedUrl.host;
7749
8170
  }
7750
8171
  if (aParsedUrl.port) {
7751
- url3 += ":" + aParsedUrl.port;
8172
+ url4 += ":" + aParsedUrl.port;
7752
8173
  }
7753
8174
  if (aParsedUrl.path) {
7754
- url3 += aParsedUrl.path;
8175
+ url4 += aParsedUrl.path;
7755
8176
  }
7756
- return url3;
8177
+ return url4;
7757
8178
  }
7758
8179
  exports.urlGenerate = urlGenerate;
7759
8180
  var MAX_CACHED_INPUTS = 32;
@@ -7781,12 +8202,12 @@ var require_util = __commonJS({
7781
8202
  }
7782
8203
  var normalize = lruMemoize(function normalize2(aPath) {
7783
8204
  let path5 = aPath;
7784
- const url3 = urlParse(aPath);
7785
- if (url3) {
7786
- if (!url3.path) {
8205
+ const url4 = urlParse(aPath);
8206
+ if (url4) {
8207
+ if (!url4.path) {
7787
8208
  return aPath;
7788
8209
  }
7789
- path5 = url3.path;
8210
+ path5 = url4.path;
7790
8211
  }
7791
8212
  const isAbsolute = exports.isAbsolute(path5);
7792
8213
  const parts = [];
@@ -7826,9 +8247,9 @@ var require_util = __commonJS({
7826
8247
  if (path5 === "") {
7827
8248
  path5 = isAbsolute ? "/" : ".";
7828
8249
  }
7829
- if (url3) {
7830
- url3.path = path5;
7831
- return urlGenerate(url3);
8250
+ if (url4) {
8251
+ url4.path = path5;
8252
+ return urlGenerate(url4);
7832
8253
  }
7833
8254
  return path5;
7834
8255
  });
@@ -9149,13 +9570,13 @@ var require_source_map_consumer = __commonJS({
9149
9570
  if (this.sourceRoot != null) {
9150
9571
  relativeSource = util.relative(this.sourceRoot, relativeSource);
9151
9572
  }
9152
- let url3;
9153
- if (this.sourceRoot != null && (url3 = util.urlParse(this.sourceRoot))) {
9573
+ let url4;
9574
+ if (this.sourceRoot != null && (url4 = util.urlParse(this.sourceRoot))) {
9154
9575
  const fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
9155
- if (url3.scheme == "file" && this._sources.has(fileUriAbsPath)) {
9576
+ if (url4.scheme == "file" && this._sources.has(fileUriAbsPath)) {
9156
9577
  return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)];
9157
9578
  }
9158
- if ((!url3.path || url3.path == "/") && this._sources.has("/" + relativeSource)) {
9579
+ if ((!url4.path || url4.path == "/") && this._sources.has("/" + relativeSource)) {
9159
9580
  return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
9160
9581
  }
9161
9582
  }
@@ -10374,7 +10795,7 @@ var import_find_up = __toESM(require_find_up());
10374
10795
  var import_fs_extra6 = __toESM(require_lib2());
10375
10796
  var import_path5 = __toESM(require("path"));
10376
10797
  var import_semver4 = __toESM(require_semver());
10377
- var import_url2 = __toESM(require("url"));
10798
+ var import_url3 = __toESM(require("url"));
10378
10799
 
10379
10800
  // src/create-serverless-config.ts
10380
10801
  var import_fs_extra4 = __toESM(require_lib2());
@@ -10545,6 +10966,9 @@ var RSC_PREFETCH_SUFFIX = ".prefetch.rsc";
10545
10966
  var MAX_UNCOMPRESSED_LAMBDA_SIZE = !isNaN(
10546
10967
  Number(process.env.MAX_UNCOMPRESSED_LAMBDA_SIZE)
10547
10968
  ) ? Number(process.env.MAX_UNCOMPRESSED_LAMBDA_SIZE) : DEFAULT_MAX_UNCOMPRESSED_LAMBDA_SIZE;
10969
+ var skipDefaultLocaleRewrite = Boolean(
10970
+ process.env.NEXT_EXPERIMENTAL_DEFER_DEFAULT_LOCALE_REWRITE
10971
+ );
10548
10972
  var TEST_DYNAMIC_ROUTE = /\/\[[^\/]+?\](?=\/|$)/;
10549
10973
  function isDynamicRoute(route) {
10550
10974
  route = route.startsWith("/") ? route : `/${route}`;
@@ -10823,9 +11247,12 @@ async function getDynamicRoutes({
10823
11247
  return routes;
10824
11248
  }
10825
11249
  function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, isServerMode, isCorrectLocaleAPIRoutes, inversedAppPathRoutesManifest) {
10826
- return dynamicRoutes.map((route) => {
10827
- if (route.middleware !== void 0 || route.middlewarePath !== void 0)
10828
- return route;
11250
+ const finalDynamicRoutes = [];
11251
+ for (const route of dynamicRoutes) {
11252
+ if (route.middleware !== void 0 || route.middlewarePath !== void 0) {
11253
+ finalDynamicRoutes.push(route);
11254
+ continue;
11255
+ }
10829
11256
  const { i18n } = routesManifest || {};
10830
11257
  if (i18n) {
10831
11258
  const { pathname } = import_url.default.parse(route.dest);
@@ -10836,6 +11263,14 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
10836
11263
  const isAutoExport = staticPages[addLocaleOrDefault(pathname, routesManifest).substring(1)];
10837
11264
  const isAppRoute = inversedAppPathRoutesManifest?.[pathnameNoPrefix || ""];
10838
11265
  const isLocalePrefixed = isFallback || isBlocking || isAutoExport || isServerMode;
11266
+ if (skipDefaultLocaleRewrite && isLocalePrefixed && routesManifest?.i18n?.localeDetection === false) {
11267
+ const nonLocalePrefixedRoute = JSON.parse(JSON.stringify(route));
11268
+ nonLocalePrefixedRoute.src = nonLocalePrefixedRoute.src.replace(
11269
+ "^",
11270
+ `^${dynamicPrefix || ""}[/]?`
11271
+ );
11272
+ finalDynamicRoutes.push(nonLocalePrefixedRoute);
11273
+ }
10839
11274
  route.src = route.src.replace(
10840
11275
  "^",
10841
11276
  `^${dynamicPrefix ? `${dynamicPrefix}[/]?` : "[/]?"}(?${isLocalePrefixed ? "<nextLocale>" : ":"}${i18n.locales.map((locale) => (0, import_escape_string_regexp.default)(locale)).join("|")})?`
@@ -10849,8 +11284,9 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
10849
11284
  } else {
10850
11285
  route.src = route.src.replace("^", `^${dynamicPrefix}`);
10851
11286
  }
10852
- return route;
10853
- });
11287
+ finalDynamicRoutes.push(route);
11288
+ }
11289
+ return finalDynamicRoutes;
10854
11290
  }
10855
11291
  async function getImagesManifest(entryPath, outputDirectory) {
10856
11292
  const pathImagesManifest = import_path2.default.join(
@@ -13097,6 +13533,7 @@ var legacy_versions_default = [
13097
13533
 
13098
13534
  // src/server-build.ts
13099
13535
  var import_path4 = __toESM(require("path"));
13536
+ var import_url2 = __toESM(require("url"));
13100
13537
  var import_semver3 = __toESM(require_semver());
13101
13538
  var import_async_sema2 = __toESM(require_lib());
13102
13539
  var import_build_utils2 = require("@vercel/build-utils");
@@ -13186,6 +13623,9 @@ async function serverBuild({
13186
13623
  const experimentalAllowBundling = Boolean(
13187
13624
  process.env.NEXT_EXPERIMENTAL_FUNCTION_BUNDLING
13188
13625
  );
13626
+ const skipDefaultLocaleRewrite2 = Boolean(
13627
+ process.env.NEXT_EXPERIMENTAL_DEFER_DEFAULT_LOCALE_REWRITE
13628
+ );
13189
13629
  const lambdas = {};
13190
13630
  const prerenders = {};
13191
13631
  const lambdaPageKeys = Object.keys(lambdaPages);
@@ -13205,6 +13645,7 @@ async function serverBuild({
13205
13645
  let appRscPrefetches = {};
13206
13646
  let appBuildTraces = {};
13207
13647
  let appDir = null;
13648
+ const rscHeader = routesManifest.rsc?.header?.toLowerCase() || "__rsc__";
13208
13649
  if (appPathRoutesManifest) {
13209
13650
  appDir = import_path4.default.join(pagesDir, "../app");
13210
13651
  appBuildTraces = await (0, import_build_utils2.glob)("**/*.js.nft.json", appDir);
@@ -13216,20 +13657,84 @@ async function serverBuild({
13216
13657
  value.contentType = rscContentTypeHeader;
13217
13658
  }
13218
13659
  }
13219
- for (const rewrite of afterFilesRewrites) {
13220
- if (rewrite.src && rewrite.dest) {
13221
- const rscSuffix = isAppPPREnabled ? `(\\.prefetch)?\\.rsc` : "\\.rsc";
13222
- rewrite.src = rewrite.src.replace(
13223
- /\/?\(\?:\/\)\?/,
13224
- `(?<rscsuff>${rscSuffix})?(?:/)?`
13660
+ const modifyRewrites = (rewrites, isAfterFilesRewrite = false) => {
13661
+ for (let i = 0; i < rewrites.length; i++) {
13662
+ const rewrite = rewrites[i];
13663
+ if (!rewrite.src || !rewrite.dest)
13664
+ continue;
13665
+ const { protocol, pathname, query } = import_url2.default.parse(rewrite.dest);
13666
+ if (isAfterFilesRewrite) {
13667
+ const rscSuffix = isAppPPREnabled ? `(\\.prefetch)?\\.rsc` : "\\.rsc";
13668
+ rewrite.src = rewrite.src.replace(
13669
+ /\/?\(\?:\/\)\?/,
13670
+ `(?<rscsuff>${rscSuffix})?(?:/)?`
13671
+ );
13672
+ let destQueryIndex = rewrite.dest.indexOf("?");
13673
+ if (destQueryIndex === -1) {
13674
+ destQueryIndex = rewrite.dest.length;
13675
+ }
13676
+ rewrite.dest = rewrite.dest.substring(0, destQueryIndex) + "$rscsuff" + rewrite.dest.substring(destQueryIndex);
13677
+ }
13678
+ const { rewriteHeaders } = routesManifest;
13679
+ if (!rewriteHeaders)
13680
+ continue;
13681
+ if (protocol || !pathname && !query)
13682
+ continue;
13683
+ const missing = "missing" in rewrite && rewrite.missing ? rewrite.missing : [];
13684
+ let found = missing.filter(
13685
+ (h) => h.type === "header" && h.key.toLowerCase() === rscHeader
13225
13686
  );
13226
- let destQueryIndex = rewrite.dest.indexOf("?");
13227
- if (destQueryIndex === -1) {
13228
- destQueryIndex = rewrite.dest.length;
13687
+ if (found.some(
13688
+ (m) => (
13689
+ // These are rules that don't have a value check or those that
13690
+ // have their value set to '1'.
13691
+ !m.value || m.value === "1"
13692
+ )
13693
+ )) {
13694
+ continue;
13229
13695
  }
13230
- rewrite.dest = rewrite.dest.substring(0, destQueryIndex) + "$rscsuff" + rewrite.dest.substring(destQueryIndex);
13696
+ const has = "has" in rewrite && rewrite.has ? (
13697
+ // As we mutate the array below, we need to clone it to avoid
13698
+ // mutating the original
13699
+ [...rewrite.has]
13700
+ ) : [];
13701
+ found = has.filter(
13702
+ (h) => h.type === "header" && h.key.toLowerCase() === rscHeader
13703
+ );
13704
+ if (found.some(
13705
+ (h) => (
13706
+ // These are rules that have a value set to anything other than
13707
+ // '1'.
13708
+ h.value && h.value !== "1"
13709
+ )
13710
+ )) {
13711
+ continue;
13712
+ }
13713
+ for (const h of found) {
13714
+ has.splice(has.indexOf(h), 1);
13715
+ }
13716
+ has.push({ type: "header", key: rscHeader, value: "1" });
13717
+ const headers2 = "headers" in rewrite && rewrite.headers ? (
13718
+ // Clone the existing headers to avoid mutating the original
13719
+ // object.
13720
+ { ...rewrite.headers }
13721
+ ) : {};
13722
+ const updated = {
13723
+ ...rewrite,
13724
+ has,
13725
+ headers: headers2
13726
+ };
13727
+ if (pathname)
13728
+ headers2[rewriteHeaders.pathHeader] = pathname;
13729
+ if (query)
13730
+ headers2[rewriteHeaders.queryHeader] = query;
13731
+ rewrites.splice(i, 0, updated);
13732
+ i++;
13231
13733
  }
13232
- }
13734
+ };
13735
+ modifyRewrites(beforeFilesRewrites);
13736
+ modifyRewrites(afterFilesRewrites, true);
13737
+ modifyRewrites(fallbackRewrites);
13233
13738
  }
13234
13739
  const isCorrectNotFoundRoutes = import_semver3.default.gte(
13235
13740
  nextVersion,
@@ -14282,7 +14787,6 @@ ${JSON.stringify(
14282
14787
  }
14283
14788
  }
14284
14789
  }
14285
- const rscHeader = routesManifest.rsc?.header?.toLowerCase() || "__rsc__";
14286
14790
  const rscPrefetchHeader = routesManifest.rsc?.prefetchHeader?.toLowerCase();
14287
14791
  const rscVaryHeader = routesManifest?.rsc?.varyHeader || "RSC, Next-Router-State-Tree, Next-Router-Prefetch";
14288
14792
  const appNotFoundPath = import_path4.default.posix.join(".", entryDirectory, "_not-found");
@@ -14420,33 +14924,38 @@ ${JSON.stringify(
14420
14924
  continue: true
14421
14925
  }
14422
14926
  ] : [],
14423
- {
14424
- src: `^${import_path4.default.posix.join("/", entryDirectory)}$`,
14425
- dest: `${import_path4.default.posix.join(
14426
- "/",
14427
- entryDirectory,
14428
- i18n.defaultLocale
14429
- )}`,
14430
- continue: true
14431
- },
14432
- // Auto-prefix non-locale path with default locale
14433
- // note for prerendered pages this will cause
14434
- // x-now-route-matches to contain the path minus the locale
14435
- // e.g. for /de/posts/[slug] x-now-route-matches would have
14436
- // 1=posts%2Fpost-1
14437
- {
14438
- src: `^${import_path4.default.posix.join(
14439
- "/",
14440
- entryDirectory,
14441
- "/"
14442
- )}(?!(?:_next/.*|${i18n.locales.map((locale) => (0, import_escape_string_regexp2.default)(locale)).join("|")})(?:/.*|$))(.*)$`,
14443
- dest: `${import_path4.default.posix.join(
14444
- "/",
14445
- entryDirectory,
14446
- i18n.defaultLocale
14447
- )}/$1`,
14448
- continue: true
14449
- }
14927
+ // We only want to add these rewrites before user redirects
14928
+ // when `skipDefaultLocaleRewrite` is not flagged on
14929
+ // and when localeDetection is enabled.
14930
+ ...!skipDefaultLocaleRewrite2 || i18n.localeDetection !== false ? [
14931
+ {
14932
+ src: `^${import_path4.default.posix.join("/", entryDirectory)}$`,
14933
+ dest: `${import_path4.default.posix.join(
14934
+ "/",
14935
+ entryDirectory,
14936
+ i18n.defaultLocale
14937
+ )}`,
14938
+ continue: true
14939
+ },
14940
+ // Auto-prefix non-locale path with default locale
14941
+ // note for prerendered pages this will cause
14942
+ // x-now-route-matches to contain the path minus the locale
14943
+ // e.g. for /de/posts/[slug] x-now-route-matches would have
14944
+ // 1=posts%2Fpost-1
14945
+ {
14946
+ src: `^${import_path4.default.posix.join(
14947
+ "/",
14948
+ entryDirectory,
14949
+ "/"
14950
+ )}(?!(?:_next/.*|${i18n.locales.map((locale) => (0, import_escape_string_regexp2.default)(locale)).join("|")})(?:/.*|$))(.*)$`,
14951
+ dest: `${import_path4.default.posix.join(
14952
+ "/",
14953
+ entryDirectory,
14954
+ i18n.defaultLocale
14955
+ )}/$1`,
14956
+ continue: true
14957
+ }
14958
+ ] : []
14450
14959
  ] : [],
14451
14960
  ...headers,
14452
14961
  ...redirects,
@@ -14677,6 +15186,37 @@ ${JSON.stringify(
14677
15186
  // remove locale prefixes to check public files and
14678
15187
  // to allow checking non-prefixed lambda outputs
14679
15188
  ...i18n ? [
15189
+ // When `skipDefaultLocaleRewrite` is flagged on and localeDetection is disabled,
15190
+ // we only want to add the rewrite as the fallback case once routing is complete.
15191
+ ...skipDefaultLocaleRewrite2 && i18n.localeDetection === false ? [
15192
+ {
15193
+ src: `^${import_path4.default.posix.join("/", entryDirectory)}$`,
15194
+ dest: `${import_path4.default.posix.join(
15195
+ "/",
15196
+ entryDirectory,
15197
+ i18n.defaultLocale
15198
+ )}`,
15199
+ check: true
15200
+ },
15201
+ // Auto-prefix non-locale path with default locale
15202
+ // note for prerendered pages this will cause
15203
+ // x-now-route-matches to contain the path minus the locale
15204
+ // e.g. for /de/posts/[slug] x-now-route-matches would have
15205
+ // 1=posts%2Fpost-1
15206
+ {
15207
+ src: `^${import_path4.default.posix.join(
15208
+ "/",
15209
+ entryDirectory,
15210
+ "/"
15211
+ )}(?!(?:_next/.*|${i18n.locales.map((locale) => (0, import_escape_string_regexp2.default)(locale)).join("|")})(?:/.*|$))(.*)$`,
15212
+ dest: `${import_path4.default.posix.join(
15213
+ "/",
15214
+ entryDirectory,
15215
+ i18n.defaultLocale
15216
+ )}/$1`,
15217
+ check: true
15218
+ }
15219
+ ] : [],
14680
15220
  {
14681
15221
  src: import_path4.default.posix.join(
14682
15222
  "/",
@@ -16578,7 +17118,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16578
17118
  for (let i = 0; i < dynamicRoutes.length; i++) {
16579
17119
  const route = dynamicRoutes[i];
16580
17120
  mergedDynamicRoutesLambdaRoutes.push(route);
16581
- const { pathname } = import_url2.default.parse(route.dest);
17121
+ const { pathname } = import_url3.default.parse(route.dest);
16582
17122
  if (pathname && pageLambdaMap[pathname]) {
16583
17123
  mergedDynamicRoutesLambdaRoutes.push(
16584
17124
  dynamicPageLambdaRoutesMap[pathname]
@@ -16588,7 +17128,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16588
17128
  for (let i = 0; i < dataRoutes.length; i++) {
16589
17129
  const route = dataRoutes[i];
16590
17130
  mergedDataRoutesLambdaRoutes.push(route);
16591
- const { pathname } = import_url2.default.parse(route.dest);
17131
+ const { pathname } = import_url3.default.parse(route.dest);
16592
17132
  if (pathname && pageLambdaMap[pathname] && dynamicPageLambdaRoutesMap[pathname]) {
16593
17133
  mergedDataRoutesLambdaRoutes.push(dynamicPageLambdaRoutesMap[pathname]);
16594
17134
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.4.2",
3
+ "version": "4.4.5",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -30,8 +30,8 @@
30
30
  "@types/semver": "6.0.0",
31
31
  "@types/text-table": "0.2.1",
32
32
  "@types/webpack-sources": "3.2.0",
33
- "@vercel/build-utils": "9.0.1",
34
- "@vercel/routing-utils": "5.0.0",
33
+ "@vercel/build-utils": "9.1.1",
34
+ "@vercel/routing-utils": "5.0.2",
35
35
  "async-sema": "3.0.1",
36
36
  "buffer-crc32": "0.2.13",
37
37
  "bytes": "3.1.2",