@vercel/next 3.0.1 → 3.0.2-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,39 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47464
47468
  }
47465
47469
  }
47466
47470
  }
47471
+ const normalizeNextDataRoute = isNextDataServerResolving
47472
+ ? [
47473
+ // strip _next/data prefix for resolving
47474
+ {
47475
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
47476
+ dest: `${path_1.default.join('/', entryDirectory, '/$1')}`,
47477
+ continue: true,
47478
+ override: true,
47479
+ has: [
47480
+ {
47481
+ type: 'header',
47482
+ key: 'x-nextjs-data',
47483
+ },
47484
+ ],
47485
+ },
47486
+ ]
47487
+ : [];
47488
+ const denormalizeNextDataRoute = isNextDataServerResolving
47489
+ ? [
47490
+ {
47491
+ src: '/(.*)',
47492
+ has: [
47493
+ {
47494
+ type: 'header',
47495
+ key: 'x-nextjs-data',
47496
+ },
47497
+ ],
47498
+ dest: `${path_1.default.join('/', entryDirectory, '/_next/data/', buildId, '/$1.json')}`,
47499
+ continue: true,
47500
+ override: true,
47501
+ },
47502
+ ]
47503
+ : [];
47467
47504
  return {
47468
47505
  wildcard: wildcardConfig,
47469
47506
  images: imagesManifest?.images?.loader === 'default'
@@ -47487,6 +47524,15 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47487
47524
  ...staticDirectoryFiles,
47488
47525
  ...privateOutputs.files,
47489
47526
  ...middleware.edgeFunctions,
47527
+ ...(isNextDataServerResolving
47528
+ ? {
47529
+ __next_data_catchall: new build_utils_1.FileBlob({
47530
+ contentType: 'application/json',
47531
+ mode: 0o644,
47532
+ data: '{}',
47533
+ }),
47534
+ }
47535
+ : {}),
47490
47536
  },
