@vercel/next 4.2.10 → 4.2.12

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 +86 -47
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -11971,7 +11971,9 @@ function normalizePage(page) {
11971
11971
  if (!page.startsWith("/")) {
11972
11972
  page = `/${page}`;
11973
11973
  }
11974
- page = page.replace(/\/index$/, "/");
11974
+ if (page === "/index") {
11975
+ page = "/";
11976
+ }
11975
11977
  return page;
11976
11978
  }
11977
11979
  async function getRoutesManifest(entryPath, outputDirectory, nextVersion) {
@@ -12017,8 +12019,8 @@ async function getDynamicRoutes({
12017
12019
  bypassToken,
12018
12020
  isServerMode,
12019
12021
  dynamicMiddlewareRouteMap,
12020
- experimentalPPRRoutes,
12021
- hasActionOutputSupport
12022
+ hasActionOutputSupport,
12023
+ isAppPPREnabled
12022
12024
  }) {
12023
12025
  if (routesManifest) {
12024
12026
  switch (routesManifest.version) {
@@ -12072,7 +12074,7 @@ async function getDynamicRoutes({
12072
12074
  }
12073
12075
  ];
12074
12076
  }
12075
- if (experimentalPPRRoutes.has(page)) {
12077
+ if (isAppPPREnabled) {
12076
12078
  let dest = route.dest?.replace(/($|\?)/, ".prefetch.rsc$1");
12077
12079
  if (page === "/" || page === "/index") {
12078
12080
  dest = dest?.replace(/([^/]+\.prefetch\.rsc(\?.*|$))/, "__$1");
@@ -12656,6 +12658,9 @@ async function getSourceFilePathFromPage({
12656
12658
  }
12657
12659
  }
12658
12660
  }
12661
+ if (page === "/_not-found/page") {
12662
+ return "";
12663
+ }
12659
12664
  console.log(
12660
12665
  `WARNING: Unable to find source file for page ${page} with extensions: ${extensionsToTry.join(
12661
12666
  ", "
@@ -12713,17 +12718,19 @@ async function getPageLambdaGroups({
12713
12718
  const routeName = normalizePage(page.replace(/\.js$/, ""));
12714
12719
  const isPrerenderRoute = prerenderRoutes.has(routeName);
12715
12720
  const isExperimentalPPR = experimentalPPRRoutes?.has(routeName) ?? false;
12721
+ const isStreaming = !isPrerenderRoute || isExperimentalPPR;
12716
12722
  let opts = {};
12717
12723
  if (functionsConfigManifest && functionsConfigManifest.functions[routeName]) {
12718
12724
  opts = functionsConfigManifest.functions[routeName];
12719
12725
  }
12720
12726
  if (config && config.functions) {
12721
- const pageFromManifest = inversedAppPathManifest?.[routeName];
12722
12727
  const sourceFile = await getSourceFilePathFromPage({
12723
12728
  workPath: entryPath,
12724
- // since this function is used by both `pages` and `app`, the manifest might not be provided
12725
- // so fallback to normal behavior of just checking the `page`.
12726
- page: pageFromManifest ?? page,
12729
+ page: normalizeSourceFilePageFromManifest(
12730
+ routeName,
12731
+ page,
12732
+ inversedAppPathManifest
12733
+ ),
12727
12734
  pageExtensions
12728
12735
  });
12729
12736
  const vercelConfigOpts = await (0, import_build_utils.getLambdaOptionsFromFunction)({
@@ -12758,6 +12765,7 @@ async function getPageLambdaGroups({
12758
12765
  ...opts,
12759
12766
  isPrerenders: isPrerenderRoute,
12760
12767
  isExperimentalPPR,
12768
+ isStreaming,
12761
12769
  isApiLambda: !!isApiPage(page),
12762
12770
  pseudoLayerBytes: initialPseudoLayer.pseudoLayerBytes,
12763
12771
  pseudoLayerUncompressedBytes: initialPseudoLayerUncompressed,
@@ -12779,6 +12787,28 @@ async function getPageLambdaGroups({
12779
12787
  }
12780
12788
  return groups;
12781
12789
  }
12790
+ function normalizeSourceFilePageFromManifest(routeName, page, inversedAppPathManifest) {
12791
+ const pageFromManifest = inversedAppPathManifest?.[routeName];
12792
+ if (!pageFromManifest) {
12793
+ return page;
12794
+ }
12795
+ const metadataConventions = [
12796
+ "/favicon.",
12797
+ "/icon.",
12798
+ "/apple-icon.",
12799
+ "/opengraph-image.",
12800
+ "/twitter-image.",
12801
+ "/sitemap.",
12802
+ "/robots."
12803
+ ];
12804
+ const isSpecialFile = metadataConventions.some(
12805
+ (convention) => routeName.startsWith(convention)
12806
+ );
12807
+ if (isSpecialFile) {
12808
+ return routeName;
12809
+ }
12810
+ return pageFromManifest;
12811
+ }
12782
12812
  var outputFunctionFileSizeInfo = (pages, pseudoLayer, pseudoLayerUncompressedBytes, compressedPages) => {
12783
12813
  const exceededLimitOutput = [];
12784
12814
  console.log(
@@ -13102,14 +13132,6 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13102
13132
  if (isOmittedOrNotFound) {
13103
13133
  initialStatus = 404;
13104
13134
  }
13105
- let addedIndexSuffix = false;
13106
- if (isAppPathRoute) {
13107
- if (routeKey !== "/index" && routeKey.endsWith("/index")) {
13108
- routeKey = `${routeKey}/index`;
13109
- routeFileNoExt = routeKey;
13110
- addedIndexSuffix = true;
13111
- }
13112
- }
13113
13135
  let outputPathPage = import_path2.default.posix.join(entryDirectory, routeFileNoExt);
13114
13136
  if (!isAppPathRoute) {
13115
13137
  outputPathPage = normalizeIndexOutput(outputPathPage, isServerMode);
@@ -13234,7 +13256,7 @@ var onPrerenderRoute = (prerenderRouteArgs) => async (routeKey, {
13234
13256
  );
13235
13257
  }
13236
13258
  experimentalStreamingLambdaPath = experimentalStreamingLambdaPaths.get(
13237
- pathnameToOutputName(entryDirectory, routeKey, addedIndexSuffix)
13259
+ pathnameToOutputName(entryDirectory, routeKey)
13238
13260
  );
13239
13261
  if (!experimentalStreamingLambdaPath && srcRoute) {
13240
13262
  experimentalStreamingLambdaPath = experimentalStreamingLambdaPaths.get(
@@ -13413,11 +13435,9 @@ function normalizeIndexOutput(outputName, isServerMode) {
13413
13435
  function getNextServerPath(nextVersion) {
13414
13436
  return import_semver.default.gte(nextVersion, "v11.0.2-canary.4") ? "next/dist/server" : "next/dist/next-server/server";
13415
13437
  }
13416
- function pathnameToOutputName(entryDirectory, pathname, addedIndexSuffix = false) {
13438
+ function pathnameToOutputName(entryDirectory, pathname) {
13417
13439
  if (pathname === "/") {
13418
13440
  pathname = "/index";
13419
- } else if (addedIndexSuffix) {
13420
- pathname = pathname.replace(/\/index$/, "");
13421
13441
  }
13422
13442
  return import_path2.default.posix.join(entryDirectory, pathname);
13423
13443
  }
@@ -14397,8 +14417,15 @@ async function serverBuild({
14397
14417
  isCorrectLocaleAPIRoutes,
14398
14418
  requiredServerFilesManifest,
14399
14419
  variantsManifest,
14400
- experimentalPPRRoutes
14420
+ experimentalPPRRoutes,
14421
+ isAppPPREnabled
14401
14422
  }) {
14423
+ if (isAppPPREnabled) {
14424
+ (0, import_build_utils2.debug)(
14425
+ "experimentalPPRRoutes",
14426
+ JSON.stringify(Array.from(experimentalPPRRoutes))
14427
+ );
14428
+ }
14402
14429
  lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
14403
14430
  const experimentalAllowBundling = Boolean(
14404
14431
  process.env.NEXT_EXPERIMENTAL_FUNCTION_BUNDLING
@@ -14420,16 +14447,13 @@ async function serverBuild({
14420
14447
  inversedAppPathManifest[appPathRoutesManifest[ogRoute]] = ogRoute;
14421
14448
  }
14422
14449
  }
14423
- const experimental = {
14424
- ppr: requiredServerFilesManifest.config.experimental?.ppr === true || requiredServerFilesManifest.config.experimental?.ppr === "incremental"
14425
- };
14426
14450
  let appRscPrefetches = {};
14427
14451
  let appBuildTraces = {};
14428
14452
  let appDir = null;
14429
14453
  if (appPathRoutesManifest) {
14430
14454
  appDir = import_path4.default.join(pagesDir, "../app");
14431
14455
  appBuildTraces = await (0, import_build_utils2.glob)("**/*.js.nft.json", appDir);
14432
- appRscPrefetches = experimental.ppr ? {} : await (0, import_build_utils2.glob)(`**/*${RSC_PREFETCH_SUFFIX}`, appDir);
14456
+ appRscPrefetches = isAppPPREnabled ? {} : await (0, import_build_utils2.glob)(`**/*${RSC_PREFETCH_SUFFIX}`, appDir);
14433
14457
  const rscContentTypeHeader = routesManifest?.rsc?.contentTypeHeader || RSC_CONTENT_TYPE;
14434
14458
  appRscPrefetches = normalizePrefetches(appRscPrefetches);
14435
14459
  for (const value of Object.values(appRscPrefetches)) {
@@ -14441,7 +14465,7 @@ async function serverBuild({
14441
14465
  if (rewrite.src && rewrite.dest) {
14442
14466
  rewrite.src = rewrite.src.replace(
14443
14467
  /\/?\(\?:\/\)\?/,
14444
- `(?<rscsuff>${experimental.ppr ? "(\\.prefetch)?" : ""}\\.rsc)?(?:/)?`
14468
+ `(?<rscsuff>${isAppPPREnabled ? "(\\.prefetch)?" : ""}\\.rsc)?(?:/)?`
14445
14469
  );
14446
14470
  let destQueryIndex = rewrite.dest.indexOf("?");
14447
14471
  if (destQueryIndex === -1) {
@@ -14955,9 +14979,6 @@ async function serverBuild({
14955
14979
  });
14956
14980
  const appRouterStreamingActionLambdaGroups = [];
14957
14981
  for (const group of appRouterLambdaGroups) {
14958
- if (!group.isPrerenders || group.isExperimentalPPR) {
14959
- group.isStreaming = true;
14960
- }
14961
14982
  group.isAppRouter = true;
14962
14983
  if (hasActionOutputSupport) {
14963
14984
  appRouterStreamingActionLambdaGroups.push({
@@ -14968,9 +14989,6 @@ async function serverBuild({
14968
14989
  }
14969
14990
  }
14970
14991
  for (const group of appRouteHandlersLambdaGroups) {
14971
- if (!group.isPrerenders) {
14972
- group.isStreaming = true;
14973
- }
14974
14992
  group.isAppRouter = true;
14975
14993
  group.isAppRouteHandler = true;
14976
14994
  }
@@ -14998,24 +15016,32 @@ async function serverBuild({
14998
15016
  apiLambdaGroups: apiLambdaGroups.map((group) => ({
14999
15017
  pages: group.pages,
15000
15018
  isPrerender: group.isPrerenders,
15019
+ isStreaming: group.isStreaming,
15020
+ isExperimentalPPR: group.isExperimentalPPR,
15001
15021
  pseudoLayerBytes: group.pseudoLayerBytes,
15002
15022
  uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
15003
15023
  })),
15004
15024
  pageLambdaGroups: pageLambdaGroups.map((group) => ({
15005
15025
  pages: group.pages,
15006
15026
  isPrerender: group.isPrerenders,
15027
+ isStreaming: group.isStreaming,
15028
+ isExperimentalPPR: group.isExperimentalPPR,
15007
15029
  pseudoLayerBytes: group.pseudoLayerBytes,
15008
15030
  uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
15009
15031
  })),
15010
15032
  appRouterLambdaGroups: appRouterLambdaGroups.map((group) => ({
15011
15033
  pages: group.pages,
15012
15034
  isPrerender: group.isPrerenders,
15035
+ isStreaming: group.isStreaming,
15036
+ isExperimentalPPR: group.isExperimentalPPR,
15013
15037
  pseudoLayerBytes: group.pseudoLayerBytes,
15014
15038
  uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
15015
15039
  })),
15016
15040
  appRouterStreamingPrerenderLambdaGroups: appRouterStreamingActionLambdaGroups.map((group) => ({
15017
15041
  pages: group.pages,
15018
15042
  isPrerender: group.isPrerenders,
15043
+ isStreaming: group.isStreaming,
15044
+ isExperimentalPPR: group.isExperimentalPPR,
15019
15045
  pseudoLayerBytes: group.pseudoLayerBytes,
15020
15046
  uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
15021
15047
  })),
@@ -15023,6 +15049,8 @@ async function serverBuild({
15023
15049
  (group) => ({
15024
15050
  pages: group.pages,
15025
15051
  isPrerender: group.isPrerenders,
15052
+ isStreaming: group.isStreaming,
15053
+ isExperimentalPPR: group.isExperimentalPPR,
15026
15054
  pseudoLayerBytes: group.pseudoLayerBytes,
15027
15055
  uncompressedLayerBytes: group.pseudoLayerUncompressedBytes
15028
15056
  })
@@ -15159,9 +15187,8 @@ async function serverBuild({
15159
15187
  options.layers.push(appNotFoundPsuedoLayer.pseudoLayer);
15160
15188
  }
15161
15189
  const lambda = await createLambdaFromPseudoLayers(options);
15162
- const isPPR = experimental.ppr && group.isAppRouter && !group.isAppRouteHandler;
15163
15190
  let revalidate;
15164
- if (isPPR) {
15191
+ if (group.isExperimentalPPR) {
15165
15192
  if (!options.isStreaming) {
15166
15193
  throw new Error("Invariant: PPR lambda isn't streaming");
15167
15194
  }
@@ -15172,9 +15199,9 @@ async function serverBuild({
15172
15199
  }
15173
15200
  for (const pageFilename of group.pages) {
15174
15201
  const pageName = pageFilename.replace(/\.js$/, "");
15175
- const pagePath = import_path4.default.posix.join("/", pageName);
15176
- const pagePathname = pagePath === "/index" ? "/" : pagePath;
15202
+ const pagePathname = normalizePage(pageName);
15177
15203
  let isPrerender = prerenderRoutes.has(pagePathname);
15204
+ const isRoutePPREnabled = experimentalPPRRoutes.has(pagePathname);
15178
15205
  if (!isPrerender && routesManifest?.i18n) {
15179
15206
  isPrerender = routesManifest.i18n.locales.some((locale) => {
15180
15207
  return prerenderRoutes.has(
@@ -15186,7 +15213,7 @@ async function serverBuild({
15186
15213
  if (group.isActionLambda) {
15187
15214
  outputName = `${outputName}.action`;
15188
15215
  }
15189
- if (isPPR) {
15216
+ if (isRoutePPREnabled) {
15190
15217
  if (!revalidate) {
15191
15218
  throw new Error("Invariant: PPR lambda isn't set");
15192
15219
  }
@@ -15235,6 +15262,12 @@ async function serverBuild({
15235
15262
  }
15236
15263
  console.timeEnd(lambdaCreationLabel);
15237
15264
  }
15265
+ if (isAppPPREnabled) {
15266
+ (0, import_build_utils2.debug)(
15267
+ "experimentalStreamingLambdaPaths",
15268
+ JSON.stringify(Array.from(experimentalStreamingLambdaPaths))
15269
+ );
15270
+ }
15238
15271
  const prerenderRoute = onPrerenderRoute({
15239
15272
  appDir,
15240
15273
  pagesDir,
@@ -15310,7 +15343,7 @@ async function serverBuild({
15310
15343
  bypassToken: prerenderManifest.bypassToken || "",
15311
15344
  isServerMode: true,
15312
15345
  dynamicMiddlewareRouteMap: middleware.dynamicRouteMap,
15313
- experimentalPPRRoutes,
15346
+ isAppPPREnabled,
15314
15347
  hasActionOutputSupport
15315
15348
  }).then(
15316
15349
  (arr) => localizeDynamicRoutes(
@@ -15463,13 +15496,13 @@ async function serverBuild({
15463
15496
  );
15464
15497
  if (lambdas[pathname]) {
15465
15498
  lambdas[`${pathname}.rsc`] = lambdas[pathname];
15466
- if (experimental.ppr) {
15499
+ if (isAppPPREnabled) {
15467
15500
  lambdas[`${pathname}${RSC_PREFETCH_SUFFIX}`] = lambdas[pathname];
15468
15501
  }
15469
15502
  }
15470
15503
  if (edgeFunctions[pathname]) {
15471
15504
  edgeFunctions[`${pathname}.rsc`] = edgeFunctions[pathname];
15472
- if (experimental.ppr) {
15505
+ if (isAppPPREnabled) {
15473
15506
  edgeFunctions[`${pathname}${RSC_PREFETCH_SUFFIX}`] = edgeFunctions[pathname];
15474
15507
  }
15475
15508
  if (hasActionOutputSupport) {
@@ -15482,10 +15515,10 @@ async function serverBuild({
15482
15515
  const rscPrefetchHeader = routesManifest.rsc?.prefetchHeader?.toLowerCase();
15483
15516
  const rscVaryHeader = routesManifest?.rsc?.varyHeader || "RSC, Next-Router-State-Tree, Next-Router-Prefetch";
15484
15517
  const appNotFoundPath = import_path4.default.posix.join(".", entryDirectory, "_not-found");
15485
- if (experimental.ppr && !rscPrefetchHeader) {
15518
+ if (isAppPPREnabled && !rscPrefetchHeader) {
15486
15519
  throw new Error("Invariant: cannot use PPR without 'rsc.prefetchHeader'");
15487
15520
  }
15488
- if (experimental.ppr) {
15521
+ if (isAppPPREnabled) {
15489
15522
  for (const { srcRoute, dataRoute, experimentalPPR } of Object.values(
15490
15523
  prerenderManifest.staticRoutes
15491
15524
  )) {
@@ -15695,7 +15728,7 @@ async function serverBuild({
15695
15728
  // to prevent a local/deploy mismatch
15696
15729
  ...!isCorrectMiddlewareOrder ? middleware.staticRoutes : [],
15697
15730
  ...appDir ? [
15698
- ...rscPrefetchHeader && experimental.ppr ? [
15731
+ ...rscPrefetchHeader && isAppPPREnabled ? [
15699
15732
  {
15700
15733
  src: `^${import_path4.default.posix.join("/", entryDirectory, "/")}`,
15701
15734
  has: [
@@ -16213,10 +16246,14 @@ var build = async ({
16213
16246
  const nextVersionRange = await getNextVersionRange(entryPath);
16214
16247
  const nodeVersion = await (0, import_build_utils3.getNodeVersion)(entryPath, void 0, config, meta);
16215
16248
  const spawnOpts = (0, import_build_utils3.getSpawnOptions)(meta, nodeVersion);
16216
- const { cliType, lockfileVersion } = await (0, import_build_utils3.scanParentDirs)(entryPath);
16249
+ const { cliType, lockfileVersion, packageJson } = await (0, import_build_utils3.scanParentDirs)(
16250
+ entryPath,
16251
+ true
16252
+ );
16217
16253
  spawnOpts.env = (0, import_build_utils3.getEnvForPackageManager)({
16218
16254
  cliType,
16219
16255
  lockfileVersion,
16256
+ packageJsonPackageManager: packageJson?.packageManager,
16220
16257
  nodeVersion,
16221
16258
  env: spawnOpts.env || {}
16222
16259
  });
@@ -17005,6 +17042,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
17005
17042
  continue;
17006
17043
  experimentalPPRRoutes.add(route);
17007
17044
  }
17045
+ const isAppPPREnabled = requiredServerFilesManifest ? requiredServerFilesManifest.config.experimental?.ppr === true || requiredServerFilesManifest.config.experimental?.ppr === "incremental" : false;
17008
17046
  if (requiredServerFilesManifest) {
17009
17047
  if (!routesManifest) {
17010
17048
  throw new Error(
@@ -17052,7 +17090,8 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
17052
17090
  hasIsr404Page,
17053
17091
  hasIsr500Page,
17054
17092
  variantsManifest,
17055
- experimentalPPRRoutes
17093
+ experimentalPPRRoutes,
17094
+ isAppPPREnabled
17056
17095
  });
17057
17096
  }
17058
17097
  const pageKeys = Object.keys(pages);
@@ -17448,7 +17487,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
17448
17487
  canUsePreviewMode,
17449
17488
  bypassToken: prerenderManifest.bypassToken || "",
17450
17489
  isServerMode,
17451
- experimentalPPRRoutes,
17490
+ isAppPPREnabled: false,
17452
17491
  hasActionOutputSupport: false
17453
17492
  }).then(
17454
17493
  (arr) => localizeDynamicRoutes(
@@ -17475,7 +17514,7 @@ More info: http://err.sh/vercel/vercel/next-functions-config-optimized-lambdas`
17475
17514
  canUsePreviewMode,
17476
17515
  bypassToken: prerenderManifest.bypassToken || "",
17477
17516
  isServerMode,
17478
- experimentalPPRRoutes,
17517
+ isAppPPREnabled: false,
17479
17518
  hasActionOutputSupport: false
17480
17519
  }).then(
17481
17520
  (arr) => arr.map((route) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.2.10",
3
+ "version": "4.2.12",
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": "8.1.0",
33
+ "@vercel/build-utils": "8.2.0",
34
34
  "@vercel/routing-utils": "3.1.0",
35
35
  "async-sema": "3.0.1",
36
36
  "buffer-crc32": "0.2.13",