@netlify/plugin-nextjs 5.1.0 → 5.1.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.
@@ -10,11 +10,11 @@ import {
10
10
  getPatchesToApply,
11
11
  verifyHandlerDirStructure,
12
12
  writeTagsManifest
13
- } from "../../esm-chunks/chunk-ZKJEJNSJ.js";
13
+ } from "../../esm-chunks/chunk-4BNHE6TP.js";
14
14
  import "../../esm-chunks/chunk-PDPDW32D.js";
15
15
  import "../../esm-chunks/chunk-Y3K5Q6FP.js";
16
16
  import "../../esm-chunks/chunk-VZNKO4OO.js";
17
- import "../../esm-chunks/chunk-PH26UF2W.js";
17
+ import "../../esm-chunks/chunk-K7BTUM7O.js";
18
18
  import "../../esm-chunks/chunk-PJG75HGC.js";
19
19
  import "../../esm-chunks/chunk-BG455SFE.js";
20
20
  import "../../esm-chunks/chunk-UYKENJEU.js";
@@ -10,7 +10,7 @@ import {
10
10
  copyStaticExport,
11
11
  publishStaticDir,
12
12
  unpublishStaticDir
13
- } from "../../esm-chunks/chunk-74THQNRG.js";
13
+ } from "../../esm-chunks/chunk-V2T6NUOM.js";
14
14
  import "../../esm-chunks/chunk-TYCYFZ22.js";
15
15
  import "../../esm-chunks/chunk-PDPDW32D.js";
16
16
  import "../../esm-chunks/chunk-Y3K5Q6FP.js";
@@ -6,9 +6,9 @@
6
6
 
7
7
  import {
8
8
  createEdgeHandlers
9
- } from "../../esm-chunks/chunk-OBKVBMAL.js";
9
+ } from "../../esm-chunks/chunk-UTQSBE5O.js";
10
10
  import "../../esm-chunks/chunk-VZNKO4OO.js";
11
- import "../../esm-chunks/chunk-3NYX5FXN.js";
11
+ import "../../esm-chunks/chunk-L6OM53B6.js";
12
12
  import "../../esm-chunks/chunk-5JVNISGM.js";
13
13
  export {
14
14
  createEdgeHandlers
@@ -6,13 +6,13 @@
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "../../esm-chunks/chunk-F5VQRN6L.js";
10
- import "../../esm-chunks/chunk-ZKJEJNSJ.js";
9
+ } from "../../esm-chunks/chunk-HESS57SH.js";
10
+ import "../../esm-chunks/chunk-4BNHE6TP.js";
11
11
  import "../../esm-chunks/chunk-PDPDW32D.js";
12
12
  import "../../esm-chunks/chunk-Y3K5Q6FP.js";
13
13
  import "../../esm-chunks/chunk-VZNKO4OO.js";
14
- import "../../esm-chunks/chunk-3NYX5FXN.js";
15
- import "../../esm-chunks/chunk-PH26UF2W.js";
14
+ import "../../esm-chunks/chunk-L6OM53B6.js";
15
+ import "../../esm-chunks/chunk-K7BTUM7O.js";
16
16
  import "../../esm-chunks/chunk-PJG75HGC.js";
17
17
  import "../../esm-chunks/chunk-BG455SFE.js";
18
18
  import "../../esm-chunks/chunk-UYKENJEU.js";
@@ -8,7 +8,7 @@ import {
8
8
  EDGE_HANDLER_NAME,
9
9
  PluginContext,
10
10
  SERVER_HANDLER_NAME
11
- } from "../esm-chunks/chunk-3NYX5FXN.js";
11
+ } from "../esm-chunks/chunk-L6OM53B6.js";
12
12
  import "../esm-chunks/chunk-5JVNISGM.js";
13
13
  export {
14
14
  EDGE_HANDLER_NAME,
@@ -9,7 +9,7 @@ import {
9
9
  verifyNextVersion,
10
10
  verifyNoAdvancedAPIRoutes,
11
11
  verifyPublishDir
12
- } from "../esm-chunks/chunk-PH26UF2W.js";
12
+ } from "../esm-chunks/chunk-K7BTUM7O.js";
13
13
  import "../esm-chunks/chunk-PJG75HGC.js";
14
14
  import "../esm-chunks/chunk-BG455SFE.js";
15
15
  import "../esm-chunks/chunk-5JVNISGM.js";
@@ -16,7 +16,7 @@ import {
16
16
  } from "./chunk-VZNKO4OO.js";
