@vercel/next 4.16.4 → 4.16.6

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.
@@ -9645,6 +9645,7 @@ async function handleStaticOutputs(outputs, {
9645
9645
  );
9646
9646
  }
9647
9647
  var vercelConfig = JSON.parse(process.env.NEXT_ADAPTER_VERCEL_CONFIG || "{}");
9648
+ var hasWarnedAboutDotEnv = false;
9648
9649
  function isGeneratedStep(routeName) {
9649
9650
  return routeName.includes(".well-known/workflow/v1/step") || routeName.includes("api/generated/steps");
9650
9651
  }
@@ -9688,6 +9689,30 @@ async function writeDeterministicRoutesManifest(distDir) {
9688
9689
  await import_promises.default.writeFile(outputManifestPath, JSON.stringify(manifest));
9689
9690
  return outputManifestPath;
9690
9691
  }
9692
+ async function getProjectEnvFiles(projectDir) {
9693
+ const envFiles = [];
9694
+ const projectFiles = (await import_promises.default.readdir(projectDir).catch(() => [])).sort();
9695
+ for (const file of projectFiles) {
9696
+ const isEnv = file === ".env" || file.startsWith(".env.");
9697
+ if (!isEnv) {
9698
+ continue;
9699
+ }
9700
+ const statResult = await import_promises.default.lstat(import_node_path.default.join(projectDir, file)).catch(() => {
9701
+ return void 0;
9702
+ });
9703
+ if (statResult?.isFile()) {
9704
+ envFiles.push(file);
9705
+ }
9706
+ }
9707
+ return envFiles;
9708
+ }
9709
+ function resolveNextEnvLoaderPath(projectDir) {
9710
+ const { createRequire } = require("module");
9711
+ const projectRequire = createRequire(import_node_path.default.join(projectDir, "package.json"));
9712
+ const nextPackagePath = projectRequire.resolve("next/package.json");
9713
+ const requireFromNext = createRequire(nextPackagePath);
9714
+ return requireFromNext.resolve("@next/env");
9715
+ }
9691
9716
  async function handleNodeOutputs(nodeOutputs, {
9692
9717
  config,
9693
9718
  distDir,
@@ -9728,6 +9753,27 @@ async function handleNodeOutputs(nodeOutputs, {
9728
9753
  import_node_path.default.posix.relative(repoRoot, distDir),
9729
9754
  "routes-manifest.json"
9730
9755
  );
9756
+ const envFiles = await getProjectEnvFiles(projectDir);
9757
+ const hasProjectEnvFiles = envFiles.length > 0;
9758
+ const envFilePathMap = {};
9759
+ let nextEnvLoaderPathRelativeToProjectDir;
9760
+ for (const envFile of envFiles) {
9761
+ envFilePathMap[import_node_path.default.posix.join(import_node_path.default.posix.relative(repoRoot, projectDir), envFile)] = import_node_path.default.posix.relative(repoRoot, import_node_path.default.join(projectDir, envFile));
9762
+ }
9763
+ if (hasProjectEnvFiles) {
9764
+ if (!hasWarnedAboutDotEnv) {
9765
+ console.warn(
9766
+ "Detected .env file, it is strongly recommended to use Vercel's env handling instead"
9767
+ );
9768
+ hasWarnedAboutDotEnv = true;
9769
+ }
9770
+ const nextEnvLoaderPath = resolveNextEnvLoaderPath(projectDir);
9771
+ envFilePathMap[import_node_path.default.posix.relative(repoRoot, nextEnvLoaderPath)] = import_node_path.default.posix.relative(repoRoot, nextEnvLoaderPath);
9772
+ nextEnvLoaderPathRelativeToProjectDir = import_node_path.default.posix.relative(
9773
+ projectDir,
9774
+ nextEnvLoaderPath
9775
+ );
9776
+ }
9731
9777
  await Promise.all(
9732
9778
  nodeOutputs.map(async (output) => {
9733
9779
  await fsSema.acquire();
@@ -9741,6 +9787,9 @@ async function handleNodeOutputs(nodeOutputs, {
9741
9787
  files[relPath] = import_node_path.default.posix.relative(repoRoot, fsPath);
9742
9788
  }
9743
9789
  files[import_node_path.default.posix.relative(repoRoot, output.filePath)] = import_node_path.default.posix.relative(repoRoot, output.filePath);
9790
+ if (hasProjectEnvFiles) {
9791
+ Object.assign(files, envFilePathMap);
9792
+ }
9744
9793
  if (output.type === import_constants.AdapterOutputType.PAGES) {
9745
9794
  const notFoundOutput = pages404Output || pagesErrorOutput;
9746
9795
  if (notFoundOutput) {
@@ -9767,7 +9816,8 @@ async function handleNodeOutputs(nodeOutputs, {
9767
9816
  projectRelativeDistDir: import_node_path.default.posix.relative(projectDir, distDir),
9768
9817
  prerenderFallbackFalseMap,
9769
9818
  isMiddleware,
9770
- nextConfig: config
9819
+ nextConfig: config,
9820
+ nextEnvLoaderPathRelativeToProjectDir
9771
9821
  })
9772
9822
  );
9773
9823
  const operationType = output.type === import_constants.AdapterOutputType.APP_PAGE || import_constants.AdapterOutputType.PAGES ? "PAGE" : "API";
@@ -10312,6 +10362,26 @@ function normalizeNextDataRoutes(config, buildId, shouldHandleMiddlewareDataReso
10312
10362
  const basePath = config.basePath || "";
10313
10363
  const trailingSlash = config.trailingSlash || false;
10314
10364
  return [
10365
+ // remove x-nextjs-data header for non _next/data requests
10366
+ {
10367
+ src: path3.posix.join("/", basePath, "/(?!_next/data(?:/|$))(.*)"),
10368
+ has: [
10369
+ {
10370
+ type: "header",
10371
+ key: "x-nextjs-data"
10372
+ }
10373
+ ],
10374
+ transforms: [
10375
+ {
10376
+ type: "request.headers",
10377
+ op: "delete",
10378
+ target: {
10379
+ key: "x-nextjs-data"
10380
+ }
10381
+ }
10382
+ ],
10383
+ continue: true
10384
+ },
10315
10385
  // ensure x-nextjs-data header is always present if we are doing middleware next data resolving
10316
10386
  {
10317
10387
  src: path3.posix.join("/", basePath, "/_next/data/(.*)"),
@@ -24,8 +24,15 @@ module.exports = __toCommonJS(node_handler_exports);
24
24
  const getHandlerSource = (ctx) => `
25
25
  process.env.NODE_ENV = 'production';
26
26
  process.chdir(__dirname);
27
-
28
- require('next/setup-node-env')
27
+
28
+ require('next/setup-node-env');
29
+
30
+ if (process.env.__PRIVATE_NEXT_ENV_LOADER_PATH) {
31
+ const { loadEnvConfig } = require(
32
+ './' + process.env.__PRIVATE_NEXT_ENV_LOADER_PATH
33
+ );
34
+ loadEnvConfig('.', process.env.NODE_ENV === 'development');
35
+ }
29
36
 
30
37
  const _n_handler = (${ctx.isMiddleware ? () => {
31
38
  const path = require("path");
@@ -289,6 +296,9 @@ const getHandlerSource = (ctx) => `
289
296
  ).replaceAll(
290
297
  "process.env.__PRIVATE_NEXT_CONFIG",
291
298
  JSON.stringify(ctx.nextConfig)
299
+ ).replaceAll(
300
+ "process.env.__PRIVATE_NEXT_ENV_LOADER_PATH",
301
+ JSON.stringify(ctx.nextEnvLoaderPathRelativeToProjectDir || "")
292
302
  );
293
303
  // Annotate the CommonJS export names for ESM import in node:
294
304
  0 && (module.exports = {
package/dist/index.js CHANGED
@@ -15722,6 +15722,30 @@ ${JSON.stringify(
15722
15722
  ...trailingSlashRedirects,
15723
15723
  ...privateOutputs.routes,
15724
15724
  ...isNextDataServerResolving ? [
15725
+ // remove x-nextjs-data header for non _next/data requests
15726
+ {
15727
+ src: import_path5.default.posix.join(
15728
+ "/",
15729
+ entryDirectory,
15730
+ "/(?!_next/data(?:/|$))(.*)"
15731
+ ),
15732
+ has: [
15733
+ {
15734
+ type: "header",
15735
+ key: "x-nextjs-data"
15736
+ }
15737
+ ],
15738
+ transforms: [
15739
+ {
15740
+ type: "request.headers",
15741
+ op: "delete",
15742
+ target: {
15743
+ key: "x-nextjs-data"
15744
+ }
15745
+ }
15746
+ ],
15747
+ continue: true
15748
+ },
15725
15749
  // ensure x-nextjs-data header is always present
15726
15750
  // if we are doing middleware next data resolving
15727
15751
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/next",
3
- "version": "4.16.4",
3
+ "version": "4.16.6",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
@@ -16,7 +16,7 @@
16
16
  "@vercel/nft": "1.5.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@next-community/adapter-vercel": "0.0.1-beta.15",
19
+ "@next-community/adapter-vercel": "0.0.1-beta.17",
20
20
  "@types/aws-lambda": "8.10.19",
21
21
  "@types/buffer-crc32": "0.2.0",
22
22
  "@types/bytes": "3.1.1",
@@ -53,7 +53,7 @@
53
53
  "test-listen": "1.1.0",
54
54
  "text-table": "0.2.0",
55
55
  "webpack-sources": "3.2.3",
56
- "@vercel/build-utils": "13.12.1",
56
+ "@vercel/build-utils": "13.14.2",
57
57
  "@vercel/routing-utils": "6.1.1"
58
58
  },
59
59
  "scripts": {