@netlify/plugin-nextjs 5.0.0-beta.1 → 5.0.0-beta.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.
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-G3GM7JNF.js";
10
+ } from "../../esm-chunks/chunk-S5JXJCXP.js";
11
11
  import "../../esm-chunks/chunk-AVWFCGVE.js";
12
12
  import "../../esm-chunks/chunk-RSKIKBZH.js";
13
13
  export {
@@ -8,7 +8,7 @@ import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
10
  writeTagsManifest
11
- } from "../../esm-chunks/chunk-A22224GM.js";
11
+ } from "../../esm-chunks/chunk-5SZ5JD6J.js";
12
12
  import "../../esm-chunks/chunk-AVWFCGVE.js";
13
13
  import "../../esm-chunks/chunk-RSKIKBZH.js";
14
14
  export {
@@ -6,8 +6,8 @@
6
6
 
7
7
  import {
8
8
  createEdgeHandlers
9
- } from "../../esm-chunks/chunk-UXLNY5XK.js";
10
- import "../../esm-chunks/chunk-VP3PT3VV.js";
9
+ } from "../../esm-chunks/chunk-3PTPU5GO.js";
10
+ import "../../esm-chunks/chunk-TJKO3X6O.js";
11
11
  import "../../esm-chunks/chunk-RSKIKBZH.js";
12
12
  export {
13
13
  createEdgeHandlers
@@ -6,10 +6,10 @@
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "../../esm-chunks/chunk-NOX2JUQZ.js";
10
- import "../../esm-chunks/chunk-A22224GM.js";
9
+ } from "../../esm-chunks/chunk-ALO2SSMH.js";
10
+ import "../../esm-chunks/chunk-5SZ5JD6J.js";
11
11
  import "../../esm-chunks/chunk-AVWFCGVE.js";
12
- import "../../esm-chunks/chunk-VP3PT3VV.js";
12
+ import "../../esm-chunks/chunk-TJKO3X6O.js";
13
13
  import "../../esm-chunks/chunk-RSKIKBZH.js";