47491
47537
  routes: [
47492
47538
  /*
@@ -47504,6 +47550,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47504
47550
  // trailing slash
47505
47551
  ...trailingSlashRedirects,
47506
47552
  ...privateOutputs.routes,
47553
+ // normalize _next/data URL before processing redirects
47554
+ ...normalizeNextDataRoute,
47507
47555
  ...(i18n
47508
47556
  ? [
47509
47557
  // Handle auto-adding current default locale to path based on
@@ -47629,6 +47677,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47629
47677
  continue: true,
47630
47678
  },
47631
47679
  ]),
47680
+ // we need to undo _next/data normalize before checking filesystem
47681
+ ...denormalizeNextDataRoute,
47632
47682
  // while middleware was in beta the order came right before
47633
47683
  // handle: 'filesystem' we maintain this for older versions
47634
47684
  // to prevent a local/deploy mismatch
@@ -47647,13 +47697,19 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47647
47697
  },
47648
47698
  ]
47649
47699
  : []),
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
- },
47700
+ // normalize _next/data URL before processing rewrites
47701
+ ...normalizeNextDataRoute,
47702
+ ...(!isNextDataServerResolving
47703
+ ? [
47704
+ // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
47705
+ // if no match to prevent rewriting _next/data unexpectedly
47706
+ {
47707
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47708
+ dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
47709
+ check: true,
47710
+ },
47711
+ ]
47712
+ : []),
47657
47713
  // These need to come before handle: miss or else they are grouped
47658
47714
  // with that routing section
47659
47715
  ...afterFilesRewrites,
@@ -47699,18 +47755,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
47699
47755
  // routes that are called after each rewrite or after routes
47700
47756
  // if there no rewrites
47701
47757
  { handle: 'rewrite' },
47758
+ // re-build /_next/data URL after resolving
47759
+ ...denormalizeNextDataRoute,
47702
47760
  // /_next/data routes for getServerProps/getStaticProps pages
47703
47761
  ...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
- },
47762
+ ...(!isNextDataServerResolving
47763
+ ? [
47764
+ // ensure we 404 for non-existent _next/data routes before
47765
+ // trying page dynamic routes
47766
+ {
47767
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
47768
+ dest: path_1.default.join('/', entryDirectory, '404'),
47769
+ status: 404,
47770
+ },
47771
+ ]
47772
+ : []),
47711
47773
  // Dynamic routes (must come after dataRoutes as dataRoutes are more
47712
47774
  // specific)
47713
47775
  ...dynamicRoutes,
47776
+ ...(isNextDataServerResolving
47777
+ ? [
47778
+ // add a catch-all data route so we don't 404 when getting
47779
+ // middleware effects
47780
+ {
47781
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
47782
+ dest: '__next_data_catchall',
47783
+ },
47784
+ ]
47785
+ : []),
47714
47786
  // routes to call after a file has been matched
47715
47787
  { handle: 'hit' },
47716
47788
  // 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,39 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
459
462
  }
460
463
  }
461
464
  }
465
+ const normalizeNextDataRoute = isNextDataServerResolving
466
+ ? [
467
+ // strip _next/data prefix for resolving
468
+ {
469
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
470
+ dest: `${path_1.default.join('/', entryDirectory, '/$1')}`,
471
+ continue: true,
472
+ override: true,
473
+ has: [
474
+ {
475
+ type: 'header',
476
+ key: 'x-nextjs-data',
477
+ },
478
+ ],
479
+ },
480
+ ]
481
+ : [];
482
+ const denormalizeNextDataRoute = isNextDataServerResolving
483
+ ? [
484
+ {
485
+ src: '/(.*)',
486
+ has: [
487
+ {
488
+ type: 'header',
489
+ key: 'x-nextjs-data',
490
+ },
491
+ ],
492
+ dest: `${path_1.default.join('/', entryDirectory, '/_next/data/', buildId, '/$1.json')}`,
493
+ continue: true,
494
+ override: true,
495
+ },
496
+ ]
497
+ : [];
462
498
  return {
463
499
  wildcard: wildcardConfig,
464
500
  images: imagesManifest?.images?.loader === 'default'
@@ -482,6 +518,15 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
482
518
  ...staticDirectoryFiles,
483
519
  ...privateOutputs.files,
484
520
  ...middleware.edgeFunctions,
521
+ ...(isNextDataServerResolving
522
+ ? {
523
+ __next_data_catchall: new build_utils_1.FileBlob({
524
+ contentType: 'application/json',
525
+ mode: 0o644,
526
+ data: '{}',
527
+ }),
528
+ }
529
+ : {}),
485
530
  },
486
531
  routes: [
487
532
  /*
@@ -499,6 +544,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
499
544
  // trailing slash
500
545
  ...trailingSlashRedirects,
501
546
  ...privateOutputs.routes,
547
+ // normalize _next/data URL before processing redirects
548
+ ...normalizeNextDataRoute,
502
549
  ...(i18n
503
550
  ? [
504
551
  // Handle auto-adding current default locale to path based on
@@ -624,6 +671,8 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
624
671
  continue: true,
625
672
  },
626
673
  ]),
674
+ // we need to undo _next/data normalize before checking filesystem
675
+ ...denormalizeNextDataRoute,
627
676
  // while middleware was in beta the order came right before
628
677
  // handle: 'filesystem' we maintain this for older versions
629
678
  // to prevent a local/deploy mismatch
@@ -642,13 +691,19 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
642
691
  },
643
692
  ]
644
693
  : []),
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
- },
694
+ // normalize _next/data URL before processing rewrites
695
+ ...normalizeNextDataRoute,
696
+ ...(!isNextDataServerResolving
697
+ ? [
698
+ // No-op _next/data rewrite to trigger handle: 'rewrites' and then 404
699
+ // if no match to prevent rewriting _next/data unexpectedly
700
+ {
701
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
702
+ dest: path_1.default.join('/', entryDirectory, '_next/data/$1'),
703
+ check: true,
704
+ },
705
+ ]
706
+ : []),
652
707
  // These need to come before handle: miss or else they are grouped
653
708
  // with that routing section
654
709
  ...afterFilesRewrites,
@@ -694,18 +749,34 @@ async function serverBuild({ dynamicPages, pagesDir, config = {}, privateOutputs
694
749
  // routes that are called after each rewrite or after routes
695
750
  // if there no rewrites
696
751
  { handle: 'rewrite' },
752
+ // re-build /_next/data URL after resolving
753
+ ...denormalizeNextDataRoute,
697
754
  // /_next/data routes for getServerProps/getStaticProps pages
698
755
  ...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
- },
756
+ ...(!isNextDataServerResolving
757
+ ? [
758
+ // ensure we 404 for non-existent _next/data routes before
759
+ // trying page dynamic routes
760
+ {
761
+ src: path_1.default.join('/', entryDirectory, '_next/data/(.*)'),
762
+ dest: path_1.default.join('/', entryDirectory, '404'),
763
+ status: 404,
764
+ },
765
+ ]
766
+ : []),
706
767
  // Dynamic routes (must come after dataRoutes as dataRoutes are more
707
768
  // specific)
708
769
  ...dynamicRoutes,
770
+ ...(isNextDataServerResolving
771
+ ? [
772
+ // add a catch-all data route so we don't 404 when getting
773
+ // middleware effects
774
+ {
775
+ src: `^${path_1.default.join('/', entryDirectory, '/_next/data/', escapedBuildId, '/(.*).json')}`,
776
+ dest: '__next_data_catchall',
777
+ },
778
+ ]
779
+ : []),
709
780
  // routes to call after a file has been matched
710
781
  { handle: 'hit' },
711
782
  // 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.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -45,7 +45,7 @@
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.0",
49
49
  "@vercel/nft": "0.19.1",
50
50
  "@vercel/routing-utils": "1.13.4",
51
51
  "async-sema": "3.0.1",
@@ -70,5 +70,5 @@
70
70
  "typescript": "4.5.2",
71
71
  "webpack-sources": "3.2.3"
72
72
  },
73
- "gitHead": "0c7b54edad6adf48505abf2cbec01691b85963bb"
73
+ "gitHead": "4bf6295d7a1d6544f195d76a2a4aedb476fa7dc1"
74
74
  }