@vercel/next 3.0.1 → 3.0.2-canary.2

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
@@ -45724,6 +45724,7 @@ const build = async ({ files, workPath, repoRootPath, entrypoint, config = {}, m
45724
45724
  entryPath,
45725
45725
  baseDir,
45726
45726
  dataRoutes,
45727
+ buildId,
45727
45728
  escapedBuildId,
45728
45729
  outputDirectory,
45729
45730
  trailingSlashRedirects,
@@ -47023,7 +47024,8 @@ const pretty_bytes_1 = __importDefault(__webpack_require__(539));
47023
47024
  // related PR: https://github.com/vercel/next.js/pull/30046
47024
47025
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
47025
47026
  const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
47026
- 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, }) {
47027
+ const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
47028
+ 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, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
47027
47029
  const lambdas = {};
47028
47030
  const prerenders = {};
47029
47031
  const lambdaPageKeys = Object.keys(lambdaPages);
@@ -47422,6 +47424,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47422
47424
  routesManifest,
47423
47425
  isCorrectMiddlewareOrder,
47424
47426
  });
47427
+ const isNextDataServerResolving = middleware.staticRoutes.length > 0 &&
47428
+ semver_1.default.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
47425
47429
  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));
47426
47430
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
47427
47431
  const notFoundPreviewRoutes = [];
@@ -47464,6 +47468,52 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47464
47468
  }
47465
47469
  }
47466
47470
  }
47471
+ const normalizeNextDataRoute = (isOverride = false) => {
47472
+ return isNextDataServerResolving
47473
+ ? [
47474
+ // strip _next/data prefix for resolving
47475
+ {
47476
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
47477
+ dest: `${path_1.default.join('/', entryDirectory, '/$1')}`,
47478
+ ...(isOverride ? { override: true } : {}),
47479
+ continue: true,
47480
+ has: [
47481
+ {
47482
+ type: 'header',
47483
+ key: 'x-nextjs-data',
47484
+ },
47485
+ ],
47486
+ },
47487
+ ]
47488
+ : [];
47489
+ };
47490
+ const denormalizeNextDataRoute = (isOverride = false) => {
47491
+ return isNextDataServerResolving
47492
+ ? [
47493
+ {
47494
+ src: '/(.*)',
47495
+ has: [
47496
+ {
47497
+ type: 'header',
47498
+ key: 'x-nextjs-data',
47499
+ },
47500
+ ],
47501
+ dest: `${path_1.default.join('/', entryDirectory, '/_next/data/', buildId, '/$1.json')}`,
47502
+ continue: true,
47503
+ ...(isOverride ? { override: true } : {}),
47504
+ },
47505
+ ]
47506
+ : [];
47507
+ };
47508
+ let nextDataCatchallOutput = undefined;
47509
+ if (isNextDataServerResolving) {
47510
+ const catchallFsPath = path_1.default.join(entryPath, outputDirectory, '__next_data_catchall.json');
47511
+ await fs_extra_1.default.writeFile(catchallFsPath, '{}');
47512
+ nextDataCatchallOutput = new build_utils_1.FileFsRef({
47513
+ contentType: 'application/json',
47514
+ fsPath: catchallFsPath,
47515
+ });
47516
+ }
47467
47517
  return {
47468
47518
  wildcard: wildcardConfig,
47469
47519
  images: imagesManifest?.images?.loader === 'default'
@@ -47487,6 +47537,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47487
47537
  ...staticDirectoryFiles,
47488
47538
  ...privateOutputs.files,
47489
47539
  ...middleware.edgeFunctions,
47540
+ ...(isNextDataServerResolving
47541
+ ? {
47542
+ __next_data_catchall: nextDataCatchallOutput,
47543
+ }
47544
+ : {}),
47490
47545
  },
