@netlify/plugin-nextjs 5.7.3 → 5.8.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.
@@ -18,23 +18,38 @@ var ApiRouteType = /* @__PURE__ */ ((ApiRouteType2) => {
18
18
  return ApiRouteType2;
19
19
  })(ApiRouteType || {});
20
20
  async function getAPIRoutesConfigs(ctx) {
21
+ const uniqueApiRoutes = /* @__PURE__ */ new Set();
21
22
  const functionsConfigManifestPath = join(
22
23
  ctx.publishDir,
23
24
  "server",
24
25
  "functions-config-manifest.json"
25
26
  );
26
- if (!existsSync(functionsConfigManifestPath)) {
27
+ if (existsSync(functionsConfigManifestPath)) {
28
+ const functionsConfigManifest = JSON.parse(
29
+ await readFile(functionsConfigManifestPath, "utf-8")
30
+ );
31
+ for (const apiRoute of Object.keys(functionsConfigManifest.functions)) {
32
+ uniqueApiRoutes.add(apiRoute);
33
+ }
34
+ }
35
+ const pagesManifestPath = join(ctx.publishDir, "server", "pages-manifest.json");
36
+ if (existsSync(pagesManifestPath)) {
37
+ const pagesManifest = JSON.parse(await readFile(pagesManifestPath, "utf-8"));
38
+ for (const route of Object.keys(pagesManifest)) {
39
+ if (route.startsWith("/api/")) {
40
+ uniqueApiRoutes.add(route);
41
+ }
42
+ }
43
+ }
44
+ if (uniqueApiRoutes.size === 0) {
27
45
  return [];
28
46
  }
29
- const functionsConfigManifest = JSON.parse(
30
- await readFile(functionsConfigManifestPath, "utf-8")
31
- );
32
47
  const appDir = ctx.resolveFromSiteDir(".");
33
48
  const pagesDir = join(appDir, "pages");
34
49
  const srcPagesDir = join(appDir, "src", "pages");
35
50
  const { pageExtensions } = ctx.requiredServerFiles.config;
36
51
  return Promise.all(
37
- Object.keys(functionsConfigManifest.functions).map(async (apiRoute) => {
52
+ [...uniqueApiRoutes].map(async (apiRoute) => {
38
53
  const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir], pageExtensions);
39
54
  const sharedFields = {
40
55
  apiRoute,
@@ -8,7 +8,7 @@ import "./chunk-OEQOKJGE.js";
8
8
 
9
9
  // package.json
10
10
  var name = "@netlify/plugin-nextjs";
11
- var version = "5.7.3";
11
+ var version = "5.8.0";
12
12
  var description = "Run Next.js seamlessly on Netlify";
13
13
  var main = "./dist/index.js";
14
14
  var type = "module";
@@ -58,13 +58,13 @@ var homepage = "https://github.com/netlify/next-runtime#readme";
58
58
  var devDependencies = {
59
59
  "@fastly/http-compute-js": "1.1.4",
60
60
  "@netlify/blobs": "^8.0.1",
61
- "@netlify/build": "^29.54.8",
61
+ "@netlify/build": "^29.55.2",
62
62
  "@netlify/edge-bundler": "^12.2.3",
63
63
  "@netlify/edge-functions": "^2.11.0",
64
64
  "@netlify/eslint-config-node": "^7.0.1",
65
65
  "@netlify/functions": "^2.8.2",
66
- "@netlify/serverless-functions-api": "^1.29.0",
67
- "@netlify/zip-it-and-ship-it": "^9.39.6",
66
+ "@netlify/serverless-functions-api": "^1.30.1",
67
+ "@netlify/zip-it-and-ship-it": "^9.40.2",
68
68
  "@opentelemetry/api": "^1.8.0",
69
69
  "@opentelemetry/exporter-trace-otlp-http": "^0.51.0",
70
70
  "@opentelemetry/resources": "^1.24.0",
@@ -169,10 +169,10 @@ var NetlifyCacheHandler = class {
169
169
  }
170
170
  if (cacheValue.kind === "PAGE" || cacheValue.kind === "PAGES" || cacheValue.kind === "APP_PAGE" || cacheValue.kind === "ROUTE" || cacheValue.kind === "APP_ROUTE") {
171
171
  if (cacheValue.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]) {
172
- const cacheTags = cacheValue.headers[import_constants.NEXT_CACHE_TAGS_HEADER].split(",");
172
+ const cacheTags = cacheValue.headers[import_constants.NEXT_CACHE_TAGS_HEADER].split(/,|%2c/gi);
173
173
  requestContext.responseCacheTags = cacheTags;
174
174
  } else if ((cacheValue.kind === "PAGE" || cacheValue.kind === "PAGES") && typeof cacheValue.pageData === "object") {
175
- const cacheTags = [`_N_T_${key === "/index" ? "/" : key}`];
175
+ const cacheTags = [`_N_T_${key === "/index" ? "/" : encodeURI(key)}`];
176
176
  requestContext.responseCacheTags = cacheTags;
177
177
  }
178
178
  }
@@ -319,10 +319,10 @@ var NetlifyCacheHandler = class {
319
319
  if (data?.kind === "PAGE" || data?.kind === "PAGES") {
320
320
  const requestContext = (0, import_request_context.getRequestContext)();
321
321
  if (requestContext?.didPagesRouterOnDemandRevalidate) {
322
- const tag = `_N_T_${key === "/index" ? "/" : key}`;
322
+ const tag = `_N_T_${key === "/index" ? "/" : encodeURI(key)}`;
323
323
  (0, import_request_context.getLogger)().debug(`Purging CDN cache for: [${tag}]`);
324
324
  requestContext.trackBackgroundWork(
325
- purgeCache({ tags: [tag] }).catch((error) => {
325
+ purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => {
326
326
  (0, import_request_context.getLogger)().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`);
327
327
  })
328
328
  );
@@ -342,7 +342,9 @@ var NetlifyCacheHandler = class {
342
342
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
343
  async doRevalidateTag(tagOrTags, ...args) {
344
344
  (0, import_request_context.getLogger)().withFields({ tagOrTags, args }).debug("NetlifyCacheHandler.revalidateTag");
345
- const tags = Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags];
345
+ const tags = (Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]).flatMap(
346
+ (tag) => tag.split(/,|%2c/gi)
347
+ );
346
348
  const data = {
347
349
  revalidatedAt: Date.now()
348
350
  };
@@ -370,7 +372,7 @@ var NetlifyCacheHandler = class {
370
372
  if (cacheEntry.value?.kind === "FETCH") {
371
373
  cacheTags = [...tags, ...softTags];
372
374
  } else if (cacheEntry.value?.kind === "PAGE" || cacheEntry.value?.kind === "PAGES" || cacheEntry.value?.kind === "APP_PAGE" || cacheEntry.value?.kind === "ROUTE" || cacheEntry.value?.kind === "APP_ROUTE") {
373
- cacheTags = cacheEntry.value.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]?.split(",") || [];
375
+ cacheTags = cacheEntry.value.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]?.split(/,|%2c/gi) || [];
374
376
  } else {
375
377
  return false;
376
378
  }
@@ -3161,7 +3161,7 @@ var server_default = async (request, context) => {
3161
3161
  span.setAttribute("responseCacheKey", requestContext.responseCacheKey);
3162
3162
  }
3163
3163
  await adjustDateHeader({ headers: response.headers, request, span, tracer, requestContext });
3164
- setCacheControlHeaders(response.headers, request, requestContext);
3164
+ setCacheControlHeaders(response, request, requestContext);
3165
3165
  setCacheTagsHeaders(response.headers, requestContext);
3166
3166
  setVaryHeaders(response.headers, request, nextConfig);
3167
3167
  setCacheStatusHeader(response.headers);
@@ -68866,7 +68866,7 @@ var import_semantic_conventions = __toESM(require_src(), 1);
68866
68866
  import { getLogger } from "./request-context.cjs";
68867
68867
  var {
68868
68868
  default: { version, name }
68869
- } = await import("../../esm-chunks/package-EEQP43EX.js");
68869
+ } = await import("../../esm-chunks/package-4GFWM3PF.js");
68870
68870
  var sdk = new import_sdk_node.NodeSDK({
68871
68871
  resource: new import_resources.Resource({
68872
68872
  [import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
@@ -42,7 +42,7 @@ var generateNetlifyVaryValues = ({
42
42
  return values.join(",");
43
43
  };
44
44
  var getHeaderValueArray = (header) => {
45
- return header.split(",").map((value) => value.trim());
45
+ return header.split(",").map((value) => value.trim()).filter(Boolean);
46
46
  };
47
47
  var omitHeaderValues = (header, values) => {
48
48
  const headerValues = getHeaderValueArray(header);
@@ -142,7 +142,7 @@ var adjustDateHeader = async ({
142
142
  headers.set("x-nextjs-date", headers.get("date") ?? lastModifiedDate.toUTCString());
143
143
  headers.set("date", lastModifiedDate.toUTCString());
144
144
  };
145
- var setCacheControlHeaders = (headers, request, requestContext) => {
145
+ var setCacheControlHeaders = ({ headers, status }, request, requestContext) => {
146
146
  if (typeof requestContext.routeHandlerRevalidate !== "undefined" && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
147
147
  const cdnCacheControl = (
148
148
  // if we are serving already stale response, instruct edge to not attempt to cache that response
@@ -151,6 +151,10 @@ var setCacheControlHeaders = (headers, request, requestContext) => {
151
151
  headers.set("netlify-cdn-cache-control", cdnCacheControl);
152
152
  return;
153
153
  }
154
+ if (status === 404 && request.url.endsWith(".php")) {
155
+ headers.set("cache-control", "public, max-age=0, must-revalidate");
156
+ headers.set("netlify-cdn-cache-control", `max-age=31536000, durable`);
157
+ }
154
158
  const cacheControl = headers.get("cache-control");
155
159
  if (cacheControl !== null && ["GET", "HEAD"].includes(request.method) && !headers.has("cdn-cache-control") && !headers.has("netlify-cdn-cache-control")) {
156
160
  const browserCacheControl = omitHeaderValues(cacheControl, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.7.3",
3
+ "version": "5.8.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",