@vercel/next 3.7.6 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -45118,27 +45118,33 @@ async function getSourceFilePathFromPage({ workPath, page, pageExtensions, }) {
45118
45118
  // TODO: this should be updated to get the pageExtensions
45119
45119
  // value used during next build
45120
45120
  const extensionsToTry = pageExtensions || ['js', 'jsx', 'ts', 'tsx'];
45121
- let fsPath = path_1.default.join(workPath, 'pages', page);
45122
- if (await usesSrcDirectory(workPath)) {
45123
- fsPath = path_1.default.join(workPath, 'src', 'pages', page);
45124
- }
45125
- if (fs_extra_1.default.existsSync(fsPath)) {
45126
- return path_1.default.relative(workPath, fsPath);
45127
- }
45128
- const extensionless = fsPath.slice(0, -3); // remove ".js"
45129
- for (const ext of extensionsToTry) {
45130
- fsPath = `${extensionless}.${ext}`;
45121
+ for (const pageType of ['pages', 'app']) {
45122
+ let fsPath = path_1.default.join(workPath, pageType, page);
45123
+ if (await usesSrcDirectory(workPath)) {
45124
+ fsPath = path_1.default.join(workPath, 'src', pageType, page);
45125
+ }
45131
45126
  if (fs_extra_1.default.existsSync(fsPath)) {
45132
45127
  return path_1.default.relative(workPath, fsPath);
45133
45128
  }
45134
- }
45135
- if (isDirectory(extensionless)) {
45129
+ const extensionless = fsPath.replace(path_1.default.extname(fsPath), '');
45136
45130
  for (const ext of extensionsToTry) {
45137
- fsPath = path_1.default.join(extensionless, `index.${ext}`);
45131
+ fsPath = `${extensionless}.${ext}`;
45138
45132
  if (fs_extra_1.default.existsSync(fsPath)) {
45139
45133
  return path_1.default.relative(workPath, fsPath);
45140
45134
  }
45141
45135
  }
45136
+ if (isDirectory(extensionless)) {
45137
+ for (const ext of extensionsToTry) {
45138
+ fsPath = path_1.default.join(extensionless, `index.${ext}`);
45139
+ if (fs_extra_1.default.existsSync(fsPath)) {
45140
+ return path_1.default.relative(workPath, fsPath);
45141
+ }
45142
+ fsPath = path_1.default.join(extensionless, `route.${ext}`);
45143
+ if (fs_extra_1.default.existsSync(fsPath)) {
45144
+ return path_1.default.relative(workPath, fsPath);
45145
+ }
45146
+ }
45147
+ }
45142
45148
  }
45143
45149
  console.log(`WARNING: Unable to find source file for page ${page} with extensions: ${extensionsToTry.join(', ')}, this can cause functions config from \`vercel.json\` to not be applied`);
45144
45150
  return '';
@@ -45846,6 +45852,51 @@ async function getPrivateOutputs(dir, entries) {
45846
45852
  return { files, routes };
45847
45853
  }
45848
45854
  exports.getPrivateOutputs = getPrivateOutputs;
45855
+ const vercelFunctionRegionsVar = process.env.VERCEL_FUNCTION_REGIONS;
45856
+ let vercelFunctionRegions;
45857
+ if (vercelFunctionRegionsVar) {
45858
+ vercelFunctionRegions = vercelFunctionRegionsVar.split(',');
45859
+ }
45860
+ /**
45861
+ * Normalizes the regions config that comes from the Next.js edge functions manifest.
45862
+ * Ensures that config like `home` and `global` are converted to the corresponding Vercel region config.
45863
+ * In the future we'll want to make `home` and `global` part of the Build Output API.
45864
+ * - `home` refers to the regions set in vercel.json or on the Vercel dashboard project config.
45865
+ * - `global` refers to all regions.
45866
+ */
45867
+ function normalizeRegions(regions) {
45868
+ if (typeof regions === 'string') {
45869
+ regions = [regions];
45870
+ }
45871
+ const newRegions = [];
45872
+ for (const region of regions) {
45873
+ // Explicitly mentioned as `home` is one of the explicit values for preferredRegion in Next.js.
45874
+ if (region === 'home') {
45875
+ if (vercelFunctionRegions) {
45876
+ // Includes the regions from the VERCEL_FUNCTION_REGIONS env var.
45877
+ newRegions.push(...vercelFunctionRegions);
45878
+ }
45879
+ continue;
45880
+ }
45881
+ // Explicitly mentioned as `global` is one of the explicit values for preferredRegion in Next.js.
45882
+ if (region === 'global') {
45883
+ // Uses `all` instead as that's how it's implemented on Vercel.
45884
+ newRegions.push('all');
45885
+ continue;
45886
+ }
45887
+ // Explicitly mentioned as `auto` is one of the explicit values for preferredRegion in Next.js.
45888
+ if (region === 'auto') {
45889
+ newRegions.push('auto');
45890
+ continue;
45891
+ }
45892
+ newRegions.push(region);
45893
+ }
45894
+ // Ensure we don't pass an empty array as that is not supported.
45895
+ if (newRegions.length === 0) {
45896
+ return undefined;
45897
+ }
45898
+ return newRegions;
45899
+ }
45849
45900
  async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, prerenderBypassToken, nextVersion, appPathRoutesManifest, }) {
45850
45901
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
45851
45902
  const sortedFunctions = [
@@ -45919,7 +45970,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
45919
45970
  ...wasmFiles,
45920
45971
  ...assetFiles,
45921
45972
  },
45922
- regions: edgeFunction.regions,
45973
+ regions: edgeFunction.regions
45974
+ ? normalizeRegions(edgeFunction.regions)
45975
+ : undefined,
45923
45976
  entrypoint: 'index.js',
45924
45977
  envVarsInUse: edgeFunction.env,
45925
45978
  assets: (edgeFunction.assets ?? []).map(({ name }) => {
package/dist/utils.js CHANGED
@@ -761,27 +761,33 @@ async function getSourceFilePathFromPage({ workPath, page, pageExtensions, }) {
761
761
  // TODO: this should be updated to get the pageExtensions
762
762
  // value used during next build
763
763
  const extensionsToTry = pageExtensions || ['js', 'jsx', 'ts', 'tsx'];
764
- let fsPath = path_1.default.join(workPath, 'pages', page);
765
- if (await usesSrcDirectory(workPath)) {
766
- fsPath = path_1.default.join(workPath, 'src', 'pages', page);
767
- }
768
- if (fs_extra_1.default.existsSync(fsPath)) {
769
- return path_1.default.relative(workPath, fsPath);
770
- }
771
- const extensionless = fsPath.slice(0, -3); // remove ".js"
772
- for (const ext of extensionsToTry) {
773
- fsPath = `${extensionless}.${ext}`;
764
+ for (const pageType of ['pages', 'app']) {
765
+ let fsPath = path_1.default.join(workPath, pageType, page);
766
+ if (await usesSrcDirectory(workPath)) {
767
+ fsPath = path_1.default.join(workPath, 'src', pageType, page);
768
+ }
774
769
  if (fs_extra_1.default.existsSync(fsPath)) {
775
770
  return path_1.default.relative(workPath, fsPath);
776
771
  }
777
- }
778
- if (isDirectory(extensionless)) {
772
+ const extensionless = fsPath.replace(path_1.default.extname(fsPath), '');
779
773
  for (const ext of extensionsToTry) {
780
- fsPath = path_1.default.join(extensionless, `index.${ext}`);
774
+ fsPath = `${extensionless}.${ext}`;
781
775
  if (fs_extra_1.default.existsSync(fsPath)) {
782
776
  return path_1.default.relative(workPath, fsPath);
783
777
  }
784
778
  }
779
+ if (isDirectory(extensionless)) {
780
+ for (const ext of extensionsToTry) {
781
+ fsPath = path_1.default.join(extensionless, `index.${ext}`);
782
+ if (fs_extra_1.default.existsSync(fsPath)) {
783
+ return path_1.default.relative(workPath, fsPath);
784
+ }
785
+ fsPath = path_1.default.join(extensionless, `route.${ext}`);
786
+ if (fs_extra_1.default.existsSync(fsPath)) {
787
+ return path_1.default.relative(workPath, fsPath);
788
+ }
789
+ }
790
+ }
785
791
  }
786
792
  console.log(`WARNING: Unable to find source file for page ${page} with extensions: ${extensionsToTry.join(', ')}, this can cause functions config from \`vercel.json\` to not be applied`);
787
793
  return '';
@@ -1489,6 +1495,51 @@ async function getPrivateOutputs(dir, entries) {
1489
1495
  return { files, routes };
1490
1496
  }
1491
1497
  exports.getPrivateOutputs = getPrivateOutputs;
1498
+ const vercelFunctionRegionsVar = process.env.VERCEL_FUNCTION_REGIONS;
1499
+ let vercelFunctionRegions;
1500
+ if (vercelFunctionRegionsVar) {
1501
+ vercelFunctionRegions = vercelFunctionRegionsVar.split(',');
1502
+ }
1503
+ /**
1504
+ * Normalizes the regions config that comes from the Next.js edge functions manifest.
1505
+ * Ensures that config like `home` and `global` are converted to the corresponding Vercel region config.
1506
+ * In the future we'll want to make `home` and `global` part of the Build Output API.
1507
+ * - `home` refers to the regions set in vercel.json or on the Vercel dashboard project config.
1508
+ * - `global` refers to all regions.
1509
+ */
1510
+ function normalizeRegions(regions) {
1511
+ if (typeof regions === 'string') {
1512
+ regions = [regions];
1513
+ }
1514
+ const newRegions = [];
1515
+ for (const region of regions) {
1516
+ // Explicitly mentioned as `home` is one of the explicit values for preferredRegion in Next.js.
1517
+ if (region === 'home') {
1518
+ if (vercelFunctionRegions) {
1519
+ // Includes the regions from the VERCEL_FUNCTION_REGIONS env var.
1520
+ newRegions.push(...vercelFunctionRegions);
1521
+ }
1522
+ continue;
1523
+ }
1524
+ // Explicitly mentioned as `global` is one of the explicit values for preferredRegion in Next.js.
1525
+ if (region === 'global') {
1526
+ // Uses `all` instead as that's how it's implemented on Vercel.
1527
+ newRegions.push('all');
1528
+ continue;
1529
+ }
1530
+ // Explicitly mentioned as `auto` is one of the explicit values for preferredRegion in Next.js.
1531
+ if (region === 'auto') {
1532
+ newRegions.push('auto');
1533
+ continue;
1534
+ }
1535
+ newRegions.push(region);
1536
+ }
1537
+ // Ensure we don't pass an empty array as that is not supported.
1538
+ if (newRegions.length === 0) {
1539
+ return undefined;
1540
+ }
1541
+ return newRegions;
1542
+ }
1492
1543
  async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest, isCorrectMiddlewareOrder, prerenderBypassToken, nextVersion, appPathRoutesManifest, }) {
1493
1544
  const middlewareManifest = await getMiddlewareManifest(entryPath, outputDirectory);
1494
1545
  const sortedFunctions = [
@@ -1562,7 +1613,9 @@ async function getMiddlewareBundle({ entryPath, outputDirectory, routesManifest,
1562
1613
  ...wasmFiles,
1563
1614
  ...assetFiles,
1564
1615
  },
1565
- regions: edgeFunction.regions,
1616
+ regions: edgeFunction.regions
1617
+ ? normalizeRegions(edgeFunction.regions)
1618
+ : undefined,
1566
1619
  entrypoint: 'index.js',
1567
1620
  envVarsInUse: edgeFunction.env,
1568
1621
  assets: (edgeFunction.assets ?? []).map(({ name }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "3.7.6",
3
+ "version": "3.8.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -60,5 +60,5 @@
60
60
  "text-table": "0.2.0",
61
61
  "webpack-sources": "3.2.3"
62
62
  },
63
- "gitHead": "2de365f9cfea3ce283d2bf855507c71209f1e3d8"
63
+ "gitHead": "85947b658ee1b4b3b7fcb631bdc6e591ee1e338a"
64
64
  }