@vercel/next 3.1.5 → 3.1.8

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 CHANGED
@@ -44633,14 +44633,18 @@ const pretty_bytes_1 = __importDefault(__webpack_require__(539));
44633
44633
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
44634
44634
  const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
44635
44635
  const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
44636
+ const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
44637
+ const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
44636
44638
  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, }) {
44637
44639
  const lambdas = {};
44638
44640
  const prerenders = {};
44639
44641
  const lambdaPageKeys = Object.keys(lambdaPages);
44640
44642
  const internalPages = ['_app.js', '_error.js', '_document.js'];
44641
44643
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
44644
+ const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
44642
44645
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
44643
44646
  const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
44647
+ const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
44644
44648
  let hasStatic500 = !!staticPages[path_1.default.join(entryDirectory, '500')];
44645
44649
  if (lambdaPageKeys.length === 0) {
44646
44650
  throw new build_utils_1.NowBuildError({
@@ -44819,7 +44823,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
44819
44823
  if (requiredServerFilesManifest.appDir) {
44820
44824
  fsPath = path_1.default.join(requiredServerFilesManifest.appDir, file);
44821
44825
  }
44822
- const relativePath = path_1.default.join(path_1.default.relative(baseDir, fsPath));
44826
+ const relativePath = path_1.default.relative(baseDir, fsPath);
44823
44827
  const { mode } = await fs_extra_1.default.lstat(fsPath);
44824
44828
  lstatSema.release();
44825
44829
  requiredFiles[relativePath] = new build_utils_1.FileFsRef({
@@ -44975,16 +44979,67 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
44975
44979
  const combinedGroups = [...pageLambdaGroups, ...apiLambdaGroups];
44976
44980
  await (0, utils_1.detectLambdaLimitExceeding)(combinedGroups, lambdaCompressedByteLimit, compressedPages);
44977
44981
  for (const group of combinedGroups) {
44982
+ const groupPageFiles = {};
44983
+ for (const page of [...group.pages, ...internalPages]) {
44984
+ const pageFileName = path_1.default.normalize(path_1.default.relative(baseDir, lambdaPages[page].fsPath));
44985
+ groupPageFiles[pageFileName] = compressedPages[page];
44986
+ }
44987
+ const updatedManifestFiles = {};
44988
+ if (isCorrectManifests) {
44989
+ // filter dynamic routes to only the included dynamic routes
44990
+ // in this specific serverless function so that we don't
44991
+ // accidentally match a dynamic route while resolving that
44992
+ // is not actually in this specific serverless function
44993
+ for (const manifest of [
44994
+ 'routes-manifest.json',
44995
+ 'server/pages-manifest.json',
44996
+ ]) {
44997
+ const fsPath = path_1.default.join(entryPath, outputDirectory, manifest);
44998
+ const relativePath = path_1.default.relative(baseDir, fsPath);
44999
+ delete group.pseudoLayer[relativePath];
45000
+ const manifestData = await fs_extra_1.default.readJSON(fsPath);
45001
+ const normalizedPages = new Set(group.pages.map(page => {
45002
+ page = `/${page.replace(/\.js$/, '')}`;
45003
+ if (page === '/index')
45004
+ page = '/';
45005
+ return page;
45006
+ }));
45007
+ switch (manifest) {
45008
+ case 'routes-manifest.json': {
45009
+ const filterItem = (item) => normalizedPages.has(item.page);
45010
+ manifestData.dynamicRoutes =
45011
+ manifestData.dynamicRoutes?.filter(filterItem);
45012
+ manifestData.staticRoutes =
45013
+ manifestData.staticRoutes?.filter(filterItem);
45014
+ break;
45015
+ }
45016
+ case 'server/pages-manifest.json': {
45017
+ for (const key of Object.keys(manifestData)) {
45018
+ if ((0, utils_1.isDynamicRoute)(key) && !normalizedPages.has(key)) {
45019
+ delete manifestData[key];
45020
+ }
45021
+ }
45022
+ break;
45023
+ }
45024
+ default: {
45025
+ throw new build_utils_1.NowBuildError({
45026
+ message: `Unexpected manifest value ${manifest}, please contact support if this continues`,
45027
+ code: 'NEXT_MANIFEST_INVARIANT',
45028
+ });
45029
+ }
45030
+ }
45031
+ updatedManifestFiles[relativePath] = new build_utils_1.FileBlob({
45032
+ contentType: 'application/json',
45033
+ data: JSON.stringify(manifestData),
45034
+ });
45035
+ }
45036
+ }
44978
45037
  const lambda = await (0, utils_1.createLambdaFromPseudoLayers)({
44979
- files: launcherFiles,
44980
- layers: [
44981
- group.pseudoLayer,
44982
- [...group.pages, ...internalPages].reduce((prev, page) => {
44983
- const pageFileName = path_1.default.normalize(path_1.default.relative(baseDir, lambdaPages[page].fsPath));
44984
- prev[pageFileName] = compressedPages[page];
44985
- return prev;
44986
- }, {}),
44987
- ],
45038
+ files: {
45039
+ ...launcherFiles,
45040
+ ...updatedManifestFiles,
45041
+ },
45042
+ layers: [group.pseudoLayer, groupPageFiles],
44988
45043
  handler: path_1.default.join(path_1.default.relative(baseDir, requiredServerFilesManifest.appDir || entryPath), '___next_launcher.cjs'),
44989
45044
  memory: group.memory,
44990
45045
  runtime: nodeVersion.runtime,
@@ -45030,6 +45085,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
45030
45085
  static404Page,
45031
45086
  hasPages404: routesManifest.pages404,
45032
45087
  isCorrectNotFoundRoutes,
45088
+ isEmptyAllowQueryForPrendered,
45033
45089
  });
45034
45090
  Object.keys(prerenderManifest.staticRoutes).forEach(route => prerenderRoute(route, {}));
45035
45091
  Object.keys(prerenderManifest.fallbackRoutes).forEach(route => prerenderRoute(route, { isFallback: true }));
@@ -46679,7 +46735,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
46679
46735
  exports.onPrerenderRouteInitial = onPrerenderRouteInitial;
46680
46736
  let prerenderGroup = 1;
46681
46737
  const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFallback, isOmitted, locale, }) => {
46682
- const { pagesDir, hasPages404, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, } = prerenderRouteArgs;
46738
+ const { pagesDir, hasPages404, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
46683
46739
  if (isBlocking && isFallback) {
46684
46740
  throw new build_utils_1.NowBuildError({
46685
46741
  code: 'NEXT_ISBLOCKING_ISFALLBACK',
@@ -46819,21 +46875,39 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
46819
46875
  // a given path. All other query keys will be striped. We can automatically
46820
46876
  // detect this for prerender (ISR) pages by reading the routes manifest file.
46821
46877
  const pageKey = srcRoute || routeKey;
46822
- const isDynamic = isDynamicRoute(pageKey);
46823
46878
  const route = routesManifest?.dynamicRoutes.find((r) => r.page === pageKey && !('isMiddleware' in r));
46824
46879
  const routeKeys = route?.routeKeys;
46825
46880
  // by default allowQuery should be undefined and only set when
46826
46881
  // we have sufficient information to set it
46827
46882
  let allowQuery;
46828
- if (routeKeys) {
46829
- // if we have routeKeys in the routes-manifest we use those
46830
- // for allowQuery for dynamic routes
46831
- allowQuery = Object.values(routeKeys);
46832
- }
46833
- else if (!isDynamic) {
46834
- // for non-dynamic routes we use an empty array since
46835
- // no query values bust the cache for non-dynamic prerenders
46836
- allowQuery = [];
46883
+ if (isEmptyAllowQueryForPrendered) {
46884
+ const isDynamic = isDynamicRoute(routeKey);
46885
+ if (!isDynamic) {
46886
+ // for non-dynamic routes we use an empty array since
46887
+ // no query values bust the cache for non-dynamic prerenders
46888
+ // prerendered paths also do not pass allowQuery as they match
46889
+ // during handle: 'filesystem' so should not cache differently
46890
+ // by query values
46891
+ allowQuery = [];
46892
+ }
46893
+ else if (routeKeys) {
46894
+ // if we have routeKeys in the routes-manifest we use those
46895
+ // for allowQuery for dynamic routes
46896
+ allowQuery = Object.values(routeKeys);
46897
+ }
46898
+ }
46899
+ else {
46900
+ const isDynamic = isDynamicRoute(pageKey);
46901
+ if (routeKeys) {
46902
+ // if we have routeKeys in the routes-manifest we use those
46903
+ // for allowQuery for dynamic routes
46904
+ allowQuery = Object.values(routeKeys);
46905
+ }
46906
+ else if (!isDynamic) {
46907
+ // for non-dynamic routes we use an empty array since
46908
+ // no query values bust the cache for non-dynamic prerenders
46909
+ allowQuery = [];
46910
+ }
46837
46911
  }
46838
46912
  prerenders[outputPathPage] = new build_utils_1.Prerender({
46839
46913
  expiration: initialRevalidate,
@@ -19,14 +19,18 @@ const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
19
19
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
20
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
+ const EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION = 'v12.2.0';
23
+ const CORRECTED_MANIFESTS_VERSION = 'v12.2.0';
22
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, }) {
23
25
  const lambdas = {};
24
26
  const prerenders = {};
25
27
  const lambdaPageKeys = Object.keys(lambdaPages);
26
28
  const internalPages = ['_app.js', '_error.js', '_document.js'];
27
29
  const pageBuildTraces = await (0, build_utils_1.glob)('**/*.js.nft.json', pagesDir);
30
+ const isEmptyAllowQueryForPrendered = semver_1.default.gte(nextVersion, EMPTY_ALLOW_QUERY_FOR_PRERENDERED_VERSION);
28
31
  const isCorrectNotFoundRoutes = semver_1.default.gte(nextVersion, CORRECT_NOT_FOUND_ROUTES_VERSION);
29
32
  const isCorrectMiddlewareOrder = semver_1.default.gte(nextVersion, CORRECT_MIDDLEWARE_ORDER_VERSION);
33
+ const isCorrectManifests = semver_1.default.gte(nextVersion, CORRECTED_MANIFESTS_VERSION);
30
34
  let hasStatic500 = !!staticPages[path_1.default.join(entryDirectory, '500')];
31
35
  if (lambdaPageKeys.length === 0) {
32
36
  throw new build_utils_1.NowBuildError({
@@ -205,7 +209,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
205
209
  if (requiredServerFilesManifest.appDir) {
206
210
  fsPath = path_1.default.join(requiredServerFilesManifest.appDir, file);
207
211
  }
208
- const relativePath = path_1.default.join(path_1.default.relative(baseDir, fsPath));
212
+ const relativePath = path_1.default.relative(baseDir, fsPath);
209
213
  const { mode } = await fs_extra_1.default.lstat(fsPath);
210
214
  lstatSema.release();
211
215
  requiredFiles[relativePath] = new build_utils_1.FileFsRef({
@@ -361,16 +365,67 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
361
365
  const combinedGroups = [...pageLambdaGroups, ...apiLambdaGroups];
362
366
  await (0, utils_1.detectLambdaLimitExceeding)(combinedGroups, lambdaCompressedByteLimit, compressedPages);
363
367
  for (const group of combinedGroups) {
368
+ const groupPageFiles = {};
369
+ for (const page of [...group.pages, ...internalPages]) {
370
+ const pageFileName = path_1.default.normalize(path_1.default.relative(baseDir, lambdaPages[page].fsPath));
371
+ groupPageFiles[pageFileName] = compressedPages[page];
372
+ }
373
+ const updatedManifestFiles = {};
374
+ if (isCorrectManifests) {
375
+ // filter dynamic routes to only the included dynamic routes
376
+ // in this specific serverless function so that we don't
377
+ // accidentally match a dynamic route while resolving that
378
+ // is not actually in this specific serverless function
379
+ for (const manifest of [
380
+ 'routes-manifest.json',
381
+ 'server/pages-manifest.json',
382
+ ]) {
383
+ const fsPath = path_1.default.join(entryPath, outputDirectory, manifest);
384
+ const relativePath = path_1.default.relative(baseDir, fsPath);
385
+ delete group.pseudoLayer[relativePath];
386
+ const manifestData = await fs_extra_1.default.readJSON(fsPath);
387
+ const normalizedPages = new Set(group.pages.map(page => {
388
+ page = `/${page.replace(/\.js$/, '')}`;
389
+ if (page === '/index')
390
+ page = '/';
391
+ return page;
392
+ }));
393
+ switch (manifest) {
394
+ case 'routes-manifest.json': {
395
+ const filterItem = (item) => normalizedPages.has(item.page);
396
+ manifestData.dynamicRoutes =
397
+ manifestData.dynamicRoutes?.filter(filterItem);
398
+ manifestData.staticRoutes =
399
+ manifestData.staticRoutes?.filter(filterItem);
400
+ break;
401
+ }
402
+ case 'server/pages-manifest.json': {
403
+ for (const key of Object.keys(manifestData)) {
404
+ if ((0, utils_1.isDynamicRoute)(key) && !normalizedPages.has(key)) {
405
+ delete manifestData[key];
406
+ }
407
+ }
408
+ break;
409
+ }
410
+ default: {
411
+ throw new build_utils_1.NowBuildError({
412
+ message: `Unexpected manifest value ${manifest}, please contact support if this continues`,
413
+ code: 'NEXT_MANIFEST_INVARIANT',
414
+ });
415
+ }
416
+ }
417
+ updatedManifestFiles[relativePath] = new build_utils_1.FileBlob({
418
+ contentType: 'application/json',
419
+ data: JSON.stringify(manifestData),
420
+ });
421
+ }
422
+ }
364
423
  const lambda = await (0, utils_1.createLambdaFromPseudoLayers)({
365
- files: launcherFiles,
366
- layers: [
367
- group.pseudoLayer,
368
- [...group.pages, ...internalPages].reduce((prev, page) => {
369
- const pageFileName = path_1.default.normalize(path_1.default.relative(baseDir, lambdaPages[page].fsPath));
370
- prev[pageFileName] = compressedPages[page];
371
- return prev;
372
- }, {}),
373
- ],
424
+ files: {
425
+ ...launcherFiles,
426
+ ...updatedManifestFiles,
427
+ },
428
+ layers: [group.pseudoLayer, groupPageFiles],
374
429
  handler: path_1.default.join(path_1.default.relative(baseDir, requiredServerFilesManifest.appDir || entryPath), '___next_launcher.cjs'),
375
430
  memory: group.memory,
376
431
  runtime: nodeVersion.runtime,
@@ -416,6 +471,7 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
416
471
  static404Page,
417
472
  hasPages404: routesManifest.pages404,
418
473
  isCorrectNotFoundRoutes,
474
+ isEmptyAllowQueryForPrendered,
419
475
  });
420
476
  Object.keys(prerenderManifest.staticRoutes).forEach(route => prerenderRoute(route, {}));
421
477
  Object.keys(prerenderManifest.fallbackRoutes).forEach(route => prerenderRoute(route, { isFallback: true }));
package/dist/utils.js CHANGED
@@ -1027,7 +1027,7 @@ const onPrerenderRouteInitial = (prerenderManifest, canUsePreviewMode, entryDire
1027
1027
  exports.onPrerenderRouteInitial = onPrerenderRouteInitial;
1028
1028
  let prerenderGroup = 1;
1029
1029
  const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFallback, isOmitted, locale, }) => {
1030
- const { pagesDir, hasPages404, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, } = prerenderRouteArgs;
1030
+ const { pagesDir, hasPages404, static404Page, entryDirectory, prerenderManifest, isSharedLambdas, isServerMode, canUsePreviewMode, lambdas, prerenders, pageLambdaMap, routesManifest, isCorrectNotFoundRoutes, isEmptyAllowQueryForPrendered, } = prerenderRouteArgs;
1031
1031
  if (isBlocking && isFallback) {
1032
1032
  throw new build_utils_1.NowBuildError({
1033
1033
  code: 'NEXT_ISBLOCKING_ISFALLBACK',
@@ -1167,21 +1167,39 @@ const onPrerenderRoute = (prerenderRouteArgs) => (routeKey, { isBlocking, isFall
1167
1167
  // a given path. All other query keys will be striped. We can automatically
1168
1168
  // detect this for prerender (ISR) pages by reading the routes manifest file.
1169
1169
  const pageKey = srcRoute || routeKey;
1170
- const isDynamic = isDynamicRoute(pageKey);
1171
1170
  const route = routesManifest?.dynamicRoutes.find((r) => r.page === pageKey && !('isMiddleware' in r));
1172
1171
  const routeKeys = route?.routeKeys;
1173
1172
  // by default allowQuery should be undefined and only set when
1174
1173
  // we have sufficient information to set it
1175
1174
  let allowQuery;
1176
- if (routeKeys) {
1177
- // if we have routeKeys in the routes-manifest we use those
1178
- // for allowQuery for dynamic routes
1179
- allowQuery = Object.values(routeKeys);
1175
+ if (isEmptyAllowQueryForPrendered) {
1176
+ const isDynamic = isDynamicRoute(routeKey);
1177
+ if (!isDynamic) {
1178
+ // for non-dynamic routes we use an empty array since
1179
+ // no query values bust the cache for non-dynamic prerenders
1180
+ // prerendered paths also do not pass allowQuery as they match
1181
+ // during handle: 'filesystem' so should not cache differently
1182
+ // by query values
1183
+ allowQuery = [];
1184
+ }
1185
+ else if (routeKeys) {
1186
+ // if we have routeKeys in the routes-manifest we use those
1187
+ // for allowQuery for dynamic routes
1188
+ allowQuery = Object.values(routeKeys);
1189
+ }
1180
1190
  }
1181
- else if (!isDynamic) {
1182
- // for non-dynamic routes we use an empty array since
1183
- // no query values bust the cache for non-dynamic prerenders
1184
- allowQuery = [];
1191
+ else {
1192
+ const isDynamic = isDynamicRoute(pageKey);
1193
+ if (routeKeys) {
1194
+ // if we have routeKeys in the routes-manifest we use those
1195
+ // for allowQuery for dynamic routes
1196
+ allowQuery = Object.values(routeKeys);
1197
+ }
1198
+ else if (!isDynamic) {
1199
+ // for non-dynamic routes we use an empty array since
1200
+ // no query values bust the cache for non-dynamic prerenders
1201
+ allowQuery = [];
1202
+ }
1185
1203
  }
1186
1204
  prerenders[outputPathPage] = new build_utils_1.Prerender({
1187
1205
  expiration: initialRevalidate,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.1.5",
3
+ "version": "3.1.8",
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": "5.0.2",
48
+ "@vercel/build-utils": "5.0.4",
49
49
  "@vercel/nft": "0.20.1",
50
- "@vercel/routing-utils": "1.13.5",
50
+ "@vercel/routing-utils": "2.0.0",
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": "d2f8d178f77e15cb490cce73f5766537d892f763"
73
+ "gitHead": "3d3774ee7e3d344b3292d2166d485bdf41a68d4c"
74
74
  }