@vercel/next 4.0.1 → 4.0.2

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.
@@ -206,10 +206,17 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfi
206
206
  // for notFound GS(S)P support
207
207
  if (i18n) {
208
208
  for (const locale of i18n.locales) {
209
- const static404File = staticPages[path_1.default.posix.join(entryDirectory, locale, '/404')] ||
210
- new build_utils_1.FileFsRef({
209
+ let static404File = staticPages[path_1.default.posix.join(entryDirectory, locale, '/404')];
210
+ if (!static404File) {
211
+ static404File = new build_utils_1.FileFsRef({
211
212
  fsPath: path_1.default.join(pagesDir, locale, '/404.html'),
212
213
  });
214
+ if (!fs_extra_1.default.existsSync(static404File.fsPath)) {
215
+ static404File = new build_utils_1.FileFsRef({
216
+ fsPath: path_1.default.join(pagesDir, '/404.html'),
217
+ });
218
+ }
219
+ }
213
220
  requiredFiles[path_1.default.relative(baseDir, static404File.fsPath)] =
214
221
  static404File;
215
222
  }
@@ -622,7 +629,25 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfi
622
629
  });
623
630
  const isNextDataServerResolving = middleware.staticRoutes.length > 0 &&
624
631
  semver_1.default.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
625
- 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));
632
+ const dynamicRoutes = await (0, utils_1.getDynamicRoutes)(entryPath, entryDirectory, dynamicPages, false, routesManifest, omittedPrerenderRoutes, canUsePreviewMode, prerenderManifest.bypassToken || '', true, middleware.dynamicRouteMap).then(arr => (0, utils_1.localizeDynamicRoutes)(arr, dynamicPrefix, entryDirectory, staticPages, prerenderManifest, routesManifest, true, isCorrectLocaleAPIRoutes, inversedAppPathManifest));
633
+ const pagesPlaceholderRscEntries = {};
634
+ if (appDir) {
635
+ // since we attempt to rewrite all paths to an .rsc variant,
636
+ // we need to create dummy rsc outputs for all pages entries
637
+ // this is so that an RSC request to a `pages` entry will match
638
+ // rather than falling back to a catchall `app` entry
639
+ // on the nextjs side, invalid RSC response payloads will correctly trigger an mpa navigation
640
+ const pagesManifest = path_1.default.join(entryPath, outputDirectory, `server/pages-manifest.json`);
641
+ const pagesData = await fs_extra_1.default.readJSON(pagesManifest);
642
+ const pagesEntries = Object.keys(pagesData);
643
+ for (const page of pagesEntries) {
644
+ const pathName = page.startsWith('/') ? page.slice(1) : page;
645
+ pagesPlaceholderRscEntries[`${pathName}.rsc`] = new build_utils_1.FileBlob({
646
+ data: '{}',
647
+ contentType: 'application/json',
648
+ });
649
+ }
650
+ }
626
651
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
627
652
  const normalizeNextDataRoute = (isOverride = false) => {
628
653
  return isNextDataServerResolving
@@ -708,7 +733,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfi
708
733
  if (ogRoute.endsWith('/route')) {
709
734
  continue;
710
735
  }
711
- route = path_1.default.posix.join('./', entryDirectory, route === '/' ? '/index' : route);
736
+ route = (0, utils_1.normalizeIndexOutput)(path_1.default.posix.join('./', entryDirectory, route === '/' ? '/index' : route), true);
712
737
  if (lambdas[route]) {
713
738
  lambdas[`${route}.rsc`] = lambdas[route];
714
739
  }
@@ -729,6 +754,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfi
729
754
  ...publicDirectoryFiles,
730
755
  ...lambdas,
731
756
  ...appRscPrefetches,
757
+ ...pagesPlaceholderRscEntries,
732
758
  // Prerenders may override Lambdas -- this is an intentional behavior.
733
759
  ...prerenders,
734
760
  ...staticPages,
@@ -1023,62 +1049,17 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, functionsConfi
1023
1049
  },
1024
1050
  ]
1025
1051
  : []),
