@vercel/next 3.8.8 → 3.9.1

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.
package/dist/index.js CHANGED
@@ -40971,7 +40971,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
40971
40971
  cwd: entryPath,
40972
40972
  });
40973
40973
  let hasLegacyRoutes = false;
40974
- const hasFunctionsConfig = !!config.functions;
40974
+ const hasFunctionsConfig = Boolean(config.functions);
40975
40975
  if (await (0, fs_extra_1.pathExists)(dotNextStatic)) {
40976
40976
  console.warn('WARNING: You should not upload the `.next` directory.');
40977
40977
  }
@@ -41137,7 +41137,8 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
41137
41137
  const requiredServerFilesManifest = isServerMode
41138
41138
  ? await (0, utils_1.getRequiredServerFilesManifest)(entryPath, outputDirectory)
41139
41139
  : false;
41140
- isServerMode = !!requiredServerFilesManifest;
41140
+ isServerMode = Boolean(requiredServerFilesManifest);
41141
+ const functionsConfigManifest = await (0, utils_1.getFunctionsConfigManifest)(entryPath, outputDirectory);
41141
41142
  const routesManifest = await (0, utils_1.getRoutesManifest)(entryPath, outputDirectory, nextVersion);
41142
41143
  const imagesManifest = await (0, utils_1.getImagesManifest)(entryPath, outputDirectory);
41143
41144
  const prerenderManifest = await (0, utils_1.getPrerenderManifest)(entryPath, outputDirectory);
@@ -41709,6 +41710,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
41709
41710
  }
41710
41711
  return (0, server_build_1.serverBuild)({
41711
41712
  config,
41713
+ functionsConfigManifest,
41712
41714
  nextVersion,
41713
41715
  trailingSlash,
41714
41716
  appPathRoutesManifest,
@@ -41876,6 +41878,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
41876
41878
  const initialPageLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
41877
41879
  entryPath,
41878
41880
  config,
41881
+ functionsConfigManifest,
41879
41882
  pages: nonApiPages,
41880
41883
  prerenderRoutes: new Set(),
41881
41884
  pageTraces,
@@ -41891,6 +41894,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
41891
41894
  const initialApiLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
41892
41895
  entryPath,
41893
41896
  config,
41897
+ functionsConfigManifest,
41894
41898
  pages: apiPages,
41895
41899
  prerenderRoutes: new Set(),
41896
41900
  pageTraces,
@@ -43099,7 +43103,7 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
43099
43103
  const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
43100
43104
  const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
43101
43105
  const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
43102
- async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
43106
+ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfigManifest, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
43103
43107
  lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
43104
43108
  const lambdas = {};
43105
43109
  const prerenders = {};
@@ -43141,15 +43145,17 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43141
43145
  };
43142
43146
  const { i18n } = routesManifest;
43143
43147
  const hasPages404 = routesManifest.pages404;
43148
+ let localePrefixed404 = false;
43144
43149
  let static404Page = staticPages[path_1.default.posix.join(entryDirectory, '404')] && hasPages404
43145
43150
  ? path_1.default.posix.join(entryDirectory, '404')
43146
43151
  : staticPages[path_1.default.posix.join(entryDirectory, '_errors/404')]
43147
43152
  ? path_1.default.posix.join(entryDirectory, '_errors/404')
43148
43153
  : undefined;
43149
43154
  if (!static404Page && i18n) {
43150
- static404Page = staticPages[path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')]
43151
- ? path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')
43152
- : undefined;
43155
+ if (staticPages[path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')]) {
43156
+ localePrefixed404 = true;
43157
+ static404Page = path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404');
43158
+ }
43153
43159
  }
43154
43160
  if (!hasStatic500 && i18n) {
43155
43161
  hasStatic500 =
@@ -43473,6 +43479,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43473
43479
  const pageLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
43474
43480
  entryPath: projectDir,
43475
43481
  config,
43482
+ functionsConfigManifest,
43476
43483
  pages: nonApiPages,
43477
43484
  prerenderRoutes,
43478
43485
  pageTraces,
@@ -43487,6 +43494,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43487
43494
  const appRouterLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
43488
43495
  entryPath: projectDir,
43489
43496
  config,
43497
+ functionsConfigManifest,
43490
43498
  pages: appRouterPages,
43491
43499
  prerenderRoutes,
43492
43500
  pageTraces,
@@ -43507,6 +43515,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43507
43515
  const apiLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
43508
43516
  entryPath: projectDir,
43509
43517
  config,
43518
+ functionsConfigManifest,
43510
43519
  pages: apiPages,
43511
43520
  prerenderRoutes,
43512
43521
  pageTraces,
@@ -43635,6 +43644,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43635
43644
  // this is handled in onPrerenderRoute for SSG pages
43636
43645
  if (i18n &&
43637
43646
  !isPrerender &&
43647
+ !group.isAppRouter &&
43638
43648
  (!isCorrectLocaleAPIRoutes ||
43639
43649
  !(pageNoExt === 'api' || pageNoExt.startsWith('api/')))) {
43640
43650
  for (const locale of i18n.locales) {
@@ -43662,6 +43672,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43662
43672
  isSharedLambdas: false,
43663
43673
  canUsePreviewMode,
43664
43674
  static404Page,
43675
+ localePrefixed404,
43665
43676
  hasPages404: routesManifest.pages404,
43666
43677
  isCorrectNotFoundRoutes,
43667
43678
  isEmptyAllowQueryForPrendered,
@@ -43692,7 +43703,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43692
43703
  });
43693
43704
  const isNextDataServerResolving = middleware.staticRoutes.length > 0 &&
43694
43705
  semver_1.default.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
43695
- const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap, inversedAppPathManifest).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes));
43706
+ const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap, inversedAppPathManifest).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes, inversedAppPathManifest));
43696
43707
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
43697
43708
  const normalizeNextDataRoute = (isOverride = false) => {
43698
43709
  return isNextDataServerResolving
@@ -43790,6 +43801,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
43790
43801
  const rscHeader = routesManifest.rsc?.header?.toLowerCase() || '__rsc__';
43791
43802
  const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
43792
43803
  'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
43804
+ const appNotFoundPath = path_1.default.posix.join('.', entryDirectory, '_not-found');
43793
43805
  return {
43794
43806
  wildcard: wildcardConfig,
43795
43807
  images: (0, utils_1.getImagesConfig)(imagesManifest),
@@ -44210,7 +44222,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
44210
44222
  hasIsr404Page ||
44211
44223
  lambdas[path_1.default.posix.join(entryDirectory, '404')]
44212
44224
  ? '/404'
44213
- : '/_error'),
44225
+ : appPathRoutesManifest &&
44226
+ (middleware.edgeFunctions[appNotFoundPath] ||
44227
+ lambdas[appNotFoundPath])
44228
+ ? '/_not-found'
44229
+ : '/_error'),
44214
44230
  status: 404,
