@vercel/next 4.4.2 → 4.4.4

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 +188 -69
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -433,7 +433,7 @@ var require_superstatic = __commonJS({
433
433
  sourceToRegex: () => sourceToRegex
434
434
  });
435
435
  module2.exports = __toCommonJS2(superstatic_exports);
436
- var import_url3 = require("url");
436
+ var import_url4 = require("url");
437
437
  var import_path_to_regexp = require_dist();
438
438
  var UN_NAMED_SEGMENT = "__UN_NAMED_SEGMENT__";
439
439
  function getCleanUrls(filePaths) {
@@ -649,7 +649,7 @@ var require_superstatic = __commonJS({
649
649
  indexes[name] = "$" + name;
650
650
  escapedDestination = escapeSegment(escapedDestination, name);
651
651
  });
652
- const parsedDestination = (0, import_url3.parse)(escapedDestination, true);
652
+ const parsedDestination = (0, import_url4.parse)(escapedDestination, true);
653
653
  delete parsedDestination.href;
654
654
  delete parsedDestination.path;
655
655
  delete parsedDestination.search;
@@ -701,7 +701,7 @@ var require_superstatic = __commonJS({
701
701
  }
702
702
  }
703
703
  }
704
- destination = (0, import_url3.format)({
704
+ destination = (0, import_url4.format)({
705
705
  ...rest,
706
706
  hostname,
707
707
  pathname,
@@ -7736,24 +7736,24 @@ var require_util = __commonJS({
7736
7736
  }
7737
7737
  exports.urlParse = urlParse;
7738
7738
  function urlGenerate(aParsedUrl) {
7739
- let url3 = "";
7739
+ let url4 = "";
7740
7740
  if (aParsedUrl.scheme) {
7741
- url3 += aParsedUrl.scheme + ":";
7741
+ url4 += aParsedUrl.scheme + ":";
7742
7742
  }
7743
- url3 += "//";
7743
+ url4 += "//";
7744
7744
  if (aParsedUrl.auth) {
7745
- url3 += aParsedUrl.auth + "@";
7745
+ url4 += aParsedUrl.auth + "@";
7746
7746
  }
7747
7747
  if (aParsedUrl.host) {
7748
- url3 += aParsedUrl.host;
7748
+ url4 += aParsedUrl.host;
7749
7749
  }
7750
7750
  if (aParsedUrl.port) {
7751
- url3 += ":" + aParsedUrl.port;
7751
+ url4 += ":" + aParsedUrl.port;
7752
7752
  }
7753
7753
  if (aParsedUrl.path) {
7754
- url3 += aParsedUrl.path;
7754
+ url4 += aParsedUrl.path;
7755
7755
  }
7756
- return url3;
7756
+ return url4;
7757
7757
  }
7758
7758
  exports.urlGenerate = urlGenerate;
7759
7759
  var MAX_CACHED_INPUTS = 32;
@@ -7781,12 +7781,12 @@ var require_util = __commonJS({
7781
7781
  }
7782
7782
  var normalize = lruMemoize(function normalize2(aPath) {
7783
7783
  let path5 = aPath;
7784
- const url3 = urlParse(aPath);
7785
- if (url3) {
7786
- if (!url3.path) {
7784
+ const url4 = urlParse(aPath);
7785
+ if (url4) {
7786
+ if (!url4.path) {
7787
7787
  return aPath;
7788
7788
  }
7789
- path5 = url3.path;
7789
+ path5 = url4.path;
7790
7790
  }
7791
7791
  const isAbsolute = exports.isAbsolute(path5);
7792
7792
  const parts = [];
@@ -7826,9 +7826,9 @@ var require_util = __commonJS({
7826
7826
  if (path5 === "") {
7827
7827
  path5 = isAbsolute ? "/" : ".";
7828
7828
  }
7829
- if (url3) {
7830
- url3.path = path5;
7831
- return urlGenerate(url3);
7829
+ if (url4) {
7830
+ url4.path = path5;
7831
+ return urlGenerate(url4);
7832
7832
  }
7833
7833
  return path5;
7834
7834
  });
@@ -9149,13 +9149,13 @@ var require_source_map_consumer = __commonJS({
9149
9149
  if (this.sourceRoot != null) {
9150
9150
  relativeSource = util.relative(this.sourceRoot, relativeSource);
9151
9151
  }
9152
- let url3;
9153
- if (this.sourceRoot != null && (url3 = util.urlParse(this.sourceRoot))) {
9152
+ let url4;
9153
+ if (this.sourceRoot != null && (url4 = util.urlParse(this.sourceRoot))) {
9154
9154
  const fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
9155
- if (url3.scheme == "file" && this._sources.has(fileUriAbsPath)) {
9155
+ if (url4.scheme == "file" && this._sources.has(fileUriAbsPath)) {
9156
9156
  return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)];
9157
9157
  }
9158
- if ((!url3.path || url3.path == "/") && this._sources.has("/" + relativeSource)) {
9158
+ if ((!url4.path || url4.path == "/") && this._sources.has("/" + relativeSource)) {
9159
9159
  return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
9160
9160
  }
9161
9161
  }
@@ -10374,7 +10374,7 @@ var import_find_up = __toESM(require_find_up());
10374
10374
  var import_fs_extra6 = __toESM(require_lib2());
10375
10375
  var import_path5 = __toESM(require("path"));
10376
10376
  var import_semver4 = __toESM(require_semver());
10377
- var import_url2 = __toESM(require("url"));
10377
+ var import_url3 = __toESM(require("url"));
10378
10378
 
10379
10379
  // src/create-serverless-config.ts
10380
10380
  var import_fs_extra4 = __toESM(require_lib2());
@@ -10545,6 +10545,9 @@ var RSC_PREFETCH_SUFFIX = ".prefetch.rsc";
10545
10545
  var MAX_UNCOMPRESSED_LAMBDA_SIZE = !isNaN(
10546
10546
  Number(process.env.MAX_UNCOMPRESSED_LAMBDA_SIZE)
10547
10547
  ) ? Number(process.env.MAX_UNCOMPRESSED_LAMBDA_SIZE) : DEFAULT_MAX_UNCOMPRESSED_LAMBDA_SIZE;
10548
+ var skipDefaultLocaleRewrite = Boolean(
10549
+ process.env.NEXT_EXPERIMENTAL_DEFER_DEFAULT_LOCALE_REWRITE
10550
+ );
10548
10551
  var TEST_DYNAMIC_ROUTE = /\/\[[^\/]+?\](?=\/|$)/;
10549
10552
  function isDynamicRoute(route) {
10550
10553
  route = route.startsWith("/") ? route : `/${route}`;
@@ -10823,9 +10826,12 @@ async function getDynamicRoutes({
10823
10826
  return routes;
10824
10827
  }
10825
10828
  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;
10829
+ const finalDynamicRoutes = [];
10830
+ for (const route of dynamicRoutes) {
10831
+ if (route.middleware !== void 0 || route.middlewarePath !== void 0) {
10832
+ finalDynamicRoutes.push(route);
10833
+ continue;
10834
+ }
10829
10835
  const { i18n } = routesManifest || {};
10830
10836
  if (i18n) {
10831
10837
  const { pathname } = import_url.default.parse(route.dest);
@@ -10836,6 +10842,14 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
10836
10842
  const isAutoExport = staticPages[addLocaleOrDefault(pathname, routesManifest).substring(1)];
10837
10843
  const isAppRoute = inversedAppPathRoutesManifest?.[pathnameNoPrefix || ""];
10838
10844
  const isLocalePrefixed = isFallback || isBlocking || isAutoExport || isServerMode;
10845
+ if (skipDefaultLocaleRewrite && isLocalePrefixed && routesManifest?.i18n?.localeDetection === false) {
10846
+ const nonLocalePrefixedRoute = JSON.parse(JSON.stringify(route));
10847
+ nonLocalePrefixedRoute.src = nonLocalePrefixedRoute.src.replace(
10848
+ "^",
10849
+ `^${dynamicPrefix || ""}[/]?`
10850
+ );
10851
+ finalDynamicRoutes.push(nonLocalePrefixedRoute);
10852
+ }
10839
10853
  route.src = route.src.replace(
10840
10854
  "^",
10841
10855
  `^${dynamicPrefix ? `${dynamicPrefix}[/]?` : "[/]?"}(?${isLocalePrefixed ? "<nextLocale>" : ":"}${i18n.locales.map((locale) => (0, import_escape_string_regexp.default)(locale)).join("|")})?`
@@ -10849,8 +10863,9 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
10849
10863
  } else {
10850
10864
  route.src = route.src.replace("^", `^${dynamicPrefix}`);
10851
10865
  }
10852
- return route;
10853
- });
10866
+ finalDynamicRoutes.push(route);
10867
+ }
10868
+ return finalDynamicRoutes;
10854
10869
  }
10855
10870
  async function getImagesManifest(entryPath, outputDirectory) {
10856
10871
  const pathImagesManifest = import_path2.default.join(
@@ -13097,6 +13112,7 @@ var legacy_versions_default = [
13097
13112
 
13098
13113
  // src/server-build.ts
13099
13114
  var import_path4 = __toESM(require("path"));
13115
+ var import_url2 = __toESM(require("url"));
13100
13116
  var import_semver3 = __toESM(require_semver());
13101
13117
  var import_async_sema2 = __toESM(require_lib());
13102
13118
  var import_build_utils2 = require("@vercel/build-utils");
@@ -13186,6 +13202,9 @@ async function serverBuild({
13186
13202
  const experimentalAllowBundling = Boolean(
13187
13203
  process.env.NEXT_EXPERIMENTAL_FUNCTION_BUNDLING
13188
13204
  );
13205
+ const skipDefaultLocaleRewrite2 = Boolean(
13206
+ process.env.NEXT_EXPERIMENTAL_DEFER_DEFAULT_LOCALE_REWRITE
13207
+ );
13189
13208
  const lambdas = {};
13190
13209
  const prerenders = {};
13191
13210
  const lambdaPageKeys = Object.keys(lambdaPages);
@@ -13205,6 +13224,7 @@ async function serverBuild({
13205
13224
  let appRscPrefetches = {};
13206
13225
  let appBuildTraces = {};
13207
13226
  let appDir = null;
13227
+ const rscHeader = routesManifest.rsc?.header?.toLowerCase() || "__rsc__";
13208
13228
  if (appPathRoutesManifest) {
13209
13229
  appDir = import_path4.default.join(pagesDir, "../app");
13210
13230
  appBuildTraces = await (0, import_build_utils2.glob)("**/*.js.nft.json", appDir);
@@ -13216,20 +13236,84 @@ async function serverBuild({
13216
13236
  value.contentType = rscContentTypeHeader;
13217
13237
  }
13218
13238
  }
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})?(?:/)?`
13239
+ const modifyRewrites = (rewrites, isAfterFilesRewrite = false) => {
13240
+ for (let i = 0; i < rewrites.length; i++) {
13241
+ const rewrite = rewrites[i];
13242
+ if (!rewrite.src || !rewrite.dest)
13243
+ continue;
13244
+ const { protocol, pathname, query } = import_url2.default.parse(rewrite.dest);
13245
+ if (isAfterFilesRewrite) {
13246
+ const rscSuffix = isAppPPREnabled ? `(\\.prefetch)?\\.rsc` : "\\.rsc";
13247
+ rewrite.src = rewrite.src.replace(
13248
+ /\/?\(\?:\/\)\?/,
13249
+ `(?<rscsuff>${rscSuffix})?(?:/)?`
13250
+ );
13251
+ let destQueryIndex = rewrite.dest.indexOf("?");
13252
+ if (destQueryIndex === -1) {
13253
+ destQueryIndex = rewrite.dest.length;
13254
+ }
13255
+ rewrite.dest = rewrite.dest.substring(0, destQueryIndex) + "$rscsuff" + rewrite.dest.substring(destQueryIndex);
13256
+ }
13257
+ const { rewriteHeaders } = routesManifest;
13258
+ if (!rewriteHeaders)
13259
+ continue;
13260
+ if (protocol || !pathname && !query)
13261
+ continue;
13262
+ const missing = "missing" in rewrite && rewrite.missing ? rewrite.missing : [];
13263
+ let found = missing.filter(
13264
+ (h) => h.type === "header" && h.key.toLowerCase() === rscHeader
13265
+ );
13266
+ if (found.some(
13267
+ (m) => (
13268
+ // These are rules that don't have a value check or those that
13269
+ // have their value set to '1'.
13270
+ !m.value || m.value === "1"
13271
+ )
13272
+ )) {
13273
+ continue;
13274
+ }
13275
+ const has = "has" in rewrite && rewrite.has ? (
13276
+ // As we mutate the array below, we need to clone it to avoid
13277
+ // mutating the original
13278
+ [...rewrite.has]
13279
+ ) : [];
13280
+ found = has.filter(
13281
+ (h) => h.type === "header" && h.key.toLowerCase() === rscHeader
13225
13282
  );
13226
- let destQueryIndex = rewrite.dest.indexOf("?");
13227
- if (destQueryIndex === -1) {
13228
- destQueryIndex = rewrite.dest.length;
13283
+ if (found.some(
13284
+ (h) => (
13285
+ // These are rules that have a value set to anything other than
13286
+ // '1'.
13287
+ h.value && h.value !== "1"
13288
+ )
13289
+ )) {
13290
+ continue;
13229
13291
  }
13230
- rewrite.dest = rewrite.dest.substring(0, destQueryIndex) + "$rscsuff" + rewrite.dest.substring(destQueryIndex);
13292
+ for (const h of found) {
13293
+ has.splice(has.indexOf(h), 1);
13294
+ }
13295
+ has.push({ type: "header", key: rscHeader, value: "1" });
13296
+ const headers2 = "headers" in rewrite && rewrite.headers ? (
13297
+ // Clone the existing headers to avoid mutating the original
13298
+ // object.
13299
+ { ...rewrite.headers }
13300
+ ) : {};
13301
+ const updated = {
13302
+ ...rewrite,
13303
+ has,
13304
+ headers: headers2
13305
+ };
13306
+ if (pathname)
13307
+ headers2[rewriteHeaders.pathHeader] = pathname;
13308
+ if (query)
13309
+ headers2[rewriteHeaders.queryHeader] = query;
13310
+ rewrites.splice(i, 0, updated);
13311
+ i++;
13231
13312
  }
13232
- }
13313
+ };
13314
+ modifyRewrites(beforeFilesRewrites);
13315
+ modifyRewrites(afterFilesRewrites, true);
13316
+ modifyRewrites(fallbackRewrites);
13233
13317
  }
13234
13318
  const isCorrectNotFoundRoutes = import_semver3.default.gte(
13235
13319
  nextVersion,
@@ -14282,7 +14366,6 @@ ${JSON.stringify(
14282
14366
  }
14283
14367
  }
14284
14368
  }
14285
- const rscHeader = routesManifest.rsc?.header?.toLowerCase() || "__rsc__";
14286
14369
  const rscPrefetchHeader = routesManifest.rsc?.prefetchHeader?.toLowerCase();
14287
14370
  const rscVaryHeader = routesManifest?.rsc?.varyHeader || "RSC, Next-Router-State-Tree, Next-Router-Prefetch";
14288
14371
  const appNotFoundPath = import_path4.default.posix.join(".", entryDirectory, "_not-found");
@@ -14420,33 +14503,38 @@ ${JSON.stringify(
14420
14503
  continue: true
14421
14504
  }
14422
14505
  ] : [],
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
- }
14506
+ // We only want to add these rewrites before user redirects
14507
+ // when `skipDefaultLocaleRewrite` is not flagged on
14508
+ // and when localeDetection is enabled.
14509
+ ...!skipDefaultLocaleRewrite2 || i18n.localeDetection !== false ? [
14510
+ {
14511
+ src: `^${import_path4.default.posix.join("/", entryDirectory)}$`,
14512
+ dest: `${import_path4.default.posix.join(
14513
+ "/",
14514
+ entryDirectory,
14515
+ i18n.defaultLocale
14516
+ )}`,
14517
+ continue: true
14518
+ },
14519
+ // Auto-prefix non-locale path with default locale
14520
+ // note for prerendered pages this will cause
14521
+ // x-now-route-matches to contain the path minus the locale
14522
+ // e.g. for /de/posts/[slug] x-now-route-matches would have
14523
+ // 1=posts%2Fpost-1
14524
+ {
14525
+ src: `^${import_path4.default.posix.join(
14526
+ "/",
14527
+ entryDirectory,
14528
+ "/"
14529
+ )}(?!(?:_next/.*|${i18n.locales.map((locale) => (0, import_escape_string_regexp2.default)(locale)).join("|")})(?:/.*|$))(.*)$`,
14530
+ dest: `${import_path4.default.posix.join(
14531
+ "/",
14532
+ entryDirectory,
14533
+ i18n.defaultLocale
14534
+ )}/$1`,
14535
+ continue: true
14536
+ }
14537
+ ] : []
14450
14538
  ] : [],
14451
14539
  ...headers,
14452
14540
  ...redirects,
@@ -14677,6 +14765,37 @@ ${JSON.stringify(
14677
14765
  // remove locale prefixes to check public files and
14678
14766
  // to allow checking non-prefixed lambda outputs
14679
14767
  ...i18n ? [
14768
+ // When `skipDefaultLocaleRewrite` is flagged on and localeDetection is disabled,
14769
+ // we only want to add the rewrite as the fallback case once routing is complete.
14770
+ ...skipDefaultLocaleRewrite2 && i18n.localeDetection === false ? [
14771
+ {
14772
+ src: `^${import_path4.default.posix.join("/", entryDirectory)}$`,
14773
+ dest: `${import_path4.default.posix.join(
14774
+ "/",
14775
+ entryDirectory,
14776
+ i18n.defaultLocale
14777
+ )}`,
14778
+ check: true
14779
+ },
14780
+ // Auto-prefix non-locale path with default locale
14781
+ // note for prerendered pages this will cause
14782
+ // x-now-route-matches to contain the path minus the locale
14783
+ // e.g. for /de/posts/[slug] x-now-route-matches would have
14784
+ // 1=posts%2Fpost-1
14785
+ {
14786
+ src: `^${import_path4.default.posix.join(
14787
+ "/",
14788
+ entryDirectory,
14789
+ "/"
14790
+ )}(?!(?:_next/.*|${i18n.locales.map((locale) => (0, import_escape_string_regexp2.default)(locale)).join("|")})(?:/.*|$))(.*)$`,
14791
+ dest: `${import_path4.default.posix.join(
14792
+ "/",
14793
+ entryDirectory,
14794
+ i18n.defaultLocale
14795
+ )}/$1`,
14796
+ check: true
14797
+ }
14798
+ ] : [],
14680
14799
  {
14681
14800
  src: import_path4.default.posix.join(
14682
14801
  "/",
@@ -16578,7 +16697,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16578
16697
  for (let i = 0; i < dynamicRoutes.length; i++) {
16579
16698
  const route = dynamicRoutes[i];
16580
16699
  mergedDynamicRoutesLambdaRoutes.push(route);
16581
- const { pathname } = import_url2.default.parse(route.dest);
16700
+ const { pathname } = import_url3.default.parse(route.dest);
16582
16701
  if (pathname && pageLambdaMap[pathname]) {
16583
16702
  mergedDynamicRoutesLambdaRoutes.push(
16584
16703
  dynamicPageLambdaRoutesMap[pathname]
@@ -16588,7 +16707,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
16588
16707
  for (let i = 0; i < dataRoutes.length; i++) {
16589
16708
  const route = dataRoutes[i];
16590
16709
  mergedDataRoutesLambdaRoutes.push(route);
16591
- const { pathname } = import_url2.default.parse(route.dest);
16710
+ const { pathname } = import_url3.default.parse(route.dest);
16592
16711
  if (pathname && pageLambdaMap[pathname] && dynamicPageLambdaRoutesMap[pathname]) {
16593
16712
  mergedDataRoutesLambdaRoutes.push(dynamicPageLambdaRoutesMap[pathname]);
16594
16713
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.4.2",
3
+ "version": "4.4.4",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -30,7 +30,7 @@
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",
33
+ "@vercel/build-utils": "9.1.0",
34
34
  "@vercel/routing-utils": "5.0.0",
35
35
  "async-sema": "3.0.1",
36
36
  "buffer-crc32": "0.2.13",