1026
- ...(appDir
1027
- ? [
1028
- // check routes that end in `.rsc` to see if a page with the resulting name (sans-.rsc) exists in the filesystem
1029
- // if so, we want to match that page instead. (This matters when prefetching a pages route while on an appdir route)
1030
- {
1031
- src: `^${path_1.default.posix.join('/', entryDirectory, '/(.*)\\.rsc$')}`,
1032
- dest: path_1.default.posix.join('/', entryDirectory, '/$1'),
1033
- has: [
1034
- {
1035
- type: 'header',
1036
- key: rscHeader,
1037
- },
1038
- ],
1039
- ...(rscPrefetchHeader
1040
- ? {
1041
- missing: [
1042
- {
1043
- type: 'header',
1044
- key: rscPrefetchHeader,
1045
- },
1046
- ],
1047
- }
1048
- : {}),
1049
- check: true,
1050
- },
1051
- ]
1052
- : []),
1053
1052
  // These need to come before handle: miss or else they are grouped
1054
1053
  // with that routing section
1055
1054
  ...afterFilesRewrites,
1056
- ...(appDir
1057
- ? [
1058
- // rewrite route back to `.rsc`, but skip checking fs
1059
- {
1060
- src: `^${path_1.default.posix.join('/', entryDirectory, '/((?!.+\\.rsc).+?)(?:/)?$')}`,
1061
- has: [
1062
- {
1063
- type: 'header',
1064
- key: rscHeader,
1065
- },
1066
- ],
1067
- dest: path_1.default.posix.join('/', entryDirectory, '/$1.rsc'),
1068
- headers: { vary: rscVaryHeader },
1069
- continue: true,
1070
- override: true,
1071
- },
1072
- ]
1073
- : []),
1074
- // make sure 404 page is used when a directory is matched without
1075
- // an index page
1076
1055
  { handle: 'resource' },
1077
1056
  ...fallbackRewrites,
1057
+ // make sure 404 page is used when a directory is matched without
1058
+ // an index page
1078
1059
  { src: path_1.default.posix.join('/', entryDirectory, '.*'), status: 404 },
1060
+ { handle: 'miss' },
1079
1061
  // We need to make sure to 404 for /_next after handle: miss since
1080
1062
  // handle: miss is called before rewrites and to prevent rewriting /_next
1081
- { handle: 'miss' },
1082
1063
  {
1083
1064
  src: path_1.default.posix.join('/', entryDirectory, '_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media)/.+'),
1084
1065
  status: 404,
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.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;
29
+ exports.isApiPage = exports.getOperationType = exports.upgradeMiddlewareManifest = exports.getMiddlewareManifest = exports.getFunctionsConfigManifest = exports.getMiddlewareBundle = exports.normalizeEdgeFunctionPath = 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"));
@@ -194,7 +194,7 @@ async function getRoutesManifest(entryPath, outputDirectory, nextVersion) {
194
194
  return routesManifest;
195
195
  }
196
196
  exports.getRoutesManifest = getRoutesManifest;
197
- async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev, routesManifest, omittedRoutes, canUsePreviewMode, bypassToken, isServerMode, dynamicMiddlewareRouteMap, appPathRoutesManifest) {
197
+ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev, routesManifest, omittedRoutes, canUsePreviewMode, bypassToken, isServerMode, dynamicMiddlewareRouteMap) {
198
198
  if (routesManifest) {
199
199
  switch (routesManifest.version) {
200
200
  case 1:
@@ -253,13 +253,11 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
253
253
  },
254
254
  ];
255
255
  }
256
- if (appPathRoutesManifest?.[page]) {
257
- routes.push({
258
- ...route,
259
- src: route.src.replace(new RegExp((0, escape_string_regexp_1.default)('(?:/)?$')), '(?:\\.rsc)(?:/)?$'),
260
- dest: route.dest?.replace(/($|\?)/, '.rsc$1'),
261
- });
262
- }
256
+ routes.push({
257
+ ...route,
258
+ src: route.src.replace(new RegExp((0, escape_string_regexp_1.default)('(?:/)?$')), '(?:\\.rsc)(?:/)?$'),
259
+ dest: route.dest?.replace(/($|\?)/, '.rsc$1'),
260
+ });
263
261
  routes.push(route);