17
17
  import {
18
18
  verifyNextVersion
19
- } from "./chunk-PH26UF2W.js";
19
+ } from "./chunk-K7BTUM7O.js";
20
20
  import {
21
21
  require_semver
22
22
  } from "./chunk-PJG75HGC.js";
@@ -9,7 +9,7 @@ import {
9
9
  copyNextServerCode,
10
10
  verifyHandlerDirStructure,
11
11
  writeTagsManifest
12
- } from "./chunk-ZKJEJNSJ.js";
12
+ } from "./chunk-4BNHE6TP.js";
13
13
  import {
14
14
  wrapTracer
15
15
  } from "./chunk-PDPDW32D.js";
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-VZNKO4OO.js";
23
23
  import {
24
24
  SERVER_HANDLER_NAME
25
- } from "./chunk-3NYX5FXN.js";
25
+ } from "./chunk-L6OM53B6.js";
26
26
  import {
27
27
  __toESM
28
28
  } from "./chunk-5JVNISGM.js";
@@ -17,36 +17,47 @@ import {
17
17
  // src/build/verification.ts
18
18
  var import_semver = __toESM(require_semver(), 1);
19
19
  import { existsSync } from "node:fs";
20
+ import { join } from "node:path";
20
21
  var SUPPORTED_NEXT_VERSIONS = ">=13.5.0";
21
22
  function verifyPublishDir(ctx) {
22
23
  if (!existsSync(ctx.publishDir)) {
23
24
  ctx.failBuild(
24
- `Your publish directory was not found at: ${ctx.publishDir}, please check your build settings`
25
+ `Your publish directory was not found at: ${ctx.publishDir}. Please check your build settings`
25
26
  );
26
27
  }
27
28
  if (ctx.publishDir === ctx.resolveFromPackagePath("")) {
28
29
  ctx.failBuild(
29
- `Your publish directory cannot be the same as the base directory of your site, please check your build settings`
30
+ `Your publish directory cannot be the same as the base directory of your site. Please check your build settings`
30
31
  );
31
32
  }
32
33
  try {
33
34
  ctx.buildConfig;
34
35
  } catch {
35
36
  ctx.failBuild(
36
- "Your publish directory does not contain expected Next.js build output, please check your build settings"
37
+ "Your publish directory does not contain expected Next.js build output. Please check your build settings"
37
38
  );
38
39
  }
39
- if ((ctx.buildConfig.output === "standalone" || ctx.buildConfig.output === void 0) && !existsSync(ctx.standaloneRootDir)) {
40
- ctx.failBuild(
41
- `Your publish directory does not contain expected Next.js build output, please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`
42
- );
40
+ if (ctx.buildConfig.output === "standalone" || ctx.buildConfig.output === void 0) {
41
+ if (!existsSync(join(ctx.publishDir, "BUILD_ID"))) {
42
+ ctx.failBuild(
43
+ "Your publish directory does not contain expected Next.js build output. Please check your build settings"
44
+ );
45
+ }
46
+ if (!existsSync(ctx.standaloneRootDir)) {
47
+ ctx.failBuild(
48
+ `Your publish directory does not contain expected Next.js build output. Please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`
49
+ );
50
+ }
43
51
  }
44
- if (ctx.buildConfig.output === "export" && !existsSync(ctx.resolveFromSiteDir("out"))) {
45
- ctx.failBuild(
46
- `Your export directory was not found at: ${ctx.resolveFromSiteDir(
47
- "out"
48
- )}, please check your build settings`
49
- );
52
+ if (ctx.buildConfig.output === "export") {
53
+ if (!ctx.exportDetail?.success) {
54
+ ctx.failBuild(`Your export failed to build. Please check your build settings`);
55
+ }
56
+ if (!existsSync(ctx.exportDetail?.outDirectory)) {
57
+ ctx.failBuild(
58
+ `Your export directory was not found at: ${ctx.exportDetail?.outDirectory}. Please check your build settings`
59
+ );
60
+ }
50
61
  }
51
62
  }
52
63
  function verifyNextVersion(ctx, nextVersion) {
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
  // src/build/plugin-context.ts
9
- import { readFileSync } from "node:fs";
9
+ import { existsSync, readFileSync } from "node:fs";
10
10
  import { readFile } from "node:fs/promises";
11
11
  import { join, relative, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
@@ -146,6 +146,27 @@ var PluginContext = class {
146
146
  async getPrerenderManifest() {
147
147
  return JSON.parse(await readFile(join(this.publishDir, "prerender-manifest.json"), "utf-8"));
148
148
  }
149
+ /**
150
+ * Uses various heuristics to try to find the .next dir.
151
+ * Works by looking for BUILD_ID, so requires the site to have been built
152
+ */
153
+ findDotNext() {
154
+ for (const dir of [
155
+ // The publish directory
156
+ this.publishDir,
157
+ // In the root
158
+ resolve(DEFAULT_PUBLISH_DIR),
159
+ // The sibling of the publish directory
160
+ resolve(this.publishDir, "..", DEFAULT_PUBLISH_DIR),
161
+ // In the package dir
162
+ resolve(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR)
163
+ ]) {
164
+ if (existsSync(join(dir, "BUILD_ID"))) {
165
+ return dir;
166
+ }
167
+ }
168
+ return false;
169
+ }
149
170
  /**
150
171
  * Get Next.js middleware config from the build output
151
172
  */
@@ -159,12 +180,41 @@ var PluginContext = class {
159
180
  /** Get RequiredServerFiles manifest from build output **/
160
181
  get requiredServerFiles() {
161
182
  if (!this._requiredServerFiles) {
183
+ let requiredServerFilesJson = join(this.publishDir, "required-server-files.json");
184
+ if (!existsSync(requiredServerFilesJson)) {
185
+ const dotNext = this.findDotNext();
186
+ if (dotNext) {
187
+ requiredServerFilesJson = join(dotNext, "required-server-files.json");
188
+ }
189
+ }
162
190
  this._requiredServerFiles = JSON.parse(
163
- readFileSync(join(this.publishDir, "required-server-files.json"), "utf-8")
191
+ readFileSync(requiredServerFilesJson, "utf-8")
164
192
  );
165
193
  }
166
194
  return this._requiredServerFiles;
167
195
  }
196
+ #exportDetail = null;
197
+ /** Get metadata when output = export */
198
+ get exportDetail() {
199
+ if (this.buildConfig.output !== "export") {
200
+ return null;
201
+ }
202
+ if (!this.#exportDetail) {
203
+ const detailFile = join(
204
+ this.requiredServerFiles.appDir,
205
+ this.buildConfig.distDir,
206
+ "export-detail.json"
207
+ );
208
+ if (!existsSync(detailFile)) {
209
+ return null;
210
+ }
211
+ try {
212
+ this.#exportDetail = JSON.parse(readFileSync(detailFile, "utf-8"));
213
+ } catch {
214
+ }
215
+ }
216
+ return this.#exportDetail;
217
+ }
168
218
  /** Get Next Config from build output **/
169
219
  get buildConfig() {
170
220
  return this.requiredServerFiles.config;
@@ -540,16 +540,35 @@ var getDeployStore = (options = {}) => {
540
540
  };
541
541
 
542
542
  // src/run/headers.ts
543
- var generateNetlifyVaryValues = ({ headers, languages, cookies }) => {
543
+ var ALL_VARIATIONS = Symbol.for("ALL_VARIATIONS");
544
+ var NetlifyVaryKeys = /* @__PURE__ */ new Set(["header", "language", "cookie", "query", "country"]);
545
+ var isNetlifyVaryKey = (key) => NetlifyVaryKeys.has(key);
546
+ var generateNetlifyVaryValues = ({
547
+ header,
548
+ language,
549
+ cookie,
550
+ query,
551
+ country
552
+ }) => {
544
553
  const values = [];
545
- if (headers.length !== 0) {
546
- values.push(`header=${headers.join(`|`)}`);
554
+ if (query.length !== 0) {
555
+ if (query.includes(ALL_VARIATIONS)) {
556
+ values.push(`query`);
557
+ } else {
558
+ values.push(`query=${query.join(`|`)}`);
559
+ }
560
+ }
561
+ if (header.length !== 0) {
562
+ values.push(`header=${header.join(`|`)}`);
547
563
  }
548
- if (languages.length !== 0) {
549
- values.push(`language=${languages.join(`|`)}`);
564
+ if (language.length !== 0) {
565
+ values.push(`language=${language.join(`|`)}`);
550
566
  }
551
- if (cookies.length !== 0) {
552
- values.push(`cookie=${cookies.join(`|`)}`);
567
+ if (cookie.length !== 0) {
568
+ values.push(`cookie=${cookie.join(`|`)}`);
569
+ }
570
+ if (country.length !== 0) {
571
+ values.push(`country=${country.join(`|`)}`);
553
572
  }
554
573
  return values.join(",");
555
574
  };
@@ -570,19 +589,33 @@ var mapHeaderValues = (header, callback) => {
570
589
  };
571
590
  var setVaryHeaders = (headers, request, { basePath, i18n }) => {
572
591
  const netlifyVaryValues = {
573
- headers: ["x-nextjs-data"],
574
- languages: [],
575
- cookies: ["__prerender_bypass", "__next_preview_data"]
592
+ header: ["x-nextjs-data"],
593
+ language: [],
594
+ cookie: ["__prerender_bypass", "__next_preview_data"],
595
+ query: [],
596
+ country: []
576
597
  };
577
598
  const vary = headers.get("vary");
578
599
  if (vary !== null) {
579
- netlifyVaryValues.headers.push(...getHeaderValueArray(vary));
600
+ netlifyVaryValues.header.push(...getHeaderValueArray(vary));
580
601
  }
581
602
  const path = new URL(request.url).pathname;
582
603
  const locales = i18n && i18n.localeDetection !== false ? i18n.locales : [];
583
604
  if (locales.length > 1 && (path === "/" || path === basePath)) {
584
- netlifyVaryValues.languages.push(...locales);
585
- netlifyVaryValues.cookies.push(`NEXT_LOCALE`);
605
+ netlifyVaryValues.language.push(...locales);
606
+ netlifyVaryValues.cookie.push(`NEXT_LOCALE`);
607
+ }
608
+ const userNetlifyVary = headers.get("netlify-vary");
609
+ if (userNetlifyVary) {
610
+ const directives = getHeaderValueArray(userNetlifyVary);
611
+ for (const directive of directives) {
612
+ const [key, value] = directive.split("=");
613
+ if (key === "query" && !value) {
614
+ netlifyVaryValues.query.push(ALL_VARIATIONS);
615
+ } else if (value && isNetlifyVaryKey(key)) {
616
+ netlifyVaryValues[key].push(...value.split("|"));
617
+ }
618
+ }
586
619
  }
587
620
  headers.set(`netlify-vary`, generateNetlifyVaryValues(netlifyVaryValues));
588
621
  };
@@ -647,7 +680,7 @@ var adjustDateHeader = async ({
647
680
  headers.set("date", lastModifiedDate.toUTCString());
648
681
  };
649
682
  var setCacheControlHeaders = (headers, request, requestContext) => {
650
- if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("netlify-cdn-cache-control")) {
683
+ if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
651
684
  const cdnCacheControl = (
652
685
  // if we are serving already stale response, instruct edge to not attempt to cache that response
653
686
  headers.get("x-nextjs-cache") === "STALE" ? "public, max-age=0, must-revalidate" : `s-maxage=${requestContext.routeHandlerRevalidate === false ? 31536e3 : requestContext.routeHandlerRevalidate}, stale-while-revalidate=31536000`
@@ -9,7 +9,7 @@ import {
9
9
  } from "./chunk-VZNKO4OO.js";
10
10
  import {
11
11
  EDGE_HANDLER_NAME
12
- } from "./chunk-3NYX5FXN.js";
12
+ } from "./chunk-L6OM53B6.js";
13
13
  import {
14
14
  __commonJS,
15
15
  __toESM
@@ -73,9 +73,12 @@ var copyStaticAssets = async (ctx) => {
73
73
  };
74
74
  var copyStaticExport = async (ctx) => {
75
75
  await tracer.withActiveSpan("copyStaticExport", async () => {
76
+ if (!ctx.exportDetail?.outDirectory) {
77
+ ctx.failBuild("Export directory not found");
78
+ }
76
79
  try {
77
80
  await rm(ctx.staticDir, { recursive: true, force: true });
78
- await cp(ctx.resolveFromSiteDir("out"), ctx.staticDir, { recursive: true });
81
+ await cp(ctx.exportDetail.outDirectory, ctx.staticDir, { recursive: true });
79
82
  } catch (error) {
80
83
  ctx.failBuild("Failed copying static export", error);
81
84
  }
@@ -8,7 +8,7 @@ import "./chunk-5JVNISGM.js";
8
8
 
9
9
  // package.json
10
10
  var name = "@netlify/plugin-nextjs";
11
- var version = "5.1.0";
11
+ var version = "5.1.2";
12
12
  var description = "Run Next.js seamlessly on Netlify";
13
13
  var main = "./dist/index.js";
14
14
  var type = "module";
@@ -59,8 +59,8 @@ var devDependencies = {
59
59
  "@fastly/http-compute-js": "1.1.4",
60
60
  "@netlify/blobs": "^7.0.1",
61
61
  "@netlify/build": "^29.37.2",
62
- "@netlify/edge-bundler": "^11.3.0",
63
- "@netlify/edge-functions": "^2.3.1",
62
+ "@netlify/edge-bundler": "^11.4.0",
63
+ "@netlify/edge-functions": "^2.5.1",
64
64
  "@netlify/eslint-config-node": "^7.0.1",
65
65
  "@netlify/functions": "^2.5.1",
66
66
  "@netlify/serverless-functions-api": "^1.10.1",
package/dist/index.js CHANGED
@@ -6,18 +6,18 @@
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "./esm-chunks/chunk-F5VQRN6L.js";
9
+ } from "./esm-chunks/chunk-HESS57SH.js";
10
10
  import {
11
11
  copyPrerenderedContent
12
12
  } from "./esm-chunks/chunk-MRD3XSKD.js";
13
- import "./esm-chunks/chunk-ZKJEJNSJ.js";
13
+ import "./esm-chunks/chunk-4BNHE6TP.js";
14
14
  import {
15
15
  copyStaticAssets,
16
16
  copyStaticContent,
17
17
  copyStaticExport,
18
18
  publishStaticDir,
19
19
  unpublishStaticDir
20
- } from "./esm-chunks/chunk-74THQNRG.js";
20
+ } from "./esm-chunks/chunk-V2T6NUOM.js";
21
21
  import "./esm-chunks/chunk-TYCYFZ22.js";
22
22
  import {
23
23
  wrapTracer
@@ -28,7 +28,7 @@ import {
28
28
  } from "./esm-chunks/chunk-Y3K5Q6FP.js";
29
29
  import {
30
30
  createEdgeHandlers
31
- } from "./esm-chunks/chunk-OBKVBMAL.js";
31
+ } from "./esm-chunks/chunk-UTQSBE5O.js";
32
32
  import "./esm-chunks/chunk-VZNKO4OO.js";
33
33
  import {
34
34
  restoreBuildCache,
@@ -39,12 +39,12 @@ import {
39
39
  } from "./esm-chunks/chunk-MCEOSJH6.js";
40
40
  import {
41
41
  PluginContext
42
- } from "./esm-chunks/chunk-3NYX5FXN.js";
42
+ } from "./esm-chunks/chunk-L6OM53B6.js";
43
43
  import {
44
44
  verifyBuildConfig,
45
45
  verifyNoAdvancedAPIRoutes,
46
46
  verifyPublishDir
47
- } from "./esm-chunks/chunk-PH26UF2W.js";
47
+ } from "./esm-chunks/chunk-K7BTUM7O.js";
48
48
  import "./esm-chunks/chunk-PJG75HGC.js";
49
49
  import "./esm-chunks/chunk-BG455SFE.js";
50
50
  import "./esm-chunks/chunk-UYKENJEU.js";
@@ -10,7 +10,7 @@ import {
10
10
  setCacheStatusHeader,
11
11
  setCacheTagsHeaders,
12
12
  setVaryHeaders
13
- } from "../../esm-chunks/chunk-57DK2TJ7.js";
13
+ } from "../../esm-chunks/chunk-PMRBBOBY.js";
14
14
  import {
15
15
  nextResponseProxy
16
16
  } from "../../esm-chunks/chunk-RL4K4CVH.js";
@@ -51202,7 +51202,7 @@ var import_sdk_trace_node = __toESM(require_src14(), 1);
51202
51202
  var import_semantic_conventions = __toESM(require_src(), 1);
51203
51203
  var {
51204
51204
  default: { version, name }
51205
- } = await import("../../esm-chunks/package-RGWYJEMK.js");
51205
+ } = await import("../../esm-chunks/package-RVJOBSMH.js");
51206
51206
  var sdk = new import_sdk_node.NodeSDK({
51207
51207
  resource: new import_resources.Resource({
51208
51208
  [import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
@@ -10,7 +10,7 @@ import {
10
10
  setCacheStatusHeader,
11
11
  setCacheTagsHeaders,
12
12
  setVaryHeaders
13
- } from "../esm-chunks/chunk-57DK2TJ7.js";
13
+ } from "../esm-chunks/chunk-PMRBBOBY.js";
14
14
  import "../esm-chunks/chunk-TYCYFZ22.js";
15
15
  import "../esm-chunks/chunk-5JVNISGM.js";
16
16
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",