44215
44231
  },
44216
44232
  ]),
@@ -44380,7 +44396,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
44380
44396
  return (mod && mod.__esModule) ? mod : { "default": mod };
44381
44397
  };
44382
44398
  Object.defineProperty(exports, "__esModule", ({ value: true }));
44383
- exports.isApiPage = exports.getOperationType = exports.upgradeMiddlewareManifest = exports.getMiddlewareManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getImagesConfig = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = exports.prettyBytes = exports.MIB = exports.KIB = void 0;
44399
+ exports.isApiPage = exports.getOperationType = exports.upgradeMiddlewareManifest = exports.getMiddlewareManifest = exports.getFunctionsConfigManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getImagesConfig = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = exports.prettyBytes = exports.MIB = exports.KIB = void 0;
44384
44400
  const build_utils_1 = __webpack_require__(3445);
44385
44401
  const async_sema_1 = __webpack_require__(7905);
44386
44402
  const buffer_crc32_1 = __importDefault(__webpack_require__(2227));
@@ -44682,7 +44698,7 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
44682
44698
  return routes;
44683
44699
  }
44684
44700
  exports.getDynamicRoutes = getDynamicRoutes;
44685
- function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, isServerMode, isCorrectLocaleAPIRoutes) {
44701
+ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, isServerMode, isCorrectLocaleAPIRoutes, inversedAppPathRoutesManifest) {
44686
44702
  return dynamicRoutes.map((route) => {
44687
44703
  // i18n is already handled for middleware
44688
44704
  if (route.middleware !== undefined || route.middlewarePath !== undefined)
@@ -44695,9 +44711,12 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
44695
44711
  const isBlocking = prerenderManifest.blockingFallbackRoutes[pathname];
44696
44712
  const isApiRoute = pathnameNoPrefix === '/api' || pathnameNoPrefix?.startsWith('/api/');
44697
44713
  const isAutoExport = staticPages[addLocaleOrDefault(pathname, routesManifest).substring(1)];
44714
+ const isAppRoute = inversedAppPathRoutesManifest?.[pathnameNoPrefix || ''];
44698
44715
  const isLocalePrefixed = isFallback || isBlocking || isAutoExport || isServerMode;
44699
44716
  route.src = route.src.replace('^', `^${dynamicPrefix ? `${dynamicPrefix}[/]?` : '[/]?'}(?${isLocalePrefixed ? '<nextLocale>' : ':'}${i18n.locales.map(locale => (0, escape_string_regexp_1.default)(locale)).join('|')})?`);
44700
- if (isLocalePrefixed && !(isCorrectLocaleAPIRoutes && isApiRoute)) {
44717
+ if (isLocalePrefixed &&
44718
+ !(isCorrectLocaleAPIRoutes && isApiRoute) &&
44719
+ !isAppRoute) {
44701
44720
  // ensure destination has locale prefix to match prerender output
44702
44721
  // path so that the prerender object is used
44703
44722
  route.dest = route.dest.replace(`${path_1.default.posix.join('/', entryDirectory, '/')}`, `${path_1.default.posix.join('/', entryDirectory, '$nextLocale', '/')}`);
@@ -45224,23 +45243,28 @@ exports.addLocaleOrDefault = addLocaleOrDefault;
45224
45243
  exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = 250 * exports.MIB;
45225
45244
  const LAMBDA_RESERVED_UNCOMPRESSED_SIZE = 2.5 * exports.MIB;
45226
45245
  const LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * exports.KIB;
45227
- async function getPageLambdaGroups({ entryPath, config, pages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer, initialPseudoLayer, initialPseudoLayerUncompressed, lambdaCompressedByteLimit, internalPages, pageExtensions, }) {
45246
+ async function getPageLambdaGroups({ entryPath, config, functionsConfigManifest, pages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer, initialPseudoLayer, initialPseudoLayerUncompressed, lambdaCompressedByteLimit, internalPages, pageExtensions, }) {
45228
45247
  const groups = [];
45229
45248
  for (const page of pages) {
45230
45249
  const newPages = [...internalPages, page];
45231
45250
  const routeName = normalizePage(page.replace(/\.js$/, ''));
45232
45251
  const isPrerenderRoute = prerenderRoutes.has(routeName);
45233
45252
  let opts = {};
45253
+ if (functionsConfigManifest &&
45254
+ functionsConfigManifest.functions[routeName]) {
45255
+ opts = functionsConfigManifest.functions[routeName];
45256
+ }
45234
45257
  if (config && config.functions) {
45235
45258
  const sourceFile = await getSourceFilePathFromPage({
45236
45259
  workPath: entryPath,
45237
45260
  page,
45238
45261
  pageExtensions,
45239
45262
  });
45240
- opts = await (0, build_utils_1.getLambdaOptionsFromFunction)({
45263
+ const vercelConfigOpts = await (0, build_utils_1.getLambdaOptionsFromFunction)({
45241
45264
  sourceFile,
45242
45265
  config,
45243
45266
  });
45267
+ opts = { ...vercelConfigOpts, ...opts };
45244
45268
  }
45245
45269
  let matchingGroup = groups.find(group => {
45246
45270
  const matches = group.maxDuration === opts.maxDuration &&
@@ -45474,7 +45498,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
45474
45498
  exports.onPrerenderRouteInitial = onPrerenderRouteInitial;
45475
45499
  let prerenderGroup = 1;
45476
45500
  const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFallback, isOmitted, locale, }) => {
45477
- const { appDir, pagesDir, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
45501
+ const { appDir, pagesDir, static404Page, localePrefixed404, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
45478
45502
  if (isBlocking && isFallback) {
45479
45503
  throw new build_utils_1.NowBuildError({
45480
45504
  code: 'NEXT_ISBLOCKING_ISFALLBACK',
@@ -45574,7 +45598,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
45574
45598
  : // Otherwise, the route itself should exist as a static HTML
45575
45599
  // file.
45576
45600
  `${isOmittedOrNotFound
45577
- ? addLocaleOrDefault('/404', routesManifest, locale)
45601
+ ? localePrefixed404
45602
+ ? addLocaleOrDefault('/404', routesManifest, locale)
45603
+ : '/404'
45578
45604
  : routeFileNoExt}.html`),
45579
45605
  });
45580
45606
  }
@@ -45586,7 +45612,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
45586
45612
  fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
45587
45613
  ? appDir
45588
45614
  : pagesDir, `${isOmittedOrNotFound
45589
- ? addLocaleOrDefault('/404.html', routesManifest, locale)
45615
+ ? localePrefixed404
45616
+ ? addLocaleOrDefault('/404.html', routesManifest, locale)
45617
+ : '/404.html'
45590
45618
  : isAppPathRoute
45591
45619
  ? dataRoute
45592
45620
  : routeFileNoExt + '.json'}`),
@@ -46053,7 +46081,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
46053
46081
  shortPath = shortPath.replace(/^pages\//, '');
46054
46082
  }
46055
46083
  else if (shortPath.startsWith('app/') &&
46056
- (shortPath.endsWith('/page') || shortPath.endsWith('/route'))) {
46084
+ (shortPath.endsWith('/page') ||
46085
+ shortPath.endsWith('/route') ||
46086
+ shortPath === 'app/_not-found')) {
46057
46087
  const ogRoute = shortPath.replace(/^app\//, '/');
46058
46088
  shortPath = (appPathRoutesManifest[ogRoute] ||
46059
46089
  shortPath.replace(/(^|\/)(page|route)$/, '')).replace(/^\//, '');
@@ -46111,6 +46141,24 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
46111
46141
  };
46112
46142
  }
46113
46143
  exports.getMiddlewareBundle = getMiddlewareBundle;
46144
+ /**
46145
+ * Attempts to read the functions config manifest from the pre-defined
46146
+ * location. If the manifest can't be found it will resolve to
46147
+ * undefined.
46148
+ */
46149
+ async function getFunctionsConfigManifest(entryPath, outputDirectory) {
46150
+ const functionConfigManifestPath = path_1.default.join(entryPath, outputDirectory, './server/functions-config-manifest.json');
46151
+ const hasManifest = await fs_extra_1.default
46152
+ .access(functionConfigManifestPath)
46153
+ .then(() => true)
46154
+ .catch(() => false);
46155
+ if (!hasManifest) {
46156
+ return;
46157
+ }
46158
+ const manifest = await fs_extra_1.default.readJSON(functionConfigManifestPath);
46159
+ return manifest.version === 1 ? manifest : undefined;
46160
+ }
46161
+ exports.getFunctionsConfigManifest = getFunctionsConfigManifest;
46114
46162
  /**
46115
46163
  * Attempts to read the middleware manifest from the pre-defined
46116
46164
  * location. If the manifest can't be found it will resolve to
@@ -21,7 +21,7 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
21
21
  const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
22
22
  const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
23
23
  const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
24
- async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
24
+ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfigManifest, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
25
25
  lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
26
26
  const lambdas = {};
27
27
  const prerenders = {};
@@ -63,15 +63,17 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
63
63
  };
64
64
  const { i18n } = routesManifest;
65
65
  const hasPages404 = routesManifest.pages404;
66
+ let localePrefixed404 = false;
66
67
  let static404Page = staticPages[path_1.default.posix.join(entryDirectory, '404')] && hasPages404
67
68
  ? path_1.default.posix.join(entryDirectory, '404')
68
69
  : staticPages[path_1.default.posix.join(entryDirectory, '_errors/404')]
69
70
  ? path_1.default.posix.join(entryDirectory, '_errors/404')
70
71
  : undefined;
71
72
  if (!static404Page && i18n) {
72
- static404Page = staticPages[path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')]
73
- ? path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')
74
- : undefined;
73
+ if (staticPages[path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404')]) {
74
+ localePrefixed404 = true;
75
+ static404Page = path_1.default.posix.join(entryDirectory, i18n.defaultLocale, '404');
76
+ }
75
77
  }
76
78
  if (!hasStatic500 && i18n) {
77
79
  hasStatic500 =
@@ -395,6 +397,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
395
397
  const pageLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
396
398
  entryPath: projectDir,
397
399
  config,
400
+ functionsConfigManifest,
398
401
  pages: nonApiPages,
399
402
  prerenderRoutes,
400
403
  pageTraces,
@@ -409,6 +412,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
409
412
  const appRouterLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
410
413
  entryPath: projectDir,
411
414
  config,
415
+ functionsConfigManifest,
412
416
  pages: appRouterPages,
413
417
  prerenderRoutes,
414
418
  pageTraces,
@@ -429,6 +433,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
429
433
  const apiLambdaGroups = await (0, utils_1.getPageLambdaGroups)({
430
434
  entryPath: projectDir,
431
435
  config,
436
+ functionsConfigManifest,
432
437
  pages: apiPages,
433
438
  prerenderRoutes,
434
439
  pageTraces,
@@ -557,6 +562,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
557
562
  // this is handled in onPrerenderRoute for SSG pages
558
563
  if (i18n &&
559
564
  !isPrerender &&
565
+ !group.isAppRouter &&
560
566
  (!isCorrectLocaleAPIRoutes ||
561
567
  !(pageNoExt === 'api' || pageNoExt.startsWith('api/')))) {
562
568
  for (const locale of i18n.locales) {
@@ -584,6 +590,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
584
590
  isSharedLambdas: false,
585
591
  canUsePreviewMode,
586
592
  static404Page,
593
+ localePrefixed404,
587
594
  hasPages404: routesManifest.pages404,
588
595
  isCorrectNotFoundRoutes,
589
596
  isEmptyAllowQueryForPrendered,
@@ -614,7 +621,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
614
621
  });
615
622
  const isNextDataServerResolving = middleware.staticRoutes.length > 0 &&
616
623
  semver_1.default.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
617
- const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap, inversedAppPathManifest).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes));
624
+ const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap, inversedAppPathManifest).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes, inversedAppPathManifest));
618
625
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
619
626
  const normalizeNextDataRoute = (isOverride = false) => {
620
627
  return isNextDataServerResolving
@@ -712,6 +719,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
712
719
  const rscHeader = routesManifest.rsc?.header?.toLowerCase() || '__rsc__';
713
720
  const rscVaryHeader = routesManifest?.rsc?.varyHeader ||
714
721
  'RSC, Next-Router-State-Tree, Next-Router-Prefetch';
722
+ const appNotFoundPath = path_1.default.posix.join('.', entryDirectory, '_not-found');
715
723
  return {
716
724
  wildcard: wildcardConfig,
717
725
  images: (0, utils_1.getImagesConfig)(imagesManifest),
@@ -1132,7 +1140,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
1132
1140
  hasIsr404Page ||
1133
1141
  lambdas[path_1.default.posix.join(entryDirectory, '404')]
1134
1142
  ? '/404'
1135
- : '/_error'),
1143
+ : appPathRoutesManifest &&
1144
+ (middleware.edgeFunctions[appNotFoundPath] ||
1145
+ lambdas[appNotFoundPath])
1146
+ ? '/_not-found'
1147
+ : '/_error'),
1136
1148
  status: 404,
1137
1149
  },
1138
1150
  ]),
package/dist/utils.js CHANGED
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.isApiPage = exports.getOperationType = exports.upgradeMiddlewareManifest = exports.getMiddlewareManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getImagesConfig = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = exports.prettyBytes = exports.MIB = exports.KIB = void 0;
29
+ exports.isApiPage = exports.getOperationType = exports.upgradeMiddlewareManifest = exports.getMiddlewareManifest = exports.getFunctionsConfigManifest = exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = exports.getImagesConfig = exports.getNextConfig = exports.normalizePackageJson = exports.validateEntrypoint = exports.excludeFiles = exports.getPrivateOutputs = exports.updateRouteSrc = exports.getNextServerPath = exports.normalizeIndexOutput = exports.getStaticFiles = exports.onPrerenderRoute = exports.onPrerenderRouteInitial = exports.detectLambdaLimitExceeding = exports.outputFunctionFileSizeInfo = exports.getPageLambdaGroups = exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = exports.addLocaleOrDefault = exports.normalizeLocalePath = exports.getPrerenderManifest = exports.getRequiredServerFilesManifest = exports.getExportStatus = exports.getExportIntent = exports.createLambdaFromPseudoLayers = exports.createPseudoLayer = exports.ExperimentalTraceVersion = exports.collectTracedFiles = exports.getFilesMapFromReasons = exports.filterStaticPages = exports.getImagesManifest = exports.localizeDynamicRoutes = exports.getDynamicRoutes = exports.getRoutesManifest = exports.prettyBytes = exports.MIB = exports.KIB = void 0;
30
30
  const build_utils_1 = require("@vercel/build-utils");
31
31
  const async_sema_1 = require("async-sema");
32
32
  const buffer_crc32_1 = __importDefault(require("buffer-crc32"));
@@ -328,7 +328,7 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
328
328
  return routes;
329
329
  }
330
330
  exports.getDynamicRoutes = getDynamicRoutes;
331
- function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, isServerMode, isCorrectLocaleAPIRoutes) {
331
+ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, isServerMode, isCorrectLocaleAPIRoutes, inversedAppPathRoutesManifest) {
332
332
  return dynamicRoutes.map((route) => {
333
333
  // i18n is already handled for middleware
334
334
  if (route.middleware !== undefined || route.middlewarePath !== undefined)
@@ -341,9 +341,12 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
341
341
  const isBlocking = prerenderManifest.blockingFallbackRoutes[pathname];
342
342
  const isApiRoute = pathnameNoPrefix === '/api' || pathnameNoPrefix?.startsWith('/api/');
343
343
  const isAutoExport = staticPages[addLocaleOrDefault(pathname, routesManifest).substring(1)];
344
+ const isAppRoute = inversedAppPathRoutesManifest?.[pathnameNoPrefix || ''];
344
345
  const isLocalePrefixed = isFallback || isBlocking || isAutoExport || isServerMode;
345
346
  route.src = route.src.replace('^', `^${dynamicPrefix ? `${dynamicPrefix}[/]?` : '[/]?'}(?${isLocalePrefixed ? '<nextLocale>' : ':'}${i18n.locales.map(locale => (0, escape_string_regexp_1.default)(locale)).join('|')})?`);
346
- if (isLocalePrefixed && !(isCorrectLocaleAPIRoutes && isApiRoute)) {
347
+ if (isLocalePrefixed &&
348
+ !(isCorrectLocaleAPIRoutes && isApiRoute) &&
349
+ !isAppRoute) {
347
350
  // ensure destination has locale prefix to match prerender output
348
351
  // path so that the prerender object is used
349
352
  route.dest = route.dest.replace(`${path_1.default.posix.join('/', entryDirectory, '/')}`, `${path_1.default.posix.join('/', entryDirectory, '$nextLocale', '/')}`);
@@ -870,23 +873,28 @@ exports.addLocaleOrDefault = addLocaleOrDefault;
870
873
  exports.MAX_UNCOMPRESSED_LAMBDA_SIZE = 250 * exports.MIB;
871
874
  const LAMBDA_RESERVED_UNCOMPRESSED_SIZE = 2.5 * exports.MIB;
872
875
  const LAMBDA_RESERVED_COMPRESSED_SIZE = 250 * exports.KIB;
873
- async function getPageLambdaGroups({ entryPath, config, pages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer, initialPseudoLayer, initialPseudoLayerUncompressed, lambdaCompressedByteLimit, internalPages, pageExtensions, }) {
876
+ async function getPageLambdaGroups({ entryPath, config, functionsConfigManifest, pages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer, initialPseudoLayer, initialPseudoLayerUncompressed, lambdaCompressedByteLimit, internalPages, pageExtensions, }) {
874
877
  const groups = [];
875
878
  for (const page of pages) {
876
879
  const newPages = [...internalPages, page];
877
880
  const routeName = normalizePage(page.replace(/\.js$/, ''));
878
881
  const isPrerenderRoute = prerenderRoutes.has(routeName);
879
882
  let opts = {};
883
+ if (functionsConfigManifest &&
884
+ functionsConfigManifest.functions[routeName]) {
885
+ opts = functionsConfigManifest.functions[routeName];
886
+ }
880
887
  if (config && config.functions) {
881
888
  const sourceFile = await getSourceFilePathFromPage({
882
889
  workPath: entryPath,
883
890
  page,
884
891
  pageExtensions,
885
892
  });
886
- opts = await (0, build_utils_1.getLambdaOptionsFromFunction)({
893
+ const vercelConfigOpts = await (0, build_utils_1.getLambdaOptionsFromFunction)({
887
894
  sourceFile,
888
895
  config,
889
896
  });
897
+ opts = { ...vercelConfigOpts, ...opts };
890
898
  }
891
899
  let matchingGroup = groups.find(group => {
892
900
  const matches = group.maxDuration === opts.maxDuration &&
@@ -1120,7 +1128,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
1120
1128
  exports.onPrerenderRouteInitial = onPrerenderRouteInitial;
1121
1129
  let prerenderGroup = 1;
1122
1130
  const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFallback, isOmitted, locale, }) => {
1123
- const { appDir, pagesDir, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
1131
+ const { appDir, pagesDir, static404Page, localePrefixed404, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
1124
1132
  if (isBlocking && isFallback) {
1125
1133
  throw new build_utils_1.NowBuildError({
1126
1134
  code: 'NEXT_ISBLOCKING_ISFALLBACK',
@@ -1220,7 +1228,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1220
1228
  : // Otherwise, the route itself should exist as a static HTML
1221
1229
  // file.
1222
1230
  `${isOmittedOrNotFound
1223
- ? addLocaleOrDefault('/404', routesManifest, locale)
1231
+ ? localePrefixed404
1232
+ ? addLocaleOrDefault('/404', routesManifest, locale)
1233
+ : '/404'
1224
1234
  : routeFileNoExt}.html`),
1225
1235
  });
1226
1236
  }
@@ -1232,7 +1242,9 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1232
1242
  fsPath: path_1.default.join(isAppPathRoute && !isOmittedOrNotFound && appDir
1233
1243
  ? appDir
1234
1244
  : pagesDir, `${isOmittedOrNotFound
1235
- ? addLocaleOrDefault('/404.html', routesManifest, locale)
1245
+ ? localePrefixed404
1246
+ ? addLocaleOrDefault('/404.html', routesManifest, locale)
1247
+ : '/404.html'
1236
1248
  : isAppPathRoute
1237
1249
  ? dataRoute
1238
1250
  : routeFileNoExt + '.json'}`),
@@ -1699,7 +1711,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1699
1711
  shortPath = shortPath.replace(/^pages\//, '');
1700
1712
  }
1701
1713
  else if (shortPath.startsWith('app/') &&
1702
- (shortPath.endsWith('/page') || shortPath.endsWith('/route'))) {
1714
+ (shortPath.endsWith('/page') ||
1715
+ shortPath.endsWith('/route') ||
1716
+ shortPath === 'app/_not-found')) {
1703
1717
  const ogRoute = shortPath.replace(/^app\//, '/');
1704
1718
  shortPath = (appPathRoutesManifest[ogRoute] ||
1705
1719
  shortPath.replace(/(^|\/)(page|route)$/, '')).replace(/^\//, '');
@@ -1757,6 +1771,24 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1757
1771
  };
1758
1772
  }
1759
1773
  exports.getMiddlewareBundle = getMiddlewareBundle;
1774
+ /**
1775
+ * Attempts to read the functions config manifest from the pre-defined
1776
+ * location. If the manifest can't be found it will resolve to
1777
+ * undefined.
1778
+ */
1779
+ async function getFunctionsConfigManifest(entryPath, outputDirectory) {
1780
+ const functionConfigManifestPath = path_1.default.join(entryPath, outputDirectory, './server/functions-config-manifest.json');
1781
+ const hasManifest = await fs_extra_1.default
1782
+ .access(functionConfigManifestPath)
1783
+ .then(() => true)
1784
+ .catch(() => false);
1785
+ if (!hasManifest) {
1786
+ return;
1787
+ }
1788
+ const manifest = await fs_extra_1.default.readJSON(functionConfigManifestPath);
1789
+ return manifest.version === 1 ? manifest : undefined;
1790
+ }
1791
+ exports.getFunctionsConfigManifest = getFunctionsConfigManifest;
1760
1792
  /**
1761
1793
  * Attempts to read the middleware manifest from the pre-defined
1762
1794
  * location. If the manifest can't be found it will resolve to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.8.8",
3
+ "version": "3.9.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -26,7 +26,7 @@
26
26
  "@types/semver": "6.0.0",
27
27
  "@types/text-table": "0.2.1",
28
28
  "@types/webpack-sources": "3.2.0",
29
- "@vercel/build-utils": "6.8.0",
29
+ "@vercel/build-utils": "6.8.2",
30
30
  "@vercel/nft": "0.22.5",
31
31
  "@vercel/routing-utils": "2.2.1",
32
32
  "async-sema": "3.0.1",