@vercel/next 2.9.0 → 3.0.1-canary.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.
- package/dist/edge-function-source/get-edge-function.js +4 -6
- package/dist/index.js +49576 -6
- package/dist/server-build.js +23 -13
- package/dist/sourcemapped.js +1 -1
- package/dist/utils.js +54 -82
- package/package.json +4 -4
package/dist/server-build.js
CHANGED
@@ -17,14 +17,15 @@ const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));
|
|
17
17
|
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
|
+
const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
|
20
21
|
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
22
|
const lambdas = {};
|
23
23
|
const prerenders = {};
|
24
24
|
const lambdaPageKeys = Object.keys(lambdaPages);
|
25
25
|
const internalPages = ['_app.js', '_error.js', '_document.js'];
|
26
26
|
const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
|
27
27
|
const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
|
28
|
+
const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
|
28
29
|
let hasStatic500 = !!staticPages[path_1.default.join(entryDirectory, '500')];
|
29
30
|
if (lambdaPageKeys.length === 0) {
|
30
31
|
throw new build_utils_1.NowBuildError({
|
@@ -274,7 +275,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
274
275
|
cache: traceCache,
|
275
276
|
processCwd: requiredServerFilesManifest.appDir || entryPath,
|
276
277
|
});
|
277
|
-
traceResult.esmFileList.forEach(file => traceResult
|
278
|
+
traceResult.esmFileList.forEach(file => traceResult?.fileList.add(file));
|
278
279
|
parentFilesMap = (0, utils_1.getFilesMapFromReasons)(traceResult.fileList, traceResult.reasons);
|
279
280
|
}
|
280
281
|
for (const page of mergedPageKeys) {
|
@@ -298,11 +299,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
298
299
|
reasons = new Map();
|
299
300
|
}
|
300
301
|
else {
|
301
|
-
fileList = Array.from(
|
302
|
+
fileList = Array.from(parentFilesMap?.get(path_1.default.relative(baseDir, lambdaPages[page].fsPath)) || []);
|
302
303
|
if (!fileList) {
|
303
304
|
throw new Error(`Invariant: Failed to trace ${page}, missing fileList`);
|
304
305
|
}
|
305
|
-
reasons =
|
306
|
+
reasons = traceResult?.reasons || new Map();
|
306
307
|
}
|
307
308
|
await Promise.all(fileList.map((0, utils_1.collectTracedFiles)(baseDir, lstatResults, lstatSema, reasons, tracedFiles)));
|
308
309
|
pageTraces[page] = tracedFiles;
|
@@ -318,7 +319,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
318
319
|
const file = initialPseudoLayer.pseudoLayer[cur];
|
319
320
|
return prev + file.uncompressedSize || 0;
|
320
321
|
}, 0);
|
321
|
-
const pageExtensions =
|
322
|
+
const pageExtensions = requiredServerFilesManifest.config?.pageExtensions;
|
322
323
|
const pageLambdaGroups = await (0, utils_1.getPageLambdaGroups)(requiredServerFilesManifest.appDir || entryPath, config, nonApiPages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer.pseudoLayer, initialPseudoLayer.pseudoLayerBytes, initialPseudoLayerSize, lambdaCompressedByteLimit, internalPages, pageExtensions);
|
323
324
|
const apiLambdaGroups = await (0, utils_1.getPageLambdaGroups)(requiredServerFilesManifest.appDir || entryPath, config, apiPages, prerenderRoutes, pageTraces, compressedPages, tracedPseudoLayer.pseudoLayer, initialPseudoLayer.pseudoLayerBytes, initialPseudoLayerSize, lambdaCompressedByteLimit, internalPages);
|
324
325
|
(0, build_utils_1.debug)(JSON.stringify({
|
@@ -358,7 +359,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
358
359
|
for (const page of group.pages) {
|
359
360
|
const pageNoExt = page.replace(/\.js$/, '');
|
360
361
|
let isPrerender = prerenderRoutes.has(path_1.default.join('/', pageNoExt === 'index' ? '' : pageNoExt));
|
361
|
-
if (!isPrerender &&
|
362
|
+
if (!isPrerender && routesManifest?.i18n) {
|
362
363
|
isPrerender = routesManifest.i18n.locales.some(locale => {
|
363
364
|
return prerenderRoutes.has(path_1.default.join('/', locale, pageNoExt === 'index' ? '' : pageNoExt));
|
364
365
|
});
|
@@ -405,7 +406,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
405
406
|
});
|
406
407
|
}
|
407
408
|
prerenderRoutes.forEach(route => {
|
408
|
-
if (routesManifest
|
409
|
+
if (routesManifest?.i18n) {
|
409
410
|
route = (0, utils_1.normalizeLocalePath)(route, routesManifest.i18n.locales).pathname;
|
410
411
|
}
|
411
412
|
delete lambdas[path_1.default.join('.', entryDirectory, route === '/' ? 'index' : route)];
|
@@ -414,11 +415,12 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
414
415
|
entryPath,
|
415
416
|
outputDirectory,
|
416
417
|
routesManifest,
|
418
|
+
isCorrectMiddlewareOrder,
|
417
419
|
});
|
418
420
|
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
421
|
const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
|
420
422
|
const notFoundPreviewRoutes = [];
|
421
|
-
if (
|
423
|
+
if (prerenderManifest.notFoundRoutes?.length > 0 && canUsePreviewMode) {
|
422
424
|
// we combine routes into one src here to reduce the number of needed
|
423
425
|
// routes since only the status is being modified and we don't want
|
424
426
|
// to exceed the routes limit
|
@@ -444,7 +446,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
444
446
|
for (let i = 0; i < prerenderManifest.notFoundRoutes.length; i++) {
|
445
447
|
const route = prerenderManifest.notFoundRoutes[i];
|
446
448
|
const isLastRoute = i === prerenderManifest.notFoundRoutes.length - 1;
|
447
|
-
if (
|
449
|
+
if (prerenderManifest.staticRoutes[route]?.initialRevalidate === false) {
|
448
450
|
if (currentRouteSrc.length + route.length + 1 >= 4096) {
|
449
451
|
pushRoute(currentRouteSrc);
|
450
452
|
currentRouteSrc = starterRouteSrc;
|
@@ -459,7 +461,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
459
461
|
}
|
460
462
|
return {
|
461
463
|
wildcard: wildcardConfig,
|
462
|
-
images:
|
464
|
+
images: imagesManifest?.images?.loader === 'default'
|
463
465
|
? {
|
464
466
|
domains: imagesManifest.images.domains,
|
465
467
|
sizes: imagesManifest.images.sizes,
|
@@ -580,6 +582,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
580
582
|
...notFoundPreviewRoutes,
|
581
583
|
...headers,
|
582
584
|
...redirects,
|
585
|
+
// middleware comes directly after redirects but before
|
586
|
+
// beforeFiles rewrites as middleware is not a "file" route
|
587
|
+
...(isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
|
583
588
|
...beforeFilesRewrites,
|
584
589
|
// Make sure to 404 for the /404 path itself
|
585
590
|
...(i18n
|
@@ -619,13 +624,16 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
619
624
|
continue: true,
|
620
625
|
},
|
621
626
|
]),
|
622
|
-
|
627
|
+
// while middleware was in beta the order came right before
|
628
|
+
// handle: 'filesystem' we maintain this for older versions
|
629
|
+
// to prevent a local/deploy mismatch
|
630
|
+
...(!isCorrectMiddlewareOrder ? middleware.staticRoutes : []),
|
623
631
|
// Next.js page lambdas, `static/` folder, reserved assets, and `public/`
|
624
632
|
// folder
|
625
633
|
{ handle: 'filesystem' },
|
626
634
|
// ensure the basePath prefixed _next/image is rewritten to the root
|
627
635
|
// _next/image path
|
628
|
-
...(
|
636
|
+
...(routesManifest?.basePath
|
629
637
|
? [
|
630
638
|
{
|
631
639
|
src: path_1.default.join('/', entryDirectory, '_next/image/?'),
|
@@ -676,7 +684,9 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
676
684
|
? []
|
677
685
|
: [
|
678
686
|
{
|
679
|
-
src: `${path_1.default.join('/', entryDirectory, '/')}(?:${i18n
|
687
|
+
src: `${path_1.default.join('/', entryDirectory, '/')}(?:${i18n?.locales
|
688
|
+
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
689
|
+
.join('|')})/(.*)`,
|
680
690
|
dest: '/$1',
|
681
691
|
check: true,
|
682
692
|
},
|
package/dist/sourcemapped.js
CHANGED
package/dist/utils.js
CHANGED
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
23
23
|
};
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
25
|
-
exports.
|
25
|
+
exports.getMiddlewareBundle = exports.getSourceFilePathFromPage = exports.isDynamicRoute = exports.normalizePage = 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 = void 0;
|
26
26
|
const build_utils_1 = require("@vercel/build-utils");
|
27
27
|
const async_sema_1 = require("async-sema");
|
28
28
|
const buffer_crc32_1 = __importDefault(require("buffer-crc32"));
|
@@ -156,8 +156,7 @@ async function getRoutesManifest(entryPath, outputDirectory, nextVersion) {
|
|
156
156
|
code: 'NEXT_NO_ROUTES_MANIFEST',
|
157
157
|
});
|
158
158
|
}
|
159
|
-
|
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 || !
|
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 &&
|
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 || !
|
196
|
+
.filter(({ page }) => canUsePreviewMode || !omittedRoutes?.has(page))
|
198
197
|
.map(params => {
|
199
198
|
if ('isMiddleware' in params) {
|
200
|
-
const route = dynamicMiddlewareRouteMap
|
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 &&
|
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
|
-
(
|
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
|
-
(
|
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
|
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' ||
|
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
|
-
|
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),
|
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 (!
|
378
|
+
if (!ignoreFn?.(file, parent)) {
|
381
379
|
parentFiles.add(file);
|
382
380
|
}
|
383
381
|
const parentReason = reasons.get(parent);
|
384
|
-
if (parentReason
|
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 =
|
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 (!
|
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 +=
|
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 =
|
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 =
|
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 (
|
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,
|
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
|
1177
|
-
const routeKeys = route
|
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 (
|
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
|
-
|
1226
|
+
routesManifest?.i18n &&
|
1232
1227
|
!locale) {
|
1233
1228
|
// load each locale
|
1234
1229
|
for (const locale of routesManifest.i18n.locales) {
|
@@ -1339,45 +1334,27 @@ async function getPrivateOutputs(dir, entries) {
|
|
1339
1334
|
return { files, routes };
|
1340
1335
|
}
|
1341
1336
|
exports.getPrivateOutputs = getPrivateOutputs;
|
1342
|
-
async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, }) {
|
1343
|
-
var _a;
|
1337
|
+
async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, }) {
|
1344
1338
|
const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
: middlewareManifest.sortedMiddleware.map(key => ({
|
1349
|
-
key,
|
1350
|
-
edgeFunction: middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.middleware[key],
|
1351
|
-
type: 'middleware',
|
1352
|
-
}))),
|
1353
|
-
...Object.entries((_a = middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.functions) !== null && _a !== void 0 ? _a : {}).map(([key, edgeFunction]) => {
|
1354
|
-
return {
|
1355
|
-
key,
|
1356
|
-
edgeFunction,
|
1357
|
-
type: 'function',
|
1358
|
-
};
|
1359
|
-
}),
|
1360
|
-
];
|
1361
|
-
if (middlewareManifest && sortedFunctions.length > 0) {
|
1362
|
-
const workerConfigs = await Promise.all(sortedFunctions.map(async ({ key, edgeFunction, type }) => {
|
1339
|
+
if (middlewareManifest && middlewareManifest?.sortedMiddleware.length > 0) {
|
1340
|
+
const workerConfigs = await Promise.all(middlewareManifest.sortedMiddleware.map(async (key) => {
|
1341
|
+
const middleware = middlewareManifest.middleware[key];
|
1363
1342
|
try {
|
1364
|
-
const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(
|
1365
|
-
name:
|
1343
|
+
const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(middleware.files, {
|
1344
|
+
name: middleware.name,
|
1366
1345
|
staticRoutes: routesManifest.staticRoutes,
|
1367
1346
|
dynamicRoutes: routesManifest.dynamicRoutes.filter(r => !('isMiddleware' in r)),
|
1368
1347
|
nextConfig: {
|
1369
1348
|
basePath: routesManifest.basePath,
|
1370
1349
|
i18n: routesManifest.i18n,
|
1371
1350
|
},
|
1372
|
-
}, path_1.default.resolve(entryPath, outputDirectory),
|
1351
|
+
}, path_1.default.resolve(entryPath, outputDirectory), middleware.wasm);
|
1373
1352
|
return {
|
1374
|
-
|
1375
|
-
page: edgeFunction.page,
|
1353
|
+
page: middlewareManifest.middleware[key].page,
|
1376
1354
|
edgeFunction: (() => {
|
1377
|
-
var _a;
|
1378
1355
|
const { source, map } = wrappedModuleSource.sourceAndMap();
|
1379
1356
|
const transformedMap = (0, sourcemapped_1.stringifySourceMap)(transformSourceMap(map));
|
1380
|
-
const wasmFiles = (
|
1357
|
+
const wasmFiles = (middleware.wasm ?? []).reduce((acc, { filePath, name }) => {
|
1381
1358
|
const fullFilePath = path_1.default.join(entryPath, outputDirectory, filePath);
|
1382
1359
|
acc[`wasm/${name}.wasm`] = new build_utils_1.FileFsRef({
|
1383
1360
|
mode: 0o644,
|
@@ -1388,7 +1365,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1388
1365
|
}, {});
|
1389
1366
|
return new build_utils_1.EdgeFunction({
|
1390
1367
|
deploymentTarget: 'v8-worker',
|
1391
|
-
name:
|
1368
|
+
name: middleware.name,
|
1392
1369
|
files: {
|
1393
1370
|
'index.js': new build_utils_1.FileBlob({
|
1394
1371
|
data: source,
|
@@ -1405,10 +1382,10 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1405
1382
|
...wasmFiles,
|
1406
1383
|
},
|
1407
1384
|
entrypoint: 'index.js',
|
1408
|
-
envVarsInUse:
|
1385
|
+
envVarsInUse: middleware.env,
|
1409
1386
|
});
|
1410
1387
|
})(),
|
1411
|
-
routeSrc: getRouteSrc(
|
1388
|
+
routeSrc: getRouteSrc(middlewareManifest.middleware[key], routesManifest),
|
1412
1389
|
};
|
1413
1390
|
}
|
1414
1391
|
catch (e) {
|
@@ -1423,21 +1400,16 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1423
1400
|
};
|
1424
1401
|
for (const worker of workerConfigs.values()) {
|
1425
1402
|
const edgeFile = worker.edgeFunction.name;
|
1426
|
-
|
1427
|
-
|
1428
|
-
source.edgeFunctions[shortPath] = worker.edgeFunction;
|
1403
|
+
worker.edgeFunction.name = edgeFile.replace(/^pages\//, '');
|
1404
|
+
source.edgeFunctions[edgeFile] = worker.edgeFunction;
|
1429
1405
|
const route = {
|
1430
1406
|
continue: true,
|
1407
|
+
middlewarePath: edgeFile,
|
1431
1408
|
src: worker.routeSrc,
|
1432
|
-
...(worker.type === 'middleware'
|
1433
|
-
? {
|
1434
|
-
middlewarePath: shortPath,
|
1435
|
-
override: true,
|
1436
|
-
}
|
1437
|
-
: {
|
1438
|
-
dest: shortPath,
|
1439
|
-
}),
|
1440
1409
|
};
|
1410
|
+
if (isCorrectMiddlewareOrder) {
|
1411
|
+
route.override = true;
|
1412
|
+
}
|
1441
1413
|
if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
|
1442
1414
|
source.dynamicRouteMap.set(worker.page, route);
|
1443
1415
|
}
|
@@ -1468,10 +1440,8 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
|
|
1468
1440
|
if (!hasManifest) {
|
1469
1441
|
return;
|
1470
1442
|
}
|
1471
|
-
|
1472
|
-
return require(middlewareManifestPath);
|
1443
|
+
return fs_extra_1.default.readJSON(middlewareManifestPath);
|
1473
1444
|
}
|
1474
|
-
exports.getMiddlewareManifest = getMiddlewareManifest;
|
1475
1445
|
/**
|
1476
1446
|
* For an object containing middleware info and a routes manifest this will
|
1477
1447
|
* generate a string with the route that will activate the middleware on
|
@@ -1483,9 +1453,9 @@ exports.getMiddlewareManifest = getMiddlewareManifest;
|
|
1483
1453
|
*/
|
1484
1454
|
function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
|
1485
1455
|
if (page === '/') {
|
1486
|
-
return regexp.replace('_next', `${
|
1456
|
+
return regexp.replace('_next', `${basePath?.substring(1) ? `${basePath?.substring(1)}/` : ''}_next`);
|
1487
1457
|
}
|
1488
|
-
const locale =
|
1458
|
+
const locale = i18n?.locales.length
|
1489
1459
|
? `(?:/(${i18n.locales
|
1490
1460
|
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
1491
1461
|
.join('|')}))?`
|
@@ -1497,12 +1467,14 @@ function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
|
|
1497
1467
|
* by removing webpack-specific prefixes
|
1498
1468
|
*/
|
1499
1469
|
function transformSourceMap(sourcemap) {
|
1500
|
-
var _a;
|
1501
1470
|
if (!sourcemap)
|
1502
1471
|
return;
|
1503
|
-
const sources =
|
1472
|
+
const sources = sourcemap.sources
|
1473
|
+
?.map(source => {
|
1504
1474
|
return source.replace(/^webpack:\/\/?_N_E\/(?:\.\/)?/, '');
|
1505
|
-
})
|
1475
|
+
})
|
1476
|
+
// Hide the Next.js entrypoint
|
1477
|
+
.map(source => {
|
1506
1478
|
return source.startsWith('?') ? '[native code]' : source;
|
1507
1479
|
});
|
1508
1480
|
return { ...sourcemap, sources };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/next",
|
3
|
-
"version": "
|
3
|
+
"version": "3.0.1-canary.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": "
|
48
|
+
"@vercel/build-utils": "4.0.1-canary.0",
|
49
49
|
"@vercel/nft": "0.19.1",
|
50
|
-
"@vercel/routing-utils": "1.13.
|
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": "
|
73
|
+
"gitHead": "39f758662131ec37c467ebba5d5b618cba0c753f"
|
74
74
|
}
|