@vercel/next 3.1.19 → 3.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +212 -89
- package/dist/server-build.js +71 -31
- package/dist/utils.js +80 -35
- package/package.json +4 -4
package/dist/index.js
CHANGED
@@ -12114,7 +12114,7 @@ async function analyze(id, code, job) {
|
|
12114
12114
|
.filter(name => !excludeAssetExtensions.has(path_1.default.extname(name)) &&
|
12115
12115
|
!excludeAssetFiles.has(path_1.default.basename(name)) &&
|
12116
12116
|
!name.endsWith('/'))
|
12117
|
-
.forEach(file =>
|
12117
|
+
.forEach(file => deps.add(file));
|
12118
12118
|
});
|
12119
12119
|
}
|
12120
12120
|
async function processRequireArg(expression, isImport = false) {
|
@@ -12147,7 +12147,7 @@ async function analyze(id, code, job) {
|
|
12147
12147
|
let scope = rollup_pluginutils_1.attachScopes(ast, 'scope');
|
12148
12148
|
if (isAst(ast)) {
|
12149
12149
|
wrappers_1.handleWrappers(ast);
|
12150
|
-
await special_cases_1.default({ id, ast, emitAsset: path => assets.add(path), emitAssetDirectory, job });
|
12150
|
+
await special_cases_1.default({ id, ast, emitDependency: path => deps.add(path), emitAsset: path => assets.add(path), emitAssetDirectory, job });
|
12151
12151
|
}
|
12152
12152
|
async function backtrack(parent, context) {
|
12153
12153
|
// computing a static expression outward
|
@@ -12234,6 +12234,18 @@ async function analyze(id, code, job) {
|
|
12234
12234
|
await processRequireArg(node.arguments[0]);
|
12235
12235
|
return;
|
12236
12236
|
}
|
12237
|
+
else if ((!isESM || job.mixedModules) &&
|
12238
|
+
node.callee.type === 'MemberExpression' &&
|
12239
|
+
node.callee.object.type === 'Identifier' &&
|
12240
|
+
node.callee.object.name === 'require' &&
|
12241
|
+
knownBindings.require.shadowDepth === 0 &&
|
12242
|
+
node.callee.property.type === 'Identifier' &&
|
12243
|
+
!node.callee.computed &&
|
12244
|
+
node.callee.property.name === 'resolve' &&
|
12245
|
+
node.arguments.length) {
|
12246
|
+
await processRequireArg(node.arguments[0]);
|
12247
|
+
return;
|
12248
|
+
}
|
12237
12249
|
const calleeValue = job.analysis.evaluatePureExpressions && await computePureStaticValue(node.callee, false);
|
12238
12250
|
// if we have a direct pure static function,
|
12239
12251
|
// and that function has a [TRIGGER] symbol -> trigger asset emission from it
|
@@ -12918,12 +12930,15 @@ class Job {
|
|
12918
12930
|
return;
|
12919
12931
|
if (path.endsWith('.node'))
|
12920
12932
|
return await sharedlib_emit_1.sharedLibEmit(path, this);
|
12921
|
-
|
12922
|
-
|
12923
|
-
|
12924
|
-
|
12925
|
-
|
12926
|
-
|
12933
|
+
const handlePjsonBoundary = async (item) => {
|
12934
|
+
// js files require the "type": "module" lookup, so always emit the package.json
|
12935
|
+
if (item.endsWith(".js")) {
|
12936
|
+
const pjsonBoundary = await this.getPjsonBoundary(item);
|
12937
|
+
if (pjsonBoundary)
|
12938
|
+
await this.emitFile(pjsonBoundary + path_1.sep + "package.json", "resolve", item);
|
12939
|
+
}
|
12940
|
+
};
|
12941
|
+
await handlePjsonBoundary(path);
|
12927
12942
|
let analyzeResult;
|
12928
12943
|
const cachedAnalysis = this.analysisCache.get(path);
|
12929
12944
|
if (cachedAnalysis) {
|
@@ -12933,6 +12948,9 @@ class Job {
|
|
12933
12948
|
const source = await this.readFile(path);
|
12934
12949
|
if (source === null)
|
12935
12950
|
throw new Error('File ' + path + ' does not exist.');
|
12951
|
+
// analyze should not have any side-effects e.g. calling `job.emitFile`
|
12952
|
+
// directly as this will not be included in the cachedAnalysis and won't
|
12953
|
+
// be emit for successive runs that leverage the cache
|
12936
12954
|
analyzeResult = await analyze_1.default(path, source.toString(), this);
|
12937
12955
|
this.analysisCache.set(path, analyzeResult);
|
12938
12956
|
}
|
@@ -12941,12 +12959,8 @@ class Job {
|
|
12941
12959
|
this.esmFileList.add(path_1.relative(this.base, path));
|
12942
12960
|
await Promise.all([
|
12943
12961
|
...[...assets].map(async (asset) => {
|
12944
|
-
|
12945
|
-
|
12946
|
-
this.ts && (ext === '.ts' || ext === '.tsx') && asset.startsWith(this.base) && asset.slice(this.base.length).indexOf(path_1.sep + 'node_modules' + path_1.sep) === -1)
|
12947
|
-
await this.emitDependency(asset, path);
|
12948
|
-
else
|
12949
|
-
await this.emitFile(asset, 'asset', path);
|
12962
|
+
await handlePjsonBoundary(asset);
|
12963
|
+
await this.emitFile(asset, 'asset', path);
|
12950
12964
|
}),
|
12951
12965
|
...[...deps].map(async (dep) => {
|
12952
12966
|
try {
|
@@ -13777,18 +13791,18 @@ const specialCases = {
|
|
13777
13791
|
emitAsset(path_1.resolve(path_1.dirname(id), '../data/geo.dat'));
|
13778
13792
|
}
|
13779
13793
|
},
|
13780
|
-
'pixelmatch'({ id,
|
13794
|
+
'pixelmatch'({ id, emitDependency }) {
|
13781
13795
|
if (id.endsWith('pixelmatch/index.js')) {
|
13782
|
-
|
13796
|
+
emitDependency(path_1.resolve(path_1.dirname(id), 'bin/pixelmatch'));
|
13783
13797
|
}
|
13784
13798
|
}
|
13785
13799
|
};
|
13786
|
-
async function handleSpecialCases({ id, ast, emitAsset, emitAssetDirectory, job }) {
|
13800
|
+
async function handleSpecialCases({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job }) {
|
13787
13801
|
const pkgName = get_package_base_1.getPackageName(id);
|
13788
13802
|
const specialCase = specialCases[pkgName || ''];
|
13789
13803
|
id = id.replace(/\\/g, '/');
|
13790
13804
|
if (specialCase)
|
13791
|
-
await specialCase({ id, ast, emitAsset, emitAssetDirectory, job });
|
13805
|
+
await specialCase({ id, ast, emitDependency, emitAsset, emitAssetDirectory, job });
|
13792
13806
|
}
|
13793
13807
|
exports.default = handleSpecialCases;
|
13794
13808
|
;
|
@@ -42910,6 +42924,10 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
|
|
42910
42924
|
? // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
42911
42925
|
path_1.default.join('/', routesManifest?.i18n.defaultLocale, '/404')
|
42912
42926
|
: '/404']?.initialRevalidate === 'number';
|
42927
|
+
const hasIsr500Page = typeof prerenderManifest.staticRoutes[routesManifest?.i18n
|
42928
|
+
? // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
|
42929
|
+
path_1.default.join('/', routesManifest?.i18n.defaultLocale, '/500')
|
42930
|
+
: '/500']?.initialRevalidate === 'number';
|
42913
42931
|
const wildcardConfig = routesManifest?.i18n?.domains && routesManifest.i18n.domains.length > 0
|
42914
42932
|
? routesManifest.i18n.domains.map(item => {
|
42915
42933
|
return {
|
@@ -43287,7 +43305,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
|
|
43287
43305
|
nextFiles['next.config.js'] = filesAfterBuild['next.config.js'];
|
43288
43306
|
}
|
43289
43307
|
const pagesDir = path_1.default.join(entryPath, outputDirectory, 'server', 'static', buildId, 'pages');
|
43290
|
-
const pages = await getServerlessPages({
|
43308
|
+
const { pages } = await getServerlessPages({
|
43291
43309
|
pagesDir,
|
43292
43310
|
entryPath,
|
43293
43311
|
outputDirectory,
|
@@ -43337,10 +43355,12 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
|
|
43337
43355
|
else {
|
43338
43356
|
(0, build_utils_1.debug)('Preparing serverless function files...');
|
43339
43357
|
const pagesDir = path_1.default.join(entryPath, outputDirectory, isServerMode ? 'server' : 'serverless', 'pages');
|
43340
|
-
const
|
43358
|
+
const appPathRoutesManifest = await (0, fs_extra_1.readJSON)(path_1.default.join(entryPath, outputDirectory, 'app-path-routes-manifest.json')).catch(() => null);
|
43359
|
+
const { pages, appPaths: lambdaAppPaths } = await getServerlessPages({
|
43341
43360
|
pagesDir,
|
43342
43361
|
entryPath,
|
43343
43362
|
outputDirectory,
|
43363
|
+
appPathRoutesManifest,
|
43344
43364
|
});
|
43345
43365
|
const isApiPage = (page) => page
|
43346
43366
|
.replace(/\\/g, '/')
|
@@ -43470,10 +43490,12 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
|
|
43470
43490
|
config,
|
43471
43491
|
nextVersion,
|
43472
43492
|
trailingSlash,
|
43493
|
+
appPathRoutesManifest,
|
43473
43494
|
dynamicPages,
|
43474
43495
|
canUsePreviewMode,
|
43475
43496
|
staticPages,
|
43476
43497
|
lambdaPages: pages,
|
43498
|
+
lambdaAppPaths,
|
43477
43499
|
omittedPrerenderRoutes,
|
43478
43500
|
isCorrectLocaleAPIRoutes,
|
43479
43501
|
pagesDir,
|
@@ -43501,6 +43523,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
|
|
43501
43523
|
requiredServerFilesManifest,
|
43502
43524
|
privateOutputs,
|
43503
43525
|
hasIsr404Page,
|
43526
|
+
hasIsr500Page,
|
43504
43527
|
});
|
43505
43528
|
}
|
43506
43529
|
// > 1 because _error is a lambda but isn't used if a static 404 is available
|
@@ -44438,15 +44461,30 @@ const prepareCache = async ({ workPath, repoRootPath, entrypoint, config = {}, }
|
|
44438
44461
|
};
|
44439
44462
|
exports.prepareCache = prepareCache;
|
44440
44463
|
async function getServerlessPages(params) {
|
44441
|
-
const [pages, middlewareManifest] = await Promise.all([
|
44464
|
+
const [pages, appPaths, middlewareManifest] = await Promise.all([
|
44442
44465
|
(0, build_utils_1.glob)('**/!(_middleware).js', params.pagesDir),
|
44466
|
+
params.appPathRoutesManifest
|
44467
|
+
? (0, build_utils_1.glob)('**/page.js', path_1.default.join(params.pagesDir, '../app'))
|
44468
|
+
: Promise.resolve({}),
|
44443
44469
|
(0, utils_1.getMiddlewareManifest)(params.entryPath, params.outputDirectory),
|
44444
44470
|
]);
|
44471
|
+
const normalizedAppPaths = {};
|
44472
|
+
if (params.appPathRoutesManifest) {
|
44473
|
+
for (const [entry, normalizedEntry] of Object.entries(params.appPathRoutesManifest)) {
|
44474
|
+
const normalizedPath = `${path_1.default.join('.', normalizedEntry)}.js`;
|
44475
|
+
const globPath = `${path_1.default.join('.', entry)}.js`;
|
44476
|
+
if (appPaths[globPath]) {
|
44477
|
+
normalizedAppPaths[normalizedPath] = appPaths[globPath];
|
44478
|
+
}
|
44479
|
+
}
|
44480
|
+
}
|
44445
44481
|
// Edge Functions do not consider as Serverless Functions
|
44446
44482
|
for (const edgeFunctionFile of Object.keys(middlewareManifest?.functions ?? {})) {
|
44447
|
-
|
44483
|
+
const edgePath = edgeFunctionFile.slice(1) + '.js';
|
44484
|
+
delete normalizedAppPaths[edgePath];
|
44485
|
+
delete pages[edgePath];
|
44448
44486
|
}
|
44449
|
-
return pages;
|
44487
|
+
return { pages, appPaths: normalizedAppPaths };
|
44450
44488
|
}
|
44451
44489
|
|
44452
44490
|
|
@@ -44825,13 +44863,20 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
|
|
44825
44863
|
const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
|
44826
44864
|
const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
|
44827
44865
|
const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
|
44828
|
-
async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, trailingSlash, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
|
44866
|
+
async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
|
44867
|
+
lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
|
44829
44868
|
const lambdas = {};
|
44830
44869
|
const prerenders = {};
|
44831
44870
|
const lambdaPageKeys = Object.keys(lambdaPages);
|
44832
44871
|
const internalPages = ['_app.js', '_error.js', '_document.js'];
|
44833
44872
|
const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
|
44834
44873
|
const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
|
44874
|
+
let appBuildTraces = {};
|
44875
|
+
let appDir = null;
|
44876
|
+
if (appPathRoutesManifest) {
|
44877
|
+
appDir = path_1.default.join(pagesDir, '../app');
|
44878
|
+
appBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', appDir);
|
44879
|
+
}
|
44835
44880
|
const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
|
44836
44881
|
const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
|
44837
44882
|
const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
|
@@ -45068,9 +45113,21 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
45068
45113
|
const compressedPages = {};
|
45069
45114
|
const mergedPageKeys = [...nonApiPages, ...apiPages, ...internalPages];
|
45070
45115
|
const traceCache = {};
|
45116
|
+
const getOriginalPagePath = (page) => {
|
45117
|
+
let originalPagePath = page;
|
45118
|
+
if (appDir && lambdaAppPaths[page]) {
|
45119
|
+
const { fsPath } = lambdaAppPaths[page];
|
45120
|
+
originalPagePath = path_1.default.relative(appDir, fsPath);
|
45121
|
+
}
|
45122
|
+
return originalPagePath;
|
45123
|
+
};
|
45124
|
+
const getBuildTraceFile = (page) => {
|
45125
|
+
return (pageBuildTraces[page + '.nft.json'] ||
|
45126
|
+
appBuildTraces[page + '.nft.json']);
|
45127
|
+
};
|
45071
45128
|
const pathsToTrace = mergedPageKeys
|
45072
45129
|
.map(page => {
|
45073
|
-
if (!
|
45130
|
+
if (!getBuildTraceFile(page)) {
|
45074
45131
|
return lambdaPages[page].fsPath;
|
45075
45132
|
}
|
45076
45133
|
})
|
@@ -45088,13 +45145,31 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
45088
45145
|
}
|
45089
45146
|
for (const page of mergedPageKeys) {
|
45090
45147
|
const tracedFiles = {};
|
45091
|
-
const
|
45148
|
+
const originalPagePath = getOriginalPagePath(page);
|
45149
|
+
const pageBuildTrace = getBuildTraceFile(originalPagePath);
|
45092
45150
|
let fileList;
|
45093
45151
|
let reasons;
|
45094
45152
|
if (pageBuildTrace) {
|
45095
45153
|
const { files } = JSON.parse(await fs_extra_1.default.readFile(pageBuildTrace.fsPath, 'utf8'));
|
45154
|
+
// TODO: this will be moved to a separate worker in the future
|
45155
|
+
// although currently this is needed in the lambda
|
45156
|
+
const isAppPath = appDir && lambdaAppPaths[page];
|
45157
|
+
const serverComponentFile = isAppPath
|
45158
|
+
? pageBuildTrace.fsPath.replace(/\.js\.nft\.json$/, '.__sc_client__.js')
|
45159
|
+
: null;
|
45160
|
+
if (serverComponentFile && (await fs_extra_1.default.pathExists(serverComponentFile))) {
|
45161
|
+
files.push(path_1.default.relative(path_1.default.dirname(pageBuildTrace.fsPath), serverComponentFile));
|
45162
|
+
try {
|
45163
|
+
const scTrace = JSON.parse(await fs_extra_1.default.readFile(`${serverComponentFile}.nft.json`, 'utf8'));
|
45164
|
+
scTrace.files.forEach((file) => files.push(file));
|
45165
|
+
}
|
45166
|
+
catch (err) {
|
45167
|
+
/* non-fatal for now */
|
45168
|
+
}
|
45169
|
+
}
|
45096
45170
|
fileList = [];
|
45097
|
-
const
|
45171
|
+
const curPagesDir = isAppPath && appDir ? appDir : pagesDir;
|
45172
|
+
const pageDir = path_1.default.dirname(path_1.default.join(curPagesDir, originalPagePath));
|
45098
45173
|
const normalizedBaseDir = `${baseDir}${baseDir.endsWith('/') ? '' : '/'}`;
|
45099
45174
|
files.forEach((file) => {
|
45100
45175
|
const absolutePath = path_1.default.join(pageDir, file);
|
@@ -45671,7 +45746,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
45671
45746
|
.map(route => {
|
45672
45747
|
route = Object.assign({}, route);
|
45673
45748
|
route.src = path_1.default.posix.join('^/', entryDirectory, '_next/data/', escapedBuildId, route.src.replace(/(^\^|\$$)/g, '') + '.json$');
|
45674
|
-
const { pathname } = new URL(route.dest || '/', 'http://n');
|
45749
|
+
const { pathname, search } = new URL(route.dest || '/', 'http://n');
|
45675
45750
|
let isPrerender = !!prerenders[path_1.default.join('./', pathname)];
|
45676
45751
|
if (routesManifest.i18n) {
|
45677
45752
|
for (const locale of routesManifest.i18n?.locales || []) {
|
@@ -45683,7 +45758,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
45683
45758
|
}
|
45684
45759
|
}
|
45685
45760
|
if (isPrerender) {
|
45686
|
-
route.dest = `/_next/data/${buildId}${pathname}.json`;
|
45761
|
+
route.dest = `/_next/data/${buildId}${pathname}.json${search || ''}`;
|
45687
45762
|
}
|
45688
45763
|
return route;
|
45689
45764
|
})
|
@@ -45784,31 +45859,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
45784
45859
|
status: 404,
|
45785
45860
|
},
|
45786
45861
|
]),
|
45787
|
-
//
|
45788
|
-
...(
|
45789
|
-
? [
|
45790
|
-
|
45791
|
-
|
45792
|
-
|
45793
|
-
|
45794
|
-
|
45795
|
-
|
45796
|
-
|
45797
|
-
|
45798
|
-
|
45799
|
-
|
45800
|
-
|
45801
|
-
|
45802
|
-
|
45803
|
-
|
45804
|
-
|
45805
|
-
|
45806
|
-
|
45807
|
-
|
45808
|
-
|
45809
|
-
|
45810
|
-
|
45811
|
-
|
45862
|
+
// custom 500 page if present
|
45863
|
+
...(i18n && (hasStatic500 || hasIsr500Page || lambdaPages['500.js'])
|
45864
|
+
? [
|
45865
|
+
{
|
45866
|
+
src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
|
45867
|
+
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
45868
|
+
.join('|')})(/.*|$)`,
|
45869
|
+
dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
|
45870
|
+
status: 500,
|
45871
|
+
caseSensitive: true,
|
45872
|
+
},
|
45873
|
+
{
|
45874
|
+
src: path_1.default.join('/', entryDirectory, '.*'),
|
45875
|
+
dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
|
45876
|
+
status: 500,
|
45877
|
+
},
|
45878
|
+
]
|
45879
|
+
: [
|
45880
|
+
{
|
45881
|
+
src: path_1.default.join('/', entryDirectory, '.*'),
|
45882
|
+
dest: path_1.default.join('/', entryDirectory, hasStatic500 ||
|
45883
|
+
hasIsr500Page ||
|
45884
|
+
lambdas[path_1.default.join(entryDirectory, '500')]
|
45885
|
+
? '/500'
|
45886
|
+
: '/_error'),
|
45887
|
+
status: 500,
|
45888
|
+
},
|
45889
|
+
]),
|
45812
45890
|
],
|
45813
45891
|
};
|
45814
45892
|
}
|
@@ -45942,7 +46020,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45942
46020
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
45943
46021
|
};
|
45944
46022
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
45945
|
-
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;
|
46023
|
+
exports.upgradeMiddlewareManifest = 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;
|
45946
46024
|
const build_utils_1 = __webpack_require__(3445);
|
45947
46025
|
const async_sema_1 = __webpack_require__(7916);
|
45948
46026
|
const buffer_crc32_1 = __importDefault(__webpack_require__(360));
|
@@ -47359,7 +47437,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
47359
47437
|
}),
|
47360
47438
|
});
|
47361
47439
|
})(),
|
47362
|
-
|
47440
|
+
routeMatchers: getRouteMatchers(edgeFunction, routesManifest),
|
47363
47441
|
};
|
47364
47442
|
}
|
47365
47443
|
catch (e) {
|
@@ -47382,26 +47460,29 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
47382
47460
|
if (worker.type === 'function') {
|
47383
47461
|
continue;
|
47384
47462
|
}
|
47385
|
-
const
|
47386
|
-
|
47387
|
-
|
47388
|
-
|
47389
|
-
|
47390
|
-
|
47391
|
-
|
47392
|
-
|
47393
|
-
|
47394
|
-
|
47395
|
-
|
47396
|
-
|
47397
|
-
|
47398
|
-
route.
|
47399
|
-
|
47400
|
-
|
47401
|
-
|
47402
|
-
|
47403
|
-
|
47404
|
-
|
47463
|
+
for (const matcher of worker.routeMatchers) {
|
47464
|
+
const route = {
|
47465
|
+
continue: true,
|
47466
|
+
src: matcher.regexp,
|
47467
|
+
has: matcher.has,
|
47468
|
+
missing: [
|
47469
|
+
{
|
47470
|
+
type: 'header',
|
47471
|
+
key: 'x-prerender-revalidate',
|
47472
|
+
value: prerenderBypassToken,
|
47473
|
+
},
|
47474
|
+
],
|
47475
|
+
};
|
47476
|
+
route.middlewarePath = shortPath;
|
47477
|
+
if (isCorrectMiddlewareOrder) {
|
47478
|
+
route.override = true;
|
47479
|
+
}
|
47480
|
+
if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
|
47481
|
+
source.dynamicRouteMap.set(worker.page, route);
|
47482
|
+
}
|
47483
|
+
else {
|
47484
|
+
source.staticRoutes.push(route);
|
47485
|
+
}
|
47405
47486
|
}
|
47406
47487
|
}
|
47407
47488
|
return source;
|
@@ -47427,28 +47508,70 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
|
|
47427
47508
|
if (!hasManifest) {
|
47428
47509
|
return;
|
47429
47510
|
}
|
47430
|
-
|
47511
|
+
const manifest = (await fs_extra_1.default.readJSON(middlewareManifestPath));
|
47512
|
+
return manifest.version === 1
|
47513
|
+
? upgradeMiddlewareManifest(manifest)
|
47514
|
+
: manifest;
|
47431
47515
|
}
|
47432
47516
|
exports.getMiddlewareManifest = getMiddlewareManifest;
|
47517
|
+
function upgradeMiddlewareManifest(v1) {
|
47518
|
+
function updateInfo(v1Info) {
|
47519
|
+
const { regexp, ...rest } = v1Info;
|
47520
|
+
return {
|
47521
|
+
...rest,
|
47522
|
+
matchers: [{ regexp }],
|
47523
|
+
};
|
47524
|
+
}
|
47525
|
+
const middleware = Object.fromEntries(Object.entries(v1.middleware).map(([p, info]) => [p, updateInfo(info)]));
|
47526
|
+
const functions = v1.functions
|
47527
|
+
? Object.fromEntries(Object.entries(v1.functions).map(([p, info]) => [p, updateInfo(info)]))
|
47528
|
+
: undefined;
|
47529
|
+
return {
|
47530
|
+
...v1,
|
47531
|
+
version: 2,
|
47532
|
+
middleware,
|
47533
|
+
functions,
|
47534
|
+
};
|
47535
|
+
}
|
47536
|
+
exports.upgradeMiddlewareManifest = upgradeMiddlewareManifest;
|
47433
47537
|
/**
|
47434
47538
|
* For an object containing middleware info and a routes manifest this will
|
47435
47539
|
* generate a string with the route that will activate the middleware on
|
47436
47540
|
* Vercel Proxy.
|
47437
47541
|
*
|
47438
|
-
* @param param0 The middleware info including
|
47542
|
+
* @param param0 The middleware info including matchers and page.
|
47439
47543
|
* @param param1 The routes manifest
|
47440
|
-
* @returns
|
47544
|
+
* @returns matchers for the middleware route.
|
47441
47545
|
*/
|
47442
|
-
function
|
47443
|
-
|
47444
|
-
|
47445
|
-
|
47446
|
-
|
47447
|
-
|
47448
|
-
|
47449
|
-
|
47450
|
-
|
47451
|
-
|
47546
|
+
function getRouteMatchers(info, { basePath = '', i18n }) {
|
47547
|
+
function getRegexp(regexp) {
|
47548
|
+
if (info.page === '/') {
|
47549
|
+
return regexp;
|
47550
|
+
}
|
47551
|
+
const locale = i18n?.locales.length
|
47552
|
+
? `(?:/(${i18n.locales
|
47553
|
+
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
47554
|
+
.join('|')}))?`
|
47555
|
+
: '';
|
47556
|
+
return `(?:^${basePath}${locale}${regexp.substring(1)})`;
|
47557
|
+
}
|
47558
|
+
function normalizeHas(has) {
|
47559
|
+
return has.map(v => v.type === 'header'
|
47560
|
+
? {
|
47561
|
+
...v,
|
47562
|
+
key: v.key.toLowerCase(),
|
47563
|
+
}
|
47564
|
+
: v);
|
47565
|
+
}
|
47566
|
+
return info.matchers.map(matcher => {
|
47567
|
+
const m = {
|
47568
|
+
regexp: getRegexp(matcher.regexp),
|
47569
|
+
};
|
47570
|
+
if (matcher.has) {
|
47571
|
+
m.has = normalizeHas(matcher.has);
|
47572
|
+
}
|
47573
|
+
return m;
|
47574
|
+
});
|
47452
47575
|
}
|
47453
47576
|
/**
|
47454
47577
|
* Makes the sources more human-readable in the source map
|
package/dist/server-build.js
CHANGED
@@ -21,13 +21,20 @@ const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
|
|
21
21
|
const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
|
22
22
|
const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
|
23
23
|
const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
|
24
|
-
async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, canUsePreviewMode, trailingSlash, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
|
24
|
+
async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs, baseDir, workPath, entryPath, nodeVersion, buildId, escapedBuildId, dynamicPrefix, entryDirectory, outputDirectory, redirects, beforeFilesRewrites, afterFilesRewrites, fallbackRewrites, headers, dataRoutes, hasIsr404Page, hasIsr500Page, imagesManifest, wildcardConfig, routesManifest, staticPages, lambdaPages, nextVersion, lambdaAppPaths, canUsePreviewMode, trailingSlash, prerenderManifest, appPathRoutesManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
|
25
|
+
lambdaPages = Object.assign({}, lambdaPages, lambdaAppPaths);
|
25
26
|
const lambdas = {};
|
26
27
|
const prerenders = {};
|
27
28
|
const lambdaPageKeys = Object.keys(lambdaPages);
|
28
29
|
const internalPages = ['_app.js', '_error.js', '_document.js'];
|
29
30
|
const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
|
30
31
|
const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
|
32
|
+
let appBuildTraces = {};
|
33
|
+
let appDir = null;
|
34
|
+
if (appPathRoutesManifest) {
|
35
|
+
appDir = path_1.default.join(pagesDir, '../app');
|
36
|
+
appBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', appDir);
|
37
|
+
}
|
31
38
|
const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
|
32
39
|
const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
|
33
40
|
const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
|
@@ -264,9 +271,21 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
264
271
|
const compressedPages = {};
|
265
272
|
const mergedPageKeys = [...nonApiPages, ...apiPages, ...internalPages];
|
266
273
|
const traceCache = {};
|
274
|
+
const getOriginalPagePath = (page) => {
|
275
|
+
let originalPagePath = page;
|
276
|
+
if (appDir && lambdaAppPaths[page]) {
|
277
|
+
const { fsPath } = lambdaAppPaths[page];
|
278
|
+
originalPagePath = path_1.default.relative(appDir, fsPath);
|
279
|
+
}
|
280
|
+
return originalPagePath;
|
281
|
+
};
|
282
|
+
const getBuildTraceFile = (page) => {
|
283
|
+
return (pageBuildTraces[page + '.nft.json'] ||
|
284
|
+
appBuildTraces[page + '.nft.json']);
|
285
|
+
};
|
267
286
|
const pathsToTrace = mergedPageKeys
|
268
287
|
.map(page => {
|
269
|
-
if (!
|
288
|
+
if (!getBuildTraceFile(page)) {
|
270
289
|
return lambdaPages[page].fsPath;
|
271
290
|
}
|
272
291
|
})
|
@@ -284,13 +303,31 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
284
303
|
}
|
285
304
|
for (const page of mergedPageKeys) {
|
286
305
|
const tracedFiles = {};
|
287
|
-
const
|
306
|
+
const originalPagePath = getOriginalPagePath(page);
|
307
|
+
const pageBuildTrace = getBuildTraceFile(originalPagePath);
|
288
308
|
let fileList;
|
289
309
|
let reasons;
|
290
310
|
if (pageBuildTrace) {
|
291
311
|
const { files } = JSON.parse(await fs_extra_1.default.readFile(pageBuildTrace.fsPath, 'utf8'));
|
312
|
+
// TODO: this will be moved to a separate worker in the future
|
313
|
+
// although currently this is needed in the lambda
|
314
|
+
const isAppPath = appDir && lambdaAppPaths[page];
|
315
|
+
const serverComponentFile = isAppPath
|
316
|
+
? pageBuildTrace.fsPath.replace(/\.js\.nft\.json$/, '.__sc_client__.js')
|
317
|
+
: null;
|
318
|
+
if (serverComponentFile && (await fs_extra_1.default.pathExists(serverComponentFile))) {
|
319
|
+
files.push(path_1.default.relative(path_1.default.dirname(pageBuildTrace.fsPath), serverComponentFile));
|
320
|
+
try {
|
321
|
+
const scTrace = JSON.parse(await fs_extra_1.default.readFile(`${serverComponentFile}.nft.json`, 'utf8'));
|
322
|
+
scTrace.files.forEach((file) => files.push(file));
|
323
|
+
}
|
324
|
+
catch (err) {
|
325
|
+
/* non-fatal for now */
|
326
|
+
}
|
327
|
+
}
|
292
328
|
fileList = [];
|
293
|
-
const
|
329
|
+
const curPagesDir = isAppPath && appDir ? appDir : pagesDir;
|
330
|
+
const pageDir = path_1.default.dirname(path_1.default.join(curPagesDir, originalPagePath));
|
294
331
|
const normalizedBaseDir = `${baseDir}${baseDir.endsWith('/') ? '' : '/'}`;
|
295
332
|
files.forEach((file) => {
|
296
333
|
const absolutePath = path_1.default.join(pageDir, file);
|
@@ -867,7 +904,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
867
904
|
.map(route => {
|
868
905
|
route = Object.assign({}, route);
|
869
906
|
route.src = path_1.default.posix.join('^/', entryDirectory, '_next/data/', escapedBuildId, route.src.replace(/(^\^|\$$)/g, '') + '.json$');
|
870
|
-
const { pathname } = new URL(route.dest || '/', 'http://n');
|
907
|
+
const { pathname, search } = new URL(route.dest || '/', 'http://n');
|
871
908
|
let isPrerender = !!prerenders[path_1.default.join('./', pathname)];
|
872
909
|
if (routesManifest.i18n) {
|
873
910
|
for (const locale of routesManifest.i18n?.locales || []) {
|
@@ -879,7 +916,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
879
916
|
}
|
880
917
|
}
|
881
918
|
if (isPrerender) {
|
882
|
-
route.dest = `/_next/data/${buildId}${pathname}.json`;
|
919
|
+
route.dest = `/_next/data/${buildId}${pathname}.json${search || ''}`;
|
883
920
|
}
|
884
921
|
return route;
|
885
922
|
})
|
@@ -980,31 +1017,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
|
|
980
1017
|
status: 404,
|
981
1018
|
},
|
982
1019
|
]),
|
983
|
-
//
|
984
|
-
...(
|
985
|
-
? [
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1020
|
+
// custom 500 page if present
|
1021
|
+
...(i18n && (hasStatic500 || hasIsr500Page || lambdaPages['500.js'])
|
1022
|
+
? [
|
1023
|
+
{
|
1024
|
+
src: `${path_1.default.join('/', entryDirectory, '/')}(?<nextLocale>${i18n.locales
|
1025
|
+
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
1026
|
+
.join('|')})(/.*|$)`,
|
1027
|
+
dest: path_1.default.join('/', entryDirectory, '/$nextLocale/500'),
|
1028
|
+
status: 500,
|
1029
|
+
caseSensitive: true,
|
1030
|
+
},
|
1031
|
+
{
|
1032
|
+
src: path_1.default.join('/', entryDirectory, '.*'),
|
1033
|
+
dest: path_1.default.join('/', entryDirectory, `/${i18n.defaultLocale}/500`),
|
1034
|
+
status: 500,
|
1035
|
+
},
|
1036
|
+
]
|
1037
|
+
: [
|
1038
|
+
{
|
1039
|
+
src: path_1.default.join('/', entryDirectory, '.*'),
|
1040
|
+
dest: path_1.default.join('/', entryDirectory, hasStatic500 ||
|
1041
|
+
hasIsr500Page ||
|
1042
|
+
lambdas[path_1.default.join(entryDirectory, '500')]
|
1043
|
+
? '/500'
|
1044
|
+
: '/_error'),
|
1045
|
+
status: 500,
|
1046
|
+
},
|
1047
|
+
]),
|
1008
1048
|
],
|
1009
1049
|
};
|
1010
1050
|
}
|
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.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;
|
25
|
+
exports.upgradeMiddlewareManifest = 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"));
|
@@ -1439,7 +1439,7 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1439
1439
|
}),
|
1440
1440
|
});
|
1441
1441
|
})(),
|
1442
|
-
|
1442
|
+
routeMatchers: getRouteMatchers(edgeFunction, routesManifest),
|
1443
1443
|
};
|
1444
1444
|
}
|
1445
1445
|
catch (e) {
|
@@ -1462,26 +1462,29 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
|
|
1462
1462
|
if (worker.type === 'function') {
|
1463
1463
|
continue;
|
1464
1464
|
}
|
1465
|
-
const
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
route.
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1465
|
+
for (const matcher of worker.routeMatchers) {
|
1466
|
+
const route = {
|
1467
|
+
continue: true,
|
1468
|
+
src: matcher.regexp,
|
1469
|
+
has: matcher.has,
|
1470
|
+
missing: [
|
1471
|
+
{
|
1472
|
+
type: 'header',
|
1473
|
+
key: 'x-prerender-revalidate',
|
1474
|
+
value: prerenderBypassToken,
|
1475
|
+
},
|
1476
|
+
],
|
1477
|
+
};
|
1478
|
+
route.middlewarePath = shortPath;
|
1479
|
+
if (isCorrectMiddlewareOrder) {
|
1480
|
+
route.override = true;
|
1481
|
+
}
|
1482
|
+
if (routesManifest.version > 3 && isDynamicRoute(worker.page)) {
|
1483
|
+
source.dynamicRouteMap.set(worker.page, route);
|
1484
|
+
}
|
1485
|
+
else {
|
1486
|
+
source.staticRoutes.push(route);
|
1487
|
+
}
|
1485
1488
|
}
|
1486
1489
|
}
|
1487
1490
|
return source;
|
@@ -1507,28 +1510,70 @@ async function getMiddlewareManifest(entryPath, outputDirectory) {
|
|
1507
1510
|
if (!hasManifest) {
|
1508
1511
|
return;
|
1509
1512
|
}
|
1510
|
-
|
1513
|
+
const manifest = (await fs_extra_1.default.readJSON(middlewareManifestPath));
|
1514
|
+
return manifest.version === 1
|
1515
|
+
? upgradeMiddlewareManifest(manifest)
|
1516
|
+
: manifest;
|
1511
1517
|
}
|
1512
1518
|
exports.getMiddlewareManifest = getMiddlewareManifest;
|
1519
|
+
function upgradeMiddlewareManifest(v1) {
|
1520
|
+
function updateInfo(v1Info) {
|
1521
|
+
const { regexp, ...rest } = v1Info;
|
1522
|
+
return {
|
1523
|
+
...rest,
|
1524
|
+
matchers: [{ regexp }],
|
1525
|
+
};
|
1526
|
+
}
|
1527
|
+
const middleware = Object.fromEntries(Object.entries(v1.middleware).map(([p, info]) => [p, updateInfo(info)]));
|
1528
|
+
const functions = v1.functions
|
1529
|
+
? Object.fromEntries(Object.entries(v1.functions).map(([p, info]) => [p, updateInfo(info)]))
|
1530
|
+
: undefined;
|
1531
|
+
return {
|
1532
|
+
...v1,
|
1533
|
+
version: 2,
|
1534
|
+
middleware,
|
1535
|
+
functions,
|
1536
|
+
};
|
1537
|
+
}
|
1538
|
+
exports.upgradeMiddlewareManifest = upgradeMiddlewareManifest;
|
1513
1539
|
/**
|
1514
1540
|
* For an object containing middleware info and a routes manifest this will
|
1515
1541
|
* generate a string with the route that will activate the middleware on
|
1516
1542
|
* Vercel Proxy.
|
1517
1543
|
*
|
1518
|
-
* @param param0 The middleware info including
|
1544
|
+
* @param param0 The middleware info including matchers and page.
|
1519
1545
|
* @param param1 The routes manifest
|
1520
|
-
* @returns
|
1546
|
+
* @returns matchers for the middleware route.
|
1521
1547
|
*/
|
1522
|
-
function
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1548
|
+
function getRouteMatchers(info, { basePath = '', i18n }) {
|
1549
|
+
function getRegexp(regexp) {
|
1550
|
+
if (info.page === '/') {
|
1551
|
+
return regexp;
|
1552
|
+
}
|
1553
|
+
const locale = i18n?.locales.length
|
1554
|
+
? `(?:/(${i18n.locales
|
1555
|
+
.map(locale => (0, escape_string_regexp_1.default)(locale))
|
1556
|
+
.join('|')}))?`
|
1557
|
+
: '';
|
1558
|
+
return `(?:^${basePath}${locale}${regexp.substring(1)})`;
|
1559
|
+
}
|
1560
|
+
function normalizeHas(has) {
|
1561
|
+
return has.map(v => v.type === 'header'
|
1562
|
+
? {
|
1563
|
+
...v,
|
1564
|
+
key: v.key.toLowerCase(),
|
1565
|
+
}
|
1566
|
+
: v);
|
1567
|
+
}
|
1568
|
+
return info.matchers.map(matcher => {
|
1569
|
+
const m = {
|
1570
|
+
regexp: getRegexp(matcher.regexp),
|
1571
|
+
};
|
1572
|
+
if (matcher.has) {
|
1573
|
+
m.has = normalizeHas(matcher.has);
|
1574
|
+
}
|
1575
|
+
return m;
|
1576
|
+
});
|
1532
1577
|
}
|
1533
1578
|
/**
|
1534
1579
|
* Makes the sources more human-readable in the source map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/next",
|
3
|
-
"version": "3.1.
|
3
|
+
"version": "3.1.22",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
@@ -44,8 +44,8 @@
|
|
44
44
|
"@types/semver": "6.0.0",
|
45
45
|
"@types/text-table": "0.2.1",
|
46
46
|
"@types/webpack-sources": "3.2.0",
|
47
|
-
"@vercel/build-utils": "5.
|
48
|
-
"@vercel/nft": "0.
|
47
|
+
"@vercel/build-utils": "5.4.0",
|
48
|
+
"@vercel/nft": "0.22.0",
|
49
49
|
"@vercel/routing-utils": "2.0.2",
|
50
50
|
"async-sema": "3.0.1",
|
51
51
|
"buffer-crc32": "0.2.13",
|
@@ -69,5 +69,5 @@
|
|
69
69
|
"typescript": "4.5.2",
|
70
70
|
"webpack-sources": "3.2.3"
|
71
71
|
},
|
72
|
-
"gitHead": "
|
72
|
+
"gitHead": "e7e0a55b72bc73c26661f7b2a3caa0884a5d1764"
|
73
73
|
}
|