@vercel/next 2.9.1-canary.0 → 3.0.0

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.
@@ -18,7 +18,6 @@ const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
18
18
  // related PR: https://github.com/vercel/next.js/pull/30046
19
19
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
20
20
  async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
21
- var _a, _b, _c, _d;
22
21
  const lambdas = {};
23
22
  const prerenders = {};
24
23
  const lambdaPageKeys = Object.keys(lambdaPages);
@@ -274,7 +273,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
274
273
  cache: traceCache,
275
274
  processCwd: requiredServerFilesManifest.appDir || entryPath,
276
275
  });
277
- traceResult.esmFileList.forEach(file => traceResult === null || traceResult === void 0 ? void 0 : traceResult.fileList.add(file));
276
+ traceResult.esmFileList.forEach(file => traceResult?.fileList.add(file));
278
277
  parentFilesMap = (0, utils_1.getFilesMapFromReasons)(traceResult.fileList, traceResult.reasons);
279
278
  }
280
279
  for (const page of mergedPageKeys) {
@@ -298,11 +297,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
298
297
  reasons = new Map();
299
298
  }
300
299
  else {
301
- fileList = Array.from((parentFilesMap === null || parentFilesMap === void 0 ? void 0 : parentFilesMap.get(path_1.default.relative(baseDir, lambdaPages[page].fsPath))) || []);
300
+ fileList = Array.from(parentFilesMap?.get(path_1.default.relative(baseDir, lambdaPages[page].fsPath)) || []);
302
301
  if (!fileList) {
303
302
  throw new Error(`Invariant: Failed to trace ${page}, missing fileList`);
304
303
  }
305
- reasons = (traceResult === null || traceResult === void 0 ? void 0 : traceResult.reasons) || new Map();
304
+ reasons = traceResult?.reasons || new Map();
306
305
  }
307
306
  await Promise.all(fileList.map((0, utils_1.collectTracedFiles)(baseDir, lstatResults, lstatSema, reasons, tracedFiles)));
308
307
  pageTraces[page] = tracedFiles;
@@ -318,7 +317,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
318
317
  const file = initialPseudoLayer.pseudoLayer[cur];
319
318
  return prev + file.uncompressedSize || 0;
320
319
  }, 0);
321
- const pageExtensions = (_a = requiredServerFilesManifest.config) === null || _a === void 0 ? void 0 : _a.pageExtensions;
320
+ const pageExtensions = requiredServerFilesManifest.config?.pageExtensions;
322
321
  const pageLambdaGroups = await (0, utils_1.getPageLambdaGroups)(requiredServerFilesManifest.appDir || entryPath, config, nonApiPages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer.pseudoLayer, initialPseudoLayer.pseudoLayerBytes, initialPseudoLayerSize, lambdaCompressedByteLimit, internalPages, pageExtensions);
323
322
  const apiLambdaGroups = await (0, utils_1.getPageLambdaGroups)(requiredServerFilesManifest.appDir || entryPath, config, apiPages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer.pseudoLayer, initialPseudoLayer.pseudoLayerBytes, initialPseudoLayerSize, lambdaCompressedByteLimit, internalPages);