14
14
  export {
15
15
  createServerHandler
@@ -0,0 +1,13 @@
1
+
2
+ const require = await (async () => {
3
+ const { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ setImageConfig
9
+ } from "../esm-chunks/chunk-H46DW7YI.js";
10
+ import "../esm-chunks/chunk-RSKIKBZH.js";
11
+ export {
12
+ setImageConfig
13
+ };
@@ -8,7 +8,7 @@ import {
8
8
  EDGE_HANDLER_NAME,
9
9
  PluginContext,
10
10
  SERVER_HANDLER_NAME
11
- } from "../esm-chunks/chunk-VP3PT3VV.js";
11
+ } from "../esm-chunks/chunk-TJKO3X6O.js";
12
12
  import "../esm-chunks/chunk-RSKIKBZH.js";
13
13
  export {
14
14
  EDGE_HANDLER_NAME,
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  EDGE_HANDLER_NAME
9
- } from "./chunk-VP3PT3VV.js";
9
+ } from "./chunk-TJKO3X6O.js";
10
10
 
11
11
  // src/build/functions/edge.ts
12
12
  import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
@@ -19,10 +19,13 @@ import { dirname, join } from "node:path";
19
19
  var copyNextServerCode = async (ctx) => {
20
20
  const srcDir = join(ctx.publishDir, "standalone/.next");
21
21
  const destDir = join(ctx.serverHandlerDir, ".next");
22
- const paths = await (0, import_fast_glob.default)([`*`, `server/*`, `server/chunks/*`, `server/+(app|pages)/**/*.js`], {
23
- cwd: srcDir,
24
- extglob: true
25
- });
22
+ const paths = await (0, import_fast_glob.default)(
23
+ [`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
24
+ {
25
+ cwd: srcDir,
26
+ extglob: true
27
+ }
28
+ );
26
29
  await Promise.all(
27
30
  paths.map(async (path) => {
28
31
  const srcPath = join(srcDir, path);
@@ -77,7 +80,9 @@ var writeTagsManifest = async (ctx) => {
77
80
  const meta = JSON.parse(file);
78
81
  tags = meta.headers["x-next-cache-tags"];
79
82
  } catch {
80
- console.log(`Unable to read cache tags for: ${path}`);
83
+ if (!definition.dataRoute?.endsWith("/default.rsc")) {
84
+ console.log(`Unable to read cache tags for: ${path}`);
85
+ }
81
86
  }
82
87
  }
83
88
  if (definition.dataRoute?.endsWith(".json")) {
@@ -8,13 +8,13 @@ import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
10
  writeTagsManifest
11
- } from "./chunk-A22224GM.js";
11
+ } from "./chunk-5SZ5JD6J.js";
12
12
  import {
13
13
  require_out
14
14
  } from "./chunk-AVWFCGVE.js";
15
15
  import {
16
16
  SERVER_HANDLER_NAME
17
- } from "./chunk-VP3PT3VV.js";
17
+ } from "./chunk-TJKO3X6O.js";
18
18
  import {
19
19
  __toESM
20
20
  } from "./chunk-RSKIKBZH.js";
@@ -0,0 +1,28 @@
1
+
2
+ const require = await (async () => {
3
+ const { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/build/image-cdn.ts
9
+ var setImageConfig = async (ctx) => {
10
+ const {
11
+ images: { path: imageEndpointPath, loader: imageLoader }
12
+ } = await ctx.getBuildConfig();
13
+ if (imageLoader === "default") {
14
+ ctx.netlifyConfig.redirects.push({
15
+ from: imageEndpointPath,
16
+ // w and q are too short to be used as params with id-length rule
17
+ // but we are forced to do so because of the next/image loader decides on their names
18
+ // eslint-disable-next-line id-length
19
+ query: { url: ":url", w: ":width", q: ":quality" },
20
+ to: "/.netlify/images?url=:url&w=:width&q=:quality",
21
+ status: 200
22
+ });
23
+ }
24
+ };
25
+
26
+ export {
27
+ setImageConfig
28
+ };
@@ -45,6 +45,8 @@ var copyPrerenderedContent = async (ctx) => {
45
45
  const key = routeToFilePath(route);
46
46
  let value;
47
47
  switch (true) {
48
+ case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
49
+ return;
48
50
  case meta.dataRoute?.endsWith(".json"):
49
51
  value = await buildPagesCacheValue(join(ctx.publishDir, "server/pages", key));
50
52
  break;
@@ -13,6 +13,8 @@ import { Buffer } from "buffer";
13
13
  import { env } from "process";
14
14
  import { Buffer as Buffer2 } from "buffer";
15
15
  import { Buffer as Buffer3 } from "buffer";
16
+ import stream from "stream";
17
+ import { promisify } from "util";
16
18
  var getEnvironmentContext = () => {
17
19
  const context = globalThis.netlifyBlobsContext || env.NETLIFY_BLOBS_CONTEXT;
18
20
  if (typeof context !== "string" || !context) {
@@ -469,6 +471,7 @@ var getDeployStore = (options = {}) => {
469
471
  const client = new Client(clientOptions);
470
472
  return new Store({ client, deployID });
471
473
  };
474
+ var pipeline = promisify(stream.pipeline);
472
475
 
473
476
  // src/run/headers.ts
474
477
  var generateNetlifyVaryValues = ({ headers, languages, cookies }) => {
@@ -555,10 +558,25 @@ var setCacheTagsHeaders = (headers, request, manifest) => {
555
558
  const tags = manifest[path];
556
559
  headers.set("cache-tag", tags);
557
560
  };
561
+ var NEXT_CACHE_TO_CACHE_STATUS = {
562
+ HIT: `hit`,
563
+ MISS: `miss,`
564
+ };
565
+ var handleNextCacheHeader = (headers) => {
566
+ const nextCache = headers.get("x-nextjs-cache");
567
+ if (typeof nextCache === "string") {
568
+ if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
569
+ const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
570
+ headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
571
+ }
572
+ headers.delete("x-nextjs-cache");
573
+ }
574
+ };
558
575
 
559
576
  export {
560
577
  setVaryHeaders,
561
578
  adjustDateHeader,
562
579
  setCacheControlHeaders,
563
- setCacheTagsHeaders
580
+ setCacheTagsHeaders,
581
+ handleNextCacheHeader
564
582
  };
@@ -17,6 +17,7 @@ var SERVER_HANDLER_NAME = "___netlify-server-handler";
17
17
  var EDGE_HANDLER_NAME = "___netlify-edge-handler";
18
18
  var PluginContext = class {
19
19
  utils;
20
+ netlifyConfig;
20
21
  pluginName;
21
22
  pluginVersion;
22
23
  constants;
@@ -70,6 +71,7 @@ var PluginContext = class {
70
71
  this.pluginVersion = this.packageJSON.version;
71
72
  this.constants = options.constants;
72
73
  this.utils = options.utils;
74
+ this.netlifyConfig = options.netlifyConfig;
73
75
  }
74
76
  /** Resolves a path correctly with mono repository awareness */
75
77
  resolve(...args) {
@@ -87,6 +89,10 @@ var PluginContext = class {
87
89
  await readFile(join(this.publishDir, "server/middleware-manifest.json"), "utf-8")
88
90
  );
89
91
  }
92
+ /** Get Next Config from build output **/
93
+ async getBuildConfig() {
94
+ return JSON.parse(await readFile(join(this.publishDir, "required-server-files.json"), "utf-8")).config;
95
+ }
90
96
  /**
91
97
  * Get Next.js routes manifest from the build output
92
98
  */
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "./esm-chunks/chunk-G3GM7JNF.js";
10
+ } from "./esm-chunks/chunk-S5JXJCXP.js";
11
11
  import {
12
12
  copyStaticAssets,
13
13
  copyStaticContent,
@@ -16,19 +16,22 @@ import {
16
16
  } from "./esm-chunks/chunk-Z7ZMLVTM.js";
17
17
  import {
18
18
  createEdgeHandlers
19
- } from "./esm-chunks/chunk-UXLNY5XK.js";
19
+ } from "./esm-chunks/chunk-3PTPU5GO.js";
20
20
  import {
21
21
  createServerHandler
22
- } from "./esm-chunks/chunk-NOX2JUQZ.js";
23
- import "./esm-chunks/chunk-A22224GM.js";
22
+ } from "./esm-chunks/chunk-ALO2SSMH.js";
23
+ import "./esm-chunks/chunk-5SZ5JD6J.js";
24
24
  import "./esm-chunks/chunk-AVWFCGVE.js";
25
25
  import {
26
26
  restoreBuildCache,
27
27
  saveBuildCache
28
28
  } from "./esm-chunks/chunk-GGHAQM5D.js";
29
+ import {
30
+ setImageConfig
31
+ } from "./esm-chunks/chunk-H46DW7YI.js";
29
32
  import {
30
33
  PluginContext
31
- } from "./esm-chunks/chunk-VP3PT3VV.js";
34
+ } from "./esm-chunks/chunk-TJKO3X6O.js";
32
35
  import "./esm-chunks/chunk-RSKIKBZH.js";
33
36
 
34
37
  // src/index.ts
@@ -42,6 +45,7 @@ var onBuild = async (options) => {
42
45
  if (!existsSync(ctx.publishDir)) {
43
46
  ctx.failBuild("Publish directory not found, please check your netlify.toml");
44
47
  }
48
+ await setImageConfig(ctx);
45
49
  await saveBuildCache(ctx);
46
50
  await Promise.all([
47
51
  copyStaticAssets(ctx),
@@ -174,8 +174,8 @@ var require_stream = __commonJS({
174
174
  exports2.stream = void 0;
175
175
  var node_stream_1 = require("node:stream");
176
176
  var node_util_1 = require("node:util");
177
- var pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
178
- var stream = (handler) => awslambda.streamifyResponse(async (event, responseStream, context) => {
177
+ var pipeline2 = (0, node_util_1.promisify)(node_stream_1.pipeline);
178
+ var stream2 = (handler) => awslambda.streamifyResponse(async (event, responseStream, context) => {
179
179
  const { body, ...httpResponseMetadata } = await handler(event, context);
180
180
  const responseBody = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
181
181
  if (typeof body === "undefined") {
@@ -184,10 +184,10 @@ var require_stream = __commonJS({
184
184
  responseBody.write(body);
185
185
  responseBody.end();
186
186
  } else {
187
- await pipeline(body, responseBody);
187
+ await pipeline2(body, responseBody);
188
188
  }
189
189
  });
190
- exports2.stream = stream;
190
+ exports2.stream = stream2;
191
191
  }
192
192
  });
193
193
 
@@ -249,7 +249,6 @@ var require_main = __commonJS({
249
249
  var cache_exports = {};
250
250
  __export(cache_exports, {
251
251
  NetlifyCacheHandler: () => NetlifyCacheHandler,
252
- blobStore: () => blobStore,
253
252
  default: () => cache_default
254
253
  });
255
254
  module.exports = __toCommonJS(cache_exports);
@@ -262,6 +261,8 @@ var import_buffer = require("buffer");
262
261
  var import_process = require("process");
263
262
  var import_buffer2 = require("buffer");
264
263
  var import_buffer3 = require("buffer");
264
+ var import_stream = __toESM(require("stream"), 1);
265
+ var import_util = require("util");
265
266
  var getEnvironmentContext = () => {
266
267
  const context = globalThis.netlifyBlobsContext || import_process.env.NETLIFY_BLOBS_CONTEXT;
267
268
  if (typeof context !== "string" || !context) {
@@ -718,11 +719,11 @@ var getDeployStore = (options = {}) => {
718
719
  const client = new Client(clientOptions);
719
720
  return new Store({ client, deployID });
720
721
  };
722
+ var pipeline = (0, import_util.promisify)(import_stream.default.pipeline);
721
723
 
722
724
  // src/run/handlers/cache.cts
723
725
  var import_functions = __toESM(require_main());
724
726
  var import_constants = require("next/dist/lib/constants.js");
725
- var blobStore = getDeployStore();
726
727
  var prerenderManifest = JSON.parse(
727
728
  (0, import_node_fs.readFileSync)((0, import_posix.join)(process.cwd(), ".next/prerender-manifest.json"), "utf-8")
728
729
  );
@@ -732,17 +733,20 @@ function toRoute(cacheKey) {
732
733
  function encodeBlobKey(key) {
733
734
  return import_node_buffer.Buffer.from(key.replace(/^\//, "")).toString("base64");
734
735
  }
736
+ var fetchBeforeNextPatchedIt = globalThis.fetch;
735
737
  var NetlifyCacheHandler = class {
736
738
  options;
737
739
  revalidatedTags;
740
+ blobStore;
738
741
  constructor(options) {
739
742
  this.options = options;
740
743
  this.revalidatedTags = options.revalidatedTags;
744
+ this.blobStore = getDeployStore({ fetch: fetchBeforeNextPatchedIt });
741
745
  }
742
746
  async get(...args) {
743
747
  const [key, ctx = {}] = args;
744
748
  console.debug(`[NetlifyCacheHandler.get]: ${key}`);
745
- const blob = await blobStore.get(encodeBlobKey(key), {
749
+ const blob = await this.blobStore.get(encodeBlobKey(key), {
746
750
  type: "json"
747
751
  });
748
752
  if (!blob) {
@@ -786,7 +790,7 @@ var NetlifyCacheHandler = class {
786
790
  async set(...args) {
787
791
  const [key, data] = args;
788
792
  console.debug(`[NetlifyCacheHandler.set]: ${key}`);
789
- await blobStore.setJSON(encodeBlobKey(key), {
793
+ await this.blobStore.setJSON(encodeBlobKey(key), {
790
794
  lastModified: Date.now(),
791
795
  value: data
792
796
  });
@@ -798,7 +802,7 @@ var NetlifyCacheHandler = class {
798
802
  revalidatedAt: Date.now()
799
803
  };
800
804
  try {
801
- await blobStore.setJSON(encodeBlobKey(tag), data);
805
+ await this.blobStore.setJSON(encodeBlobKey(tag), data);
802
806
  } catch (error) {
803
807
  console.warn(`Failed to update tag manifest for ${tag}`, error);
804
808
  }
@@ -814,7 +818,7 @@ var NetlifyCacheHandler = class {
814
818
  const cacheTags = [...tags, ...softTags];
815
819
  const allManifests = await Promise.all(
816
820
  cacheTags.map(async (tag) => {
817
- const res = await blobStore.get(encodeBlobKey(tag), { type: "json" }).then((value) => ({ [tag]: value })).catch(console.error);
821
+ const res = await this.blobStore.get(encodeBlobKey(tag), { type: "json" }).then((value) => ({ [tag]: value })).catch(console.error);
818
822
  return res || { [tag]: null };
819
823
  })
820
824
  );
@@ -847,6 +851,5 @@ var NetlifyCacheHandler = class {
847
851
  var cache_default = NetlifyCacheHandler;
848
852
  // Annotate the CommonJS export names for ESM import in node:
849
853
  0 && (module.exports = {
850
- NetlifyCacheHandler,
851
- blobStore
854
+ NetlifyCacheHandler
852
855
  });
@@ -4,22 +4,23 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
+ import {
8
+ logger
9
+ } from "../../esm-chunks/chunk-YZXA5QBC.js";
7
10
  import {
8
11
  getTagsManifest
9
12
  } from "../../esm-chunks/chunk-R4NHZWGU.js";
10
13
  import "../../esm-chunks/chunk-4AJYXTWN.js";
11
14
  import {
12
15
  adjustDateHeader,
16
+ handleNextCacheHeader,
13
17
  setCacheControlHeaders,
14
18
  setCacheTagsHeaders,
15
19
  setVaryHeaders
16
- } from "../../esm-chunks/chunk-5N2CWXSJ.js";
20
+ } from "../../esm-chunks/chunk-SMSOJ2OS.js";
17
21
  import {
18
22
  nextResponseProxy
19
23
  } from "../../esm-chunks/chunk-B6QMRLBH.js";
20
- import {
21
- logger
22
- } from "../../esm-chunks/chunk-YZXA5QBC.js";
23
24
  import {
24
25
  __commonJS,
25
26
  __toESM
@@ -3287,8 +3288,10 @@ var server_default = async (request) => {
3287
3288
  setCacheControlHeaders(response.headers, request);
3288
3289
  setCacheTagsHeaders(response.headers, request, tagsManifest);
3289
3290
  setVaryHeaders(response.headers, request, nextConfig);
3290
- if (response.status > 300 && response.status < 400) {
3291
- return new Response(null, response);
3291
+ handleNextCacheHeader(response.headers);
3292
+ if (response.status > 300 && response.status < 400 || response.status >= 500) {
3293
+ const body = await response.text();
3294
+ return new Response(body || null, response);
3292
3295
  }
3293
3296
  return response;
3294
3297
  };
@@ -6,13 +6,15 @@
6
6
 
7
7
  import {
8
8
  adjustDateHeader,
9
+ handleNextCacheHeader,
9
10
  setCacheControlHeaders,
10
11
  setCacheTagsHeaders,
11
12
  setVaryHeaders
12
- } from "../esm-chunks/chunk-5N2CWXSJ.js";
13
+ } from "../esm-chunks/chunk-SMSOJ2OS.js";
13
14
  import "../esm-chunks/chunk-RSKIKBZH.js";
14
15
  export {
15
16
  adjustDateHeader,
17
+ handleNextCacheHeader,
16
18
  setCacheControlHeaders,
17
19
  setCacheTagsHeaders,
18
20
  setVaryHeaders
package/dist/run/next.cjs CHANGED
@@ -564,6 +564,8 @@ var import_buffer = require("buffer");
564
564
  var import_process = require("process");
565
565
  var import_buffer2 = require("buffer");
566
566
  var import_buffer3 = require("buffer");
567
+ var import_stream = __toESM(require("stream"), 1);
568
+ var import_util = require("util");
567
569
  var getEnvironmentContext = () => {
568
570
  const context = globalThis.netlifyBlobsContext || import_process.env.NETLIFY_BLOBS_CONTEXT;
569
571
  if (typeof context !== "string" || !context) {
@@ -1020,6 +1022,7 @@ var getDeployStore = (options = {}) => {
1020
1022
  const client = new Client(clientOptions);
1021
1023
  return new Store({ client, deployID });
1022
1024
  };
1025
+ var pipeline = (0, import_util.promisify)(import_stream.default.pipeline);
1023
1026
 
1024
1027
  // src/run/next.cts
1025
1028
  var import_fs_monkey = __toESM(require_lib());
@@ -139,6 +139,7 @@ export const buildResponse = async ({
139
139
  }
140
140
 
141
141
  if (res.headers.get('x-middleware-next') === '1') {
142
+ res.headers.delete('x-middleware-next')
142
143
  return addMiddlewareHeaders(context.next(), res)
143
144
  }
144
145
  return res
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.0.0-beta.1",
3
+ "version": "5.0.0-beta.2",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",