@vercel/next 2.9.1-canary.0 → 3.0.1-canary.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/edge-function-source/constants.js +3 -17
- package/dist/edge-function-source/get-edge-function-source.js +2 -2
- package/dist/edge-function-source/get-edge-function.js +4 -6
- package/dist/index.js +49611 -6
- package/dist/server-build.js +23 -13
- package/dist/sourcemapped.js +1 -1
- package/dist/utils.js +77 -57
- 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.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;
|
25
|
+
exports.getMiddlewareManifest = 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,28 +1334,43 @@ async function getPrivateOutputs(dir, entries) {
|
|
1339
1334
|
return { files, routes };
|
1340
1335
|
}
|
1341
1336
|
exports.getPrivateOutputs = getPrivateOutputs;
|
1342
|
-
async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, }) {
|
1337
|
+
async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, }) {
|
1343
1338
|
const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1339
|
+
const sortedFunctions = [
|
1340
|
+
...(!middlewareManifest
|
1341
|
+
? []
|
1342
|
+
: middlewareManifest.sortedMiddleware.map(key => ({
|
1343
|
+
key,
|
1344
|
+
edgeFunction: middlewareManifest?.middleware[key],
|
1345
|
+
type: 'middleware',
|
1346
|
+
}))),
|
1347
|
+
...Object.entries(middlewareManifest?.functions ?? {}).map(([key, edgeFunction]) => {
|
1348
|
+
return {
|
1349
|
+
key,
|
1350
|
+
edgeFunction,
|
1351
|
+
type: 'function',
|
1352
|
+
};
|
1353
|
+
}),
|
1354
|
+
];
|
1355
|
+
if (middlewareManifest && sortedFunctions.length > 0) {
|
1356
|
+
const workerConfigs = await Promise.all(sortedFunctions.map(async ({ key, edgeFunction, type }) => {
|
1347
1357
|
try {
|
1348
|
-
const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(
|
1349
|
-
name:
|
1358
|
+
const wrappedModuleSource = await (0, get_edge_function_source_1.getNextjsEdgeFunctionSource)(edgeFunction.files, {
|
1359
|
+
name: edgeFunction.name,
|
1350
1360
|
staticRoutes: routesManifest.staticRoutes,
|
1351
1361
|
dynamicRoutes: routesManifest.dynamicRoutes.filter(r => !('isMiddleware' in r)),
|
1352
1362
|
nextConfig: {
|
1353
1363
|
basePath: routesManifest.basePath,
|
1354
1364
|
i18n: routesManifest.i18n,
|
1355
1365
|
},
|
1356
|
-
}, path_1.default.resolve(entryPath, outputDirectory),
|
1366
|
+
}, path_1.default.resolve(entryPath, outputDirectory), edgeFunction.wasm);
|
1357
1367
|
return {
|
1358
|
-
|
1368
|
+
type,
|
1369
|
+
page: edgeFunction.page,
|
1359
1370
|
edgeFunction: (() => {
|
1360
|
-
var _a;
|
1361
1371
|
const { source, map } = wrappedModuleSource.sourceAndMap();
|
1362
1372
|
const transformedMap = (0, sourcemapped_1.stringifySourceMap)(transformSourceMap(map));
|
1363
|
-
const wasmFiles = (
|
1373
|
+
const wasmFiles = (edgeFunction.wasm ?? []).reduce((acc, { filePath, name }) => {
|
1364
1374
|
const fullFilePath = path_1.default.join(entryPath, outputDirectory, filePath);
|
1365
1375
|
acc[`wasm/${name}.wasm`] = new build_utils_1.FileFsRef({
|
1366
1376
|
mode: 0o644,
|
@@ -1371,7 +1381,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1371
1381
|
}, {});
|
1372
1382
|
return new build_utils_1.EdgeFunction({
|
1373
1383
|
deploymentTarget: 'v8-worker',
|
1374
|
-
name:
|
1384
|
+
name: edgeFunction.name,
|
1375
1385
|
files: {
|
1376
1386
|
'index.js': new build_utils_1.FileBlob({
|
1377
1387
|
data: source,
|
@@ -1388,10 +1398,10 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1388
1398
|
...wasmFiles,
|
1389
1399
|
},
|
1390
1400
|
entrypoint: 'index.js',
|
1391
|
-
envVarsInUse:
|
1401
|
+
envVarsInUse: edgeFunction.env,
|
1392
1402
|
});
|
1393
1403
|
})(),
|
1394
|
-
routeSrc: getRouteSrc(
|
1404
|
+
routeSrc: getRouteSrc(edgeFunction, routesManifest),
|
1395
1405
|
};
|
1396
1406
|
}
|
1397
1407
|
catch (e) {
|
@@ -1406,14 +1416,22 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1406
1416
|
};
|
1407
1417
|
for (const worker of workerConfigs.values()) {
|
1408
1418
|
const edgeFile = worker.edgeFunction.name;
|
1409
|
-
|
1410
|
-
|
1419
|
+
const shortPath = edgeFile.replace(/^pages\//, '');
|
1420
|
+
worker.edgeFunction.name = shortPath;
|
1421
|
+
source.edgeFunctions[shortPath] = worker.edgeFunction;
|
1411
1422
|
const route = {
|
1412
1423
|
continue: true,
|
1413
|
-
override: true,
|
1414
|
-
middlewarePath: edgeFile,
|
1415
1424
|
src: worker.routeSrc,
|
1416
1425
|
};
|
1426
|
+
if (worker.type === 'function') {
|
1427
|
+
route.dest = shortPath;
|
1428
|
+
}
|
1429
|
+
else {
|
1430
|
+
route.middlewarePath = shortPath;
|
1431
|
+
if (isCorrectMiddlewareOrder) {
|
1432
|
+
route.override = true;
|
1433
|
+
}
|
1434
|
+
}
|
1417
1435
|
if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
|
1418
1436
|
source.dynamicRouteMap.set(worker.page, route);
|
1419
1437
|
}
|
@@ -1444,9 +1462,9 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
|
|
1444
1462
|
if (!hasManifest) {
|
1445
1463
|
return;
|
1446
1464
|
}
|
1447
|
-
|
1448
|
-
return require(middlewareManifestPath);
|
1465
|
+
return fs_extra_1.default.readJSON(middlewareManifestPath);
|
1449
1466
|
}
|
1467
|
+
exports.getMiddlewareManifest = getMiddlewareManifest;
|
1450
1468
|
/**
|
1451
1469
|
* For an object containing middleware info and a routes manifest this will
|
1452
1470
|
* generate a string with the route that will activate the middleware on
|
@@ -1458,9 +1476,9 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
|
|
1458
1476
|
*/
|
1459
1477
|
function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
|
1460
1478
|
if (page === '/') {
|
1461
|
-
return regexp.replace('_next', `${
|
1479
|
+
return regexp.replace('_next', `${basePath?.substring(1) ? `${basePath?.substring(1)}/` : ''}_next`);
|
1462
1480
|
}
|
1463
|
-
const locale =
|
1481
|
+
const locale = i18n?.locales.length
|
1464
1482
|
? `(?:/(${i18n.locales
|
1465
1483
|
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
1466
1484
|
.join('|')}))?`
|
@@ -1472,12 +1490,14 @@ function getRouteSrc({ regexp, page }, { basePath = '', i18n }) {
|
|
1472
1490
|
* by removing webpack-specific prefixes
|
1473
1491
|
*/
|
1474
1492
|
function transformSourceMap(sourcemap) {
|
1475
|
-
var _a;
|
1476
1493
|
if (!sourcemap)
|
1477
1494
|
return;
|
1478
|
-
const sources =
|
1495
|
+
const sources = sourcemap.sources
|
1496
|
+
?.map(source => {
|
1479
1497
|
return source.replace(/^webpack:\/\/?_N_E\/(?:\.\/)?/, '');
|
1480
|
-
})
|
1498
|
+
})
|
1499
|
+
// Hide the Next.js entrypoint
|
1500
|
+
.map(source => {
|
1481
1501
|
return source.startsWith('?') ? '[native code]' : source;
|
1482
1502
|
});
|
1483
1503
|
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.1",
|
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": "6d42816395b5c37c44f14e5c42af5b458a029c03"
|
74
74
|
}
|