324
323
  (0, build_utils_1.debug)(JSON.stringify({
@@ -358,7 +357,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
358
357
  for (const page of group.pages) {
359
358
  const pageNoExt = page.replace(/\.js$/, '');
360
359
  let isPrerender = prerenderRoutes.has(path_1.default.join('/', pageNoExt === 'index' ? '' : pageNoExt));
361
- if (!isPrerender && (routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n)) {
360
+ if (!isPrerender && routesManifest?.i18n) {
362
361
  isPrerender = routesManifest.i18n.locales.some(locale => {
363
362
  return prerenderRoutes.has(path_1.default.join('/', locale, pageNoExt === 'index' ? '' : pageNoExt));
364
363
  });
@@ -405,7 +404,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
405
404
  });
406
405
  }
407
406
  prerenderRoutes.forEach(route => {
408
- if (routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) {
407
+ if (routesManifest?.i18n) {
409
408
  route = (0, utils_1.normalizeLocalePath)(route, routesManifest.i18n.locales).pathname;
410
409
  }
411
410
  delete lambdas[path_1.default.join('.', entryDirectory, route === '/' ? 'index' : route)];
@@ -418,7 +417,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
418
417
  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));
419
418
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
420
419
  const notFoundPreviewRoutes = [];
421
- if (((_b = prerenderManifest.notFoundRoutes) === null || _b === void 0 ? void 0 : _b.length) > 0 && canUsePreviewMode) {
420
+ if (prerenderManifest.notFoundRoutes?.length > 0 && canUsePreviewMode) {
422
421
  // we combine routes into one src here to reduce the number of needed
423
422
  // routes since only the status is being modified and we don't want
424
423
  // to exceed the routes limit
@@ -444,7 +443,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
444
443
  for (let i = 0; i < prerenderManifest.notFoundRoutes.length; i++) {
445
444
  const route = prerenderManifest.notFoundRoutes[i];
446
445
  const isLastRoute = i === prerenderManifest.notFoundRoutes.length - 1;
447
- if (((_c = prerenderManifest.staticRoutes[route]) === null || _c === void 0 ? void 0 : _c.initialRevalidate) === false) {
446
+ if (prerenderManifest.staticRoutes[route]?.initialRevalidate === false) {
448
447
  if (currentRouteSrc.length + route.length + 1 >= 4096) {
449
448
  pushRoute(currentRouteSrc);
450
449
  currentRouteSrc = starterRouteSrc;
@@ -459,7 +458,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
459
458
  }
460
459
  return {
461
460
  wildcard: wildcardConfig,
462
- images: ((_d = imagesManifest === null || imagesManifest === void 0 ? void 0 : imagesManifest.images) === null || _d === void 0 ? void 0 : _d.loader) === 'default'
461
+ images: imagesManifest?.images?.loader === 'default'
463
462
  ? {
464
463
  domains: imagesManifest.images.domains,
465
464
  sizes: imagesManifest.images.sizes,
@@ -625,7 +624,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
625
624
  { handle: 'filesystem' },
626
625
  // ensure the basePath prefixed _next/image is rewritten to the root
627
626
  // _next/image path
628
- ...((routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.basePath)
627
+ ...(routesManifest?.basePath
629
628
  ? [
630
629
  {
631
630
  src: path_1.default.join('/', entryDirectory, '_next/image/?'),
@@ -676,7 +675,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
676
675
  ? []
677
676
  : [
678
677
  {
679
- src: `${path_1.default.join('/', entryDirectory, '/')}(?:${i18n === null || i18n === void 0 ? void 0 : i18n.locales.map(locale => (0, escape_string_regexp_1.default)(locale)).join('|')})/(.*)`,
678
+ src: `${path_1.default.join('/', entryDirectory, '/')}(?:${i18n?.locales
679
+ .map(locale => (0, escape_string_regexp_1.default)(locale))
680
+ .join('|')})/(.*)`,
680
681
  dest: '/$1',
681
682
  check: true,
682
683
  },
@@ -69,7 +69,7 @@ async function getSourceMap(content, fullFilePath) {
69
69
  }
70
70
  return convert_source_map_1.default.fromComment(content).toObject();
71
71
  }
72
- catch (_a) {
72
+ catch {
73
73
  return null;
74
74
  }
75
75
  }
package/dist/utils.js CHANGED
@@ -156,8 +156,7 @@ async function getRoutesManifest(entryPath, outputDirectory, nextVersion) {
156
156
  code: 'NEXT_NO_ROUTES_MANIFEST',
157
157
  });
158
158
  }
159
- // eslint-disable-next-line @typescript-eslint/no-var-requires
160
- const routesManifest = require(pathRoutesManifest);
159
+ const routesManifest = await fs_extra_1.default.readJSON(pathRoutesManifest);
161
160
  // remove temporary array based routeKeys from v1/v2 of routes
162
161
  // manifest since it can result in invalid routes
163
162
  for (const route of routesManifest.dataRoutes || []) {
@@ -181,23 +180,23 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
181
180
  case 1:
182
181
  case 2: {
183
182
  return routesManifest.dynamicRoutes
184
- .filter(({ page }) => canUsePreviewMode || !(omittedRoutes === null || omittedRoutes === void 0 ? void 0 : omittedRoutes.has(page)))
183
+ .filter(({ page }) => canUsePreviewMode || !omittedRoutes?.has(page))
185
184
  .map(({ page, regex }) => {
186
185
  return {
187
186
  src: regex,
188
187
  dest: !isDev ? path_1.default.join('/', entryDirectory, page) : page,
189
188
  check: true,
190
- status: canUsePreviewMode && (omittedRoutes === null || omittedRoutes === void 0 ? void 0 : omittedRoutes.has(page)) ? 404 : undefined,
189
+ status: canUsePreviewMode && omittedRoutes?.has(page) ? 404 : undefined,
191
190
  };
192
191
  });
193
192
  }
194
193
  case 3:
195
194
  case 4: {
196
195
  return routesManifest.dynamicRoutes
197
- .filter(({ page }) => canUsePreviewMode || !(omittedRoutes === null || omittedRoutes === void 0 ? void 0 : omittedRoutes.has(page)))
196
+ .filter(({ page }) => canUsePreviewMode || !omittedRoutes?.has(page))
198
197
  .map(params => {
199
198
  if ('isMiddleware' in params) {
200
- const route = dynamicMiddlewareRouteMap === null || dynamicMiddlewareRouteMap === void 0 ? void 0 : dynamicMiddlewareRouteMap.get(params.page);
199
+ const route = dynamicMiddlewareRouteMap?.get(params.page);
201
200
  if (!route) {
202
201
  throw new Error(`Could not find dynamic middleware route for ${params.page}`);
203
202
  }
@@ -215,7 +214,7 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
215
214
  if (!isServerMode) {
216
215
  route.check = true;
217
216
  }
218
- if (isServerMode && canUsePreviewMode && (omittedRoutes === null || omittedRoutes === void 0 ? void 0 : omittedRoutes.has(page))) {
217
+ if (isServerMode && canUsePreviewMode && omittedRoutes?.has(page)) {
219
218
  // only match this route when in preview mode so
220
219
  // preview works for non-prerender fallback: false pages
221
220
  route.has = [
@@ -252,7 +251,8 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
252
251
  let getRouteRegex = undefined;
253
252
  let getSortedRoutes;
254
253
  try {
255
- ({ getRouteRegex, getSortedRoutes } = require((0, resolve_from_1.default)(entryPath, 'next-server/dist/lib/router/utils')));
254
+ // NOTE: `eval('require')` is necessary to avoid bad transpilation to `__webpack_require__`
255
+ ({ getRouteRegex, getSortedRoutes } = eval('require')((0, resolve_from_1.default)(entryPath, 'next-server/dist/lib/router/utils')));
256
256
  if (typeof getRouteRegex !== 'function') {
257
257
  getRouteRegex = undefined;
258
258
  }
@@ -260,7 +260,8 @@ async function getDynamicRoutes(entryPath, entryDirectory, dynamicPages, isDev,
260
260
  catch (_) { } // eslint-disable-line no-empty
261
261
  if (!getRouteRegex || !getSortedRoutes) {
262
262
  try {
263
- ({ getRouteRegex, getSortedRoutes } = require((0, resolve_from_1.default)(entryPath, 'next/dist/next-server/lib/router/utils')));
263
+ // NOTE: `eval('require')` is necessary to avoid bad transpilation to `__webpack_require__`
264
+ ({ getRouteRegex, getSortedRoutes } = eval('require')((0, resolve_from_1.default)(entryPath, 'next/dist/next-server/lib/router/utils')));
264
265
  if (typeof getRouteRegex !== 'function') {
265
266
  getRouteRegex = undefined;
266
267
  }
@@ -302,10 +303,10 @@ function localizeDynamicRoutes(dynamicRoutes, dynamicPrefix, entryDirectory, sta
302
303
  const { i18n } = routesManifest || {};
303
304
  if (i18n) {
304
305
  const { pathname } = url_1.default.parse(route.dest);
305
- const pathnameNoPrefix = pathname === null || pathname === void 0 ? void 0 : pathname.replace(dynamicPrefix, '');
306
+ const pathnameNoPrefix = pathname?.replace(dynamicPrefix, '');
306
307
  const isFallback = prerenderManifest.fallbackRoutes[pathname];
307
308
  const isBlocking = prerenderManifest.blockingFallbackRoutes[pathname];
308
- const isApiRoute = pathnameNoPrefix === '/api' || (pathnameNoPrefix === null || pathnameNoPrefix === void 0 ? void 0 : pathnameNoPrefix.startsWith('/api/'));
309
+ const isApiRoute = pathnameNoPrefix === '/api' || pathnameNoPrefix?.startsWith('/api/');
309
310
  const isAutoExport = staticPages[addLocaleOrDefault(pathname, routesManifest).substring(1)];
310
311
  const isLocalePrefixed = isFallback || isBlocking || isAutoExport || isServerMode;
311
312
  route.src = route.src.replace('^', `^${dynamicPrefix ? `${dynamicPrefix}[/]?` : '[/]?'}(?${isLocalePrefixed ? '<nextLocale>' : ':'}${i18n.locales.map(locale => (0, escape_string_regexp_1.default)(locale)).join('|')})?`);
@@ -331,17 +332,14 @@ async function getImagesManifest(entryPath, outputDirectory) {
331
332
  if (!hasImagesManifest) {
332
333
  return undefined;
333
334
  }
334
- // eslint-disable-next-line @typescript-eslint/no-var-requires
335
- const imagesManifest = require(pathImagesManifest);
336
- return imagesManifest;
335
+ return fs_extra_1.default.readJson(pathImagesManifest);
337
336
  }
338
337
  exports.getImagesManifest = getImagesManifest;
339
338
  function filterStaticPages(staticPageFiles, dynamicPages, entryDirectory, htmlContentType, prerenderManifest, routesManifest) {
340
339
  const staticPages = {};
341
340
  Object.keys(staticPageFiles).forEach((page) => {
342
- var _a;
343
341
  const pathname = page.replace(/\.html$/, '');
344
- const routeName = normalizeLocalePath(normalizePage(pathname), (_a = routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) === null || _a === void 0 ? void 0 : _a.locales).pathname;
342
+ const routeName = normalizeLocalePath(normalizePage(pathname), routesManifest?.i18n?.locales).pathname;
345
343
  // Prerendered routes emit a `.html` file but should not be treated as a
346
344
  // static page.
347
345
  // Lazily prerendered routes have a fallback `.html` file on newer
@@ -377,11 +375,11 @@ function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
377
375
  parentFiles = new Set();
378
376
  parentFilesMap.set(parent, parentFiles);
379
377
  }
380
- if (!(ignoreFn === null || ignoreFn === void 0 ? void 0 : ignoreFn(file, parent))) {
378
+ if (!ignoreFn?.(file, parent)) {
381
379
  parentFiles.add(file);
382
380
  }
383
381
  const parentReason = reasons.get(parent);
384
- if (parentReason === null || parentReason === void 0 ? void 0 : parentReason.parents) {
382
+ if (parentReason?.parents) {
385
383
  propagateToParents(parentReason.parents, file, seen);
386
384
  }
387
385
  }
@@ -389,7 +387,7 @@ function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
389
387
  }
390
388
  for (const file of fileList) {
391
389
  const reason = reasons.get(file);
392
- const isInitial = (reason === null || reason === void 0 ? void 0 : reason.type.length) === 1 && reason.type.includes('initial');
390
+ const isInitial = reason?.type.length === 1 && reason.type.includes('initial');
393
391
  if (!reason ||
394
392
  !reason.parents ||
395
393
  (isInitial && reason.parents.size === 0)) {
@@ -773,7 +771,7 @@ function normalizeLocalePath(pathname, locales) {
773
771
  }
774
772
  exports.normalizeLocalePath = normalizeLocalePath;
775
773
  function addLocaleOrDefault(pathname, routesManifest, locale) {
776
- if (!(routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n))
774
+ if (!routesManifest?.i18n)
777
775
  return pathname;
778
776
  if (!locale)
779
777
  locale = routesManifest.i18n.defaultLocale;
@@ -812,10 +810,9 @@ async function getPageLambdaGroups(entryPath, config, pages, prerenderRoutes, pa
812
810
  let newTracedFilesUncompressedSize = group.pseudoLayerUncompressedBytes;
813
811
  for (const newPage of newPages) {
814
812
  Object.keys(pageTraces[newPage] || {}).map(file => {
815
- var _a;
816
813
  if (!group.pseudoLayer[file]) {
817
814
  const item = tracedPseudoLayer[file];
818
- newTracedFilesSize += ((_a = item.compBuffer) === null || _a === void 0 ? void 0 : _a.byteLength) || 0;
815
+ newTracedFilesSize += item.compBuffer?.byteLength || 0;
819
816
  newTracedFilesUncompressedSize += item.uncompressedSize || 0;
820
817
  }
821
818
  });
@@ -848,9 +845,8 @@ async function getPageLambdaGroups(entryPath, config, pages, prerenderRoutes, pa
848
845
  }
849
846
  for (const newPage of newPages) {
850
847
  Object.keys(pageTraces[newPage] || {}).map(file => {
851
- var _a;
852
848
  const pseudoItem = tracedPseudoLayer[file];
853
- const compressedSize = ((_a = pseudoItem === null || pseudoItem === void 0 ? void 0 : pseudoItem.compBuffer) === null || _a === void 0 ? void 0 : _a.byteLength) || 0;
849
+ const compressedSize = pseudoItem?.compBuffer?.byteLength || 0;
854
850
  if (!matchingGroup.pseudoLayer[file]) {
855
851
  matchingGroup.pseudoLayer[file] = pseudoItem;
856
852
  matchingGroup.pseudoLayerBytes += compressedSize;
@@ -993,7 +989,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
993
989
  const pr = prerenderManifest.staticRoutes[routeKey];
994
990
  const { initialRevalidate, srcRoute } = pr;
995
991
  const route = srcRoute || routeKey;
996
- const routeNoLocale = (routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n)
992
+ const routeNoLocale = routesManifest?.i18n
997
993
  ? normalizeLocalePath(routeKey, routesManifest.i18n.locales).pathname
998
994
  : routeKey;
999
995
  // if the 404 page used getStaticProps we need to update static404Page
@@ -1008,7 +1004,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
1008
1004
  (!canUsePreviewMode || (hasPages404 && routeNoLocale === '/404')) &&
1009
1005
  !prerenderManifest.fallbackRoutes[route] &&
1010
1006
  !prerenderManifest.blockingFallbackRoutes[route]) {
1011
- if ((routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) &&
1007
+ if (routesManifest?.i18n &&
1012
1008
  Object.keys(prerenderManifest.staticRoutes).some(route => {
1013
1009
  const staticRoute = prerenderManifest.staticRoutes[route];
1014
1010
  return (staticRoute.srcRoute === srcRoute &&
@@ -1031,7 +1027,6 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
1031
1027
  exports.onPrerenderRouteInitial = onPrerenderRouteInitial;
1032
1028
  let prerenderGroup = 1;
1033
1029
  const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFallback, isOmitted, locale, }) => {
1034
- var _a;
1035
1030
  const { pagesDir, hasPages404, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, } = prerenderRouteArgs;
1036
1031
  if (isBlocking && isFallback) {
1037
1032
  throw new build_utils_1.NowBuildError({
@@ -1050,7 +1045,7 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1050
1045
  let origRouteFileNoExt = routeFileNoExt;
1051
1046
  const { isLocalePrefixed } = prerenderManifest;
1052
1047
  if (!locale && isLocalePrefixed) {
1053
- const localePathResult = normalizeLocalePath(routeKey, ((_a = routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) === null || _a === void 0 ? void 0 : _a.locales) || []);
1048
+ const localePathResult = normalizeLocalePath(routeKey, routesManifest?.i18n?.locales || []);
1054
1049
  locale = localePathResult.detectedLocale;
1055
1050
  origRouteFileNoExt =
1056
1051
  localePathResult.pathname === '/'
@@ -1173,8 +1168,8 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1173
1168
  // detect this for prerender (ISR) pages by reading the routes manifest file.
1174
1169
  const pageKey = srcRoute || routeKey;
1175
1170
  const isDynamic = isDynamicRoute(pageKey);
1176
- const route = routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.dynamicRoutes.find((r) => r.page === pageKey && !('isMiddleware' in r));
1177
- const routeKeys = route === null || route === void 0 ? void 0 : route.routeKeys;
1171
+ const route = routesManifest?.dynamicRoutes.find((r) => r.page === pageKey && !('isMiddleware' in r));
1172
+ const routeKeys = route?.routeKeys;
1178
1173
  // by default allowQuery should be undefined and only set when
1179
1174
  // we have sufficient information to set it
1180
1175
  let allowQuery;
@@ -1205,7 +1200,7 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1205
1200
  bypassToken: prerenderManifest.bypassToken,
1206
1201
  });
1207
1202
  ++prerenderGroup;
1208
- if ((routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) && isBlocking) {
1203
+ if (routesManifest?.i18n && isBlocking) {
1209
1204
  for (const locale of routesManifest.i18n.locales) {
1210
1205
  const localeRouteFileNoExt = addLocaleOrDefault(routeFileNoExt, routesManifest, locale);
1211
1206
  const localeOutputPathPage = normalizeIndexOutput(path_1.default.posix.join(entryDirectory, localeRouteFileNoExt), isServerMode);
@@ -1228,7 +1223,7 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1228
1223
  }
1229
1224
  }
1230
1225
  if (((nonDynamicSsg && !isLocalePrefixed) || isFallback || isOmitted) &&
1231
- (routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.i18n) &&
1226
+ routesManifest?.i18n &&
1232
1227
  !locale) {
1233
1228
  // load each locale
1234
1229
  for (const locale of routesManifest.i18n.locales) {
@@ -1341,7 +1336,7 @@ async function getPrivateOutputs(dir, entries) {
1341
1336
  exports.getPrivateOutputs = getPrivateOutputs;
1342
1337
  async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, }) {
1343
1338
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
1344
- if (middlewareManifest && (middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.sortedMiddleware.length) > 0) {
1339
+ if (middlewareManifest && middlewareManifest?.sortedMiddleware.length > 0) {
1345
1340
  const workerConfigs = await Promise.all(middlewareManifest.sortedMiddleware.map(async (key) => {
1346
1341
  const middleware = middlewareManifest.middleware[key];
1347
1342
  try {
@@ -1357,10 +1352,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1357
1352
  return {
1358
1353
  page: middlewareManifest.middleware[key].page,
1359
1354
  edgeFunction: (() => {
1360
- var _a;
1361
1355
  const { source, map } = wrappedModuleSource.sourceAndMap();
1362
1356
  const transformedMap = (0, sourcemapped_1.stringifySourceMap)(transformSourceMap(map));
1363
- const wasmFiles = ((_a = middleware.wasm) !== null && _a !== void 0 ? _a : []).reduce((acc, { filePath, name }) => {
1357
+ const wasmFiles = (middleware.wasm ?? []).reduce((acc, { filePath, name }) => {
1364
1358
  const fullFilePath = path_1.default.join(entryPath, outputDirectory, filePath);
1365
1359
  acc[`wasm/${name}.wasm`] = new build_utils_1.FileFsRef({
1366
1360
  mode: 0o644,
@@ -1444,8 +1438,7 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
1444
1438
  if (!hasManifest) {
1445
1439
  return;
1446
1440
  }
1447
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1448
- return require(middlewareManifestPath);
1441
+ return fs_extra_1.default.readJSON(middlewareManifestPath);
1449
1442
  }
1450
1443
  /**
1451
1444
  * For an object containing middleware info and a routes manifest this will
@@ -1458,9 +1451,9 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
1458
1451
  */
1459
1452
  function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
1460
1453
  if (page === '/') {
1461
- return regexp.replace('_next', `${(basePath === null || basePath === void 0 ? void 0 : basePath.substring(1)) ? `${basePath === null || basePath === void 0 ? void 0 : basePath.substring(1)}/` : ''}_next`);
1454
+ return regexp.replace('_next', `${basePath?.substring(1) ? `${basePath?.substring(1)}/` : ''}_next`);
1462
1455
  }
1463
- const locale = (i18n === null || i18n === void 0 ? void 0 : i18n.locales.length)
1456
+ const locale = i18n?.locales.length
1464
1457
  ? `(?:/(${i18n.locales
1465
1458
  .map(locale => (0, escape_string_regexp_1.default)(locale))
1466
1459
  .join('|')}))?`
@@ -1472,12 +1465,14 @@ function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
1472
1465
  * by removing webpack-specific prefixes
1473
1466
  */
1474
1467
  function transformSourceMap(sourcemap) {
1475
- var _a;
1476
1468
  if (!sourcemap)
1477
1469
  return;
1478
- const sources = (_a = sourcemap.sources) === null || _a === void 0 ? void 0 : _a.map(source => {
1470
+ const sources = sourcemap.sources
1471
+ ?.map(source => {
1479
1472
  return source.replace(/^webpack:\/\/?_N_E\/(?:\.\/)?/, '');
1480
- }).map(source => {
1473
+ })
1474
+ // Hide the Next.js entrypoint
1475
+ .map(source => {
1481
1476
  return source.startsWith('?') ? '[native code]' : source;
1482
1477
  });
1483
1478
  return { ...sourcemap, sources };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "2.9.1-canary.0",
3
+ "version": "3.0.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -45,9 +45,9 @@
45
45
  "@types/semver": "6.0.0",
46
46
  "@types/text-table": "0.2.1",
47
47
  "@types/webpack-sources": "3.2.0",
48
- "@vercel/build-utils": "3.1.1",
48
+ "@vercel/build-utils": "4.0.0",
49
49
  "@vercel/nft": "0.19.1",
50
- "@vercel/routing-utils": "1.13.3",
50
+ "@vercel/routing-utils": "1.13.4",
51
51
  "async-sema": "3.0.1",
52
52
  "buffer-crc32": "0.2.13",
53
53
  "cheerio": "1.0.0-rc.10",
@@ -70,5 +70,5 @@
70
70
  "typescript": "4.5.2",
71
71
  "webpack-sources": "3.2.3"
72
72
  },
73
- "gitHead": "00420b7a0124b0a0b622f031b1afd9a4e8bfffbd"
73
+ "gitHead": "de0d2fba0b32588726a2799015eaff4e6bb65ffb"
74
74
  }