47491
47546
  routes: [
47492
47547
  /*
@@ -47504,6 +47559,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47504
47559
  // trailing slash
47505
47560
  ...trailingSlashRedirects,
47506
47561
  ...privateOutputs.routes,
47562
+ // normalize _next/data URL before processing redirects
47563
+ ...normalizeNextDataRoute(true),
47507
47564
  ...(i18n
47508
47565
  ? [
47509
47566
  // Handle auto-adding current default locale to path based on
@@ -47629,6 +47686,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47629
47686
  continue: true,
47630
47687
  },
47631
47688
  ]),
47689
+ // we need to undo _next/data normalize before checking filesystem
47690
+ ...denormalizeNextDataRoute(true),
47632
47691
  // while middleware was in beta the order came right before
47633
47692
  // handle: 'filesystem' we maintain this for older versions
47634
47693
  // to prevent a local/deploy mismatch
@@ -47647,13 +47706,19 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47647
47706
  },
47648
47707
  ]
47649
47708
  : []),
47650
- // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
47651
- // if no match to prevent rewriting _next/data unexpectedly
47652
- {
47653
- src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47654
- dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
47655
- check: true,
47656
- },
47709
+ // normalize _next/data URL before processing rewrites
47710
+ ...normalizeNextDataRoute(),
47711
+ ...(!isNextDataServerResolving
47712
+ ? [
47713
+ // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
47714
+ // if no match to prevent rewriting _next/data unexpectedly
47715
+ {
47716
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47717
+ dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
47718
+ check: true,
47719
+ },
47720
+ ]
47721
+ : []),
47657
47722
  // These need to come before handle: miss or else they are grouped
47658
47723
  // with that routing section
47659
47724
  ...afterFilesRewrites,
@@ -47699,18 +47764,41 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47699
47764
  // routes that are called after each rewrite or after routes
47700
47765
  // if there no rewrites
47701
47766
  { handle: 'rewrite' },
47767
+ // re-build /_next/data URL after resolving
47768
+ ...denormalizeNextDataRoute(),
47702
47769
  // /_next/data routes for getServerProps/getStaticProps pages
47703
47770
  ...dataRoutes,
47704
- // ensure we 404 for non-existent _next/data routes before
47705
- // trying page dynamic routes
47706
- {
47707
- src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47708
- dest: path_1.default.join('/', entryDirectory, '404'),
47709
- status: 404,
47710
- },
47771
+ ...(!isNextDataServerResolving
47772
+ ? [
47773
+ // ensure we 404 for non-existent _next/data routes before
47774
+ // trying page dynamic routes
47775
+ {
47776
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47777
+ dest: path_1.default.join('/', entryDirectory, '404'),
47778
+ status: 404,
47779
+ },
47780
+ ]
47781
+ : []),
47711
47782
  // Dynamic routes (must come after dataRoutes as dataRoutes are more
47712
47783
  // specific)
47713
47784
  ...dynamicRoutes,
47785
+ ...(isNextDataServerResolving
47786
+ ? [
47787
+ {
47788
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
47789
+ headers: {
47790
+ 'x-nextjs-matched-path': '/$1',
47791
+ },
47792
+ continue: true,
47793
+ },
47794
+ // add a catch-all data route so we don't 404 when getting
47795
+ // middleware effects
47796
+ {
47797
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
47798
+ dest: '__next_data_catchall',
47799
+ },
47800
+ ]
47801
+ : []),
47714
47802
  // routes to call after a file has been matched
47715
47803
  { handle: 'hit' },
47716
47804
  // Before we handle static files we need to set proper caching headers
@@ -18,7 +18,8 @@ const pretty_bytes_1 = __importDefault(require("pretty-bytes"));
18
18
  // related PR: https://github.com/vercel/next.js/pull/30046
19
19
  const CORRECT_NOT_FOUND_ROUTES_VERSION = 'v12.0.1';
20
20
  const CORRECT_MIDDLEWARE_ORDER_VERSION = 'v12.1.7-canary.29';
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
+ const NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION = 'v12.1.7-canary.33';
22
+ 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, prerenderManifest, omittedPrerenderRoutes, trailingSlashRedirects, isCorrectLocaleAPIRoutes, lambdaCompressedByteLimit, requiredServerFilesManifest, }) {
22
23
  const lambdas = {};
23
24
  const prerenders = {};
24
25
  const lambdaPageKeys = Object.keys(lambdaPages);
@@ -417,6 +418,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
417
418
  routesManifest,
418
419
  isCorrectMiddlewareOrder,
419
420
  });
421
+ const isNextDataServerResolving = middleware.staticRoutes.length > 0 &&
422
+ semver_1.default.gte(nextVersion, NEXT_DATA_MIDDLEWARE_RESOLVING_VERSION);
420
423
  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));
421
424
  const { staticFiles, publicDirectoryFiles, staticDirectoryFiles } = await (0, utils_1.getStaticFiles)(entryPath, entryDirectory, outputDirectory);
422
425
  const notFoundPreviewRoutes = [];
@@ -459,6 +462,52 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
459
462
  }
460
463
  }
461
464
  }
465
+ const normalizeNextDataRoute = (isOverride = false) => {
466
+ return isNextDataServerResolving
467
+ ? [
468
+ // strip _next/data prefix for resolving
469
+ {
470
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
471
+ dest: `${path_1.default.join('/', entryDirectory, '/$1')}`,
472
+ ...(isOverride ? { override: true } : {}),
473
+ continue: true,
474
+ has: [
475
+ {
476
+ type: 'header',
477
+ key: 'x-nextjs-data',
478
+ },
479
+ ],
480
+ },
481
+ ]
482
+ : [];
483
+ };
484
+ const denormalizeNextDataRoute = (isOverride = false) => {
485
+ return isNextDataServerResolving
486
+ ? [
487
+ {
488
+ src: '/(.*)',
489
+ has: [
490
+ {
491
+ type: 'header',
492
+ key: 'x-nextjs-data',
493
+ },
494
+ ],
495
+ dest: `${path_1.default.join('/', entryDirectory, '/_next/data/', buildId, '/$1.json')}`,
496
+ continue: true,
497
+ ...(isOverride ? { override: true } : {}),
498
+ },
499
+ ]
500
+ : [];
501
+ };
502
+ let nextDataCatchallOutput = undefined;
503
+ if (isNextDataServerResolving) {
504
+ const catchallFsPath = path_1.default.join(entryPath, outputDirectory, '__next_data_catchall.json');
505
+ await fs_extra_1.default.writeFile(catchallFsPath, '{}');
506
+ nextDataCatchallOutput = new build_utils_1.FileFsRef({
507
+ contentType: 'application/json',
508
+ fsPath: catchallFsPath,
509
+ });
510
+ }
462
511
  return {
463
512
  wildcard: wildcardConfig,
464
513
  images: imagesManifest?.images?.loader === 'default'
@@ -482,6 +531,11 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
482
531
  ...staticDirectoryFiles,
483
532
  ...privateOutputs.files,
484
533
  ...middleware.edgeFunctions,
534
+ ...(isNextDataServerResolving
535
+ ? {
536
+ __next_data_catchall: nextDataCatchallOutput,
537
+ }
538
+ : {}),
485
539
  },
486
540
  routes: [
487
541
  /*
@@ -499,6 +553,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
499
553
  // trailing slash
500
554
  ...trailingSlashRedirects,
501
555
  ...privateOutputs.routes,
556
+ // normalize _next/data URL before processing redirects
557
+ ...normalizeNextDataRoute(true),
502
558
  ...(i18n
503
559
  ? [
504
560
  // Handle auto-adding current default locale to path based on
@@ -624,6 +680,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
624
680
  continue: true,
625
681
  },
626
682
  ]),
683
+ // we need to undo _next/data normalize before checking filesystem
684
+ ...denormalizeNextDataRoute(true),
627
685
  // while middleware was in beta the order came right before
628
686
  // handle: 'filesystem' we maintain this for older versions
629
687
  // to prevent a local/deploy mismatch
@@ -642,13 +700,19 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
642
700
  },
643
701
  ]
644
702
  : []),
645
- // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
646
- // if no match to prevent rewriting _next/data unexpectedly
647
- {
648
- src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
649
- dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
650
- check: true,
651
- },
703
+ // normalize _next/data URL before processing rewrites
704
+ ...normalizeNextDataRoute(),
705
+ ...(!isNextDataServerResolving
706
+ ? [
707
+ // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
708
+ // if no match to prevent rewriting _next/data unexpectedly
709
+ {
710
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
711
+ dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
712
+ check: true,
713
+ },
714
+ ]
715
+ : []),
652
716
  // These need to come before handle: miss or else they are grouped
653
717
  // with that routing section
654
718
  ...afterFilesRewrites,
@@ -694,18 +758,41 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
694
758
  // routes that are called after each rewrite or after routes
695
759
  // if there no rewrites
696
760
  { handle: 'rewrite' },
761
+ // re-build /_next/data URL after resolving
762
+ ...denormalizeNextDataRoute(),
697
763
  // /_next/data routes for getServerProps/getStaticProps pages
698
764
  ...dataRoutes,
699
- // ensure we 404 for non-existent _next/data routes before
700
- // trying page dynamic routes
701
- {
702
- src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
703
- dest: path_1.default.join('/', entryDirectory, '404'),
704
- status: 404,
705
- },
765
+ ...(!isNextDataServerResolving
766
+ ? [
767
+ // ensure we 404 for non-existent _next/data routes before
768
+ // trying page dynamic routes
769
+ {
770
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
771
+ dest: path_1.default.join('/', entryDirectory, '404'),
772
+ status: 404,
773
+ },
774
+ ]
775
+ : []),
706
776
  // Dynamic routes (must come after dataRoutes as dataRoutes are more
707
777
  // specific)
708
778
  ...dynamicRoutes,
779
+ ...(isNextDataServerResolving
780
+ ? [
781
+ {
782
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
783
+ headers: {
784
+ 'x-nextjs-matched-path': '/$1',
785
+ },
786
+ continue: true,
787
+ },
788
+ // add a catch-all data route so we don't 404 when getting
789
+ // middleware effects
790
+ {
791
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
792
+ dest: '__next_data_catchall',
793
+ },
794
+ ]
795
+ : []),
709
796
  // routes to call after a file has been matched
710
797
  { handle: 'hit' },
711
798
  // Before we handle static files we need to set proper caching headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.0.1",
3
+ "version": "3.0.2-canary.2",
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": "4.1.0",
48
+ "@vercel/build-utils": "4.1.1-canary.1",
49
49
  "@vercel/nft": "0.19.1",
50
- "@vercel/routing-utils": "1.13.4",
50
+ "@vercel/routing-utils": "1.13.5-canary.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": "0c7b54edad6adf48505abf2cbec01691b85963bb"
73
+ "gitHead": "cf7c50d69178cd090daf00146828b310f34f4961"
74
74
  }