264
262
  continue;
265
263
  }
@@ -1503,7 +1501,7 @@ async function getStaticFiles(entryPath, entryDirectory, outputDirectory) {
1503
1501
  }
1504
1502
  exports.getStaticFiles = getStaticFiles;
1505
1503
  function normalizeIndexOutput(outputName, isServerMode) {
1506
- if (outputName !== '/index' && isServerMode) {
1504
+ if (outputName !== 'index' && outputName !== '/index' && isServerMode) {
1507
1505
  return outputName.replace(/\/index$/, '');
1508
1506
  }
1509
1507
  return outputName;
@@ -1597,6 +1595,21 @@ function normalizeRegions(regions) {
1597
1595
  }
1598
1596
  return newRegions;
1599
1597
  }
1598
+ function normalizeEdgeFunctionPath(shortPath, appPathRoutesManifest) {
1599
+ if (shortPath.startsWith('app/') &&
1600
+ (shortPath.endsWith('/page') ||
1601
+ shortPath.endsWith('/route') ||
1602
+ shortPath === 'app/_not-found')) {
1603
+ const ogRoute = shortPath.replace(/^app\//, '/');
1604
+ shortPath = (appPathRoutesManifest[ogRoute] ||
1605
+ shortPath.replace(/(^|\/)(page|route)$/, '')).replace(/^\//, '');
1606
+ if (!shortPath || shortPath === '/') {
1607
+ shortPath = 'index';
1608
+ }
1609
+ }
1610
+ return shortPath;
1611
+ }
1612
+ exports.normalizeEdgeFunctionPath = normalizeEdgeFunctionPath;
1600
1613
  async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, prerenderBypassToken, nextVersion, appPathRoutesManifest, }) {
1601
1614
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
1602
1615
  const sortedFunctions = [
@@ -1713,21 +1726,11 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1713
1726
  if (shortPath.startsWith('pages/')) {
1714
1727
  shortPath = shortPath.replace(/^pages\//, '');
1715
1728
  }
1716
- else if (shortPath.startsWith('app/') &&
1717
- (shortPath.endsWith('/page') ||
1718
- shortPath.endsWith('/route') ||
1719
- shortPath === 'app/_not-found')) {
1720
- const ogRoute = shortPath.replace(/^app\//, '/');
1721
- shortPath = (appPathRoutesManifest[ogRoute] ||
1722
- shortPath.replace(/(^|\/)(page|route)$/, '')).replace(/^\//, '');
1723
- if (!shortPath || shortPath === '/') {
1724
- shortPath = 'index';
1725
- }
1729
+ else {
1730
+ shortPath = normalizeEdgeFunctionPath(shortPath, appPathRoutesManifest);
1726
1731
  }
1727
1732
  if (routesManifest?.basePath) {
1728
- shortPath = path_1.default.posix
1729
- .join(routesManifest.basePath, shortPath)
1730
- .replace(/^\//, '');
1733
+ shortPath = normalizeIndexOutput(path_1.default.posix.join('./', routesManifest?.basePath, shortPath.replace(/^\//, '')), true);
1731
1734
  }
1732
1735
  worker.edgeFunction.name = shortPath;
1733
1736
  source.edgeFunctions[shortPath] = worker.edgeFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
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": "7.0.0",
29
+ "@vercel/build-utils": "7.1.1",
30
30
  "@vercel/nft": "0.22.5",
31
31
  "@vercel/routing-utils": "3.0.0",
32
32
  "async-sema": "3.0.1",
@@ -45,7 +45,7 @@
45
45
  "ndjson": "2.0.0",
46
46
  "pretty-bytes": "5.3.0",
47
47
  "resolve-from": "5.0.0",
48
- "semver": "6.1.1",
48
+ "semver": "6.3.1",
49
49
  "set-cookie-parser": "2.4.6",
50
50
  "source-map": "0.7.3",
51
51
  "test-listen": "1.1.0",