@netlify/plugin-nextjs 5.8.1 → 5.9.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.
Files changed (61) hide show
  1. package/README.md +3 -2
  2. package/dist/build/advanced-api-routes.js +4 -136
  3. package/dist/build/cache.js +4 -25
  4. package/dist/build/content/prerendered.js +11 -290
  5. package/dist/build/content/server.js +11 -219
  6. package/dist/build/content/static.js +14 -103
  7. package/dist/build/functions/edge.js +7 -534
  8. package/dist/build/functions/server.js +11 -130
  9. package/dist/build/image-cdn.js +3 -1599
  10. package/dist/build/plugin-context.js +6 -292
  11. package/dist/build/templates/handler-monorepo.tmpl.js +1 -1
  12. package/dist/build/templates/handler.tmpl.js +1 -1
  13. package/dist/build/verification.js +9 -104
  14. package/dist/esm-chunks/chunk-72ZI2IVI.js +36 -0
  15. package/dist/esm-chunks/chunk-AMY4NOT5.js +1610 -0
  16. package/dist/esm-chunks/chunk-BEIUVQZK.js +212 -0
  17. package/dist/esm-chunks/chunk-BVYZSEV6.js +306 -0
  18. package/dist/esm-chunks/chunk-DLVROEVU.js +144 -0
  19. package/dist/esm-chunks/chunk-GFYWJNQR.js +305 -0
  20. package/dist/esm-chunks/chunk-HGXG447M.js +561 -0
  21. package/dist/esm-chunks/chunk-HWMLYAVP.js +122 -0
  22. package/dist/esm-chunks/chunk-IJZEDP6B.js +235 -0
  23. package/dist/esm-chunks/chunk-K4RDUZYO.js +609 -0
  24. package/dist/esm-chunks/chunk-KBX7SJLC.js +73 -0
  25. package/dist/esm-chunks/chunk-NDSDIXRD.js +122 -0
  26. package/dist/esm-chunks/chunk-TYCYFZ22.js +25 -0
  27. package/dist/esm-chunks/chunk-UYKENJEU.js +19 -0
  28. package/dist/esm-chunks/chunk-XS27YRA5.js +34 -0
  29. package/dist/esm-chunks/chunk-ZENB67PD.js +148 -0
  30. package/dist/esm-chunks/chunk-ZSVHJNNY.js +120 -0
  31. package/dist/esm-chunks/next-4L47PQSM.js +569 -0
  32. package/dist/esm-chunks/{package-AOKLDA5E.js → package-BD57IC76.js} +5 -5
  33. package/dist/index.js +39 -18
  34. package/dist/run/config.js +4 -1
  35. package/dist/run/constants.js +5 -7
  36. package/dist/run/handlers/cache.cjs +1618 -31
  37. package/dist/run/handlers/request-context.cjs +6 -2
  38. package/dist/run/handlers/server.js +40 -20
  39. package/dist/run/handlers/tracer.cjs +83 -2
  40. package/dist/run/handlers/tracing.js +4 -2
  41. package/dist/run/handlers/wait-until.cjs +122 -0
  42. package/dist/run/headers.js +9 -194
  43. package/dist/run/next.cjs +1597 -15
  44. package/dist/run/revalidate.js +3 -24
  45. package/dist/shared/blobkey.js +3 -15
  46. package/edge-runtime/lib/middleware.ts +1 -1
  47. package/edge-runtime/lib/response.ts +5 -2
  48. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter.js +1218 -0
  49. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm +0 -0
  50. package/edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts +80 -0
  51. package/edge-runtime/vendor/deno.land/x/{html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts → htmlrewriter@v1.0.0/src/types.d.ts} +8 -25
  52. package/edge-runtime/vendor/import_map.json +0 -2
  53. package/edge-runtime/vendor.ts +1 -1
  54. package/package.json +4 -4
  55. package/edge-runtime/vendor/deno.land/std@0.134.0/fmt/colors.ts +0 -536
  56. package/edge-runtime/vendor/deno.land/std@0.134.0/testing/_diff.ts +0 -360
  57. package/edge-runtime/vendor/deno.land/std@0.134.0/testing/asserts.ts +0 -866
  58. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +0 -133
  59. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +0 -112
  60. package/edge-runtime/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +0 -974
  61. package/edge-runtime/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +0 -50
package/README.md CHANGED
@@ -72,7 +72,8 @@ To upgrade from v4 to v5, please visit
72
72
  ## Feedback
73
73
 
74
74
  If you think you have found a bug in Next.js on Netlify,
75
- [please open an issue](https://github.com/netlify/next-runtime/issues). If you have comments or
76
- feature requests, [see the discussion board](https://github.com/netlify/next-runtime/discussions)
75
+ [please open an issue](https://github.com/opennextjs/opennextjs-netlify/issues). If you have
76
+ comments or feature requests,
77
+ [see the discussion board](https://github.com/opennextjs/opennextjs-netlify/discussions)
77
78
 
78
79
  Please note that v4 will only receive security fixes and critical bug fixes.
@@ -5,142 +5,10 @@
5
5
  })();
6
6
 
7
7
  import {
8
- __require
9
- } from "../esm-chunks/chunk-OEQOKJGE.js";
10
-
11
- // src/build/advanced-api-routes.ts
12
- import { existsSync } from "node:fs";
13
- import { readFile } from "node:fs/promises";
14
- import { join } from "node:path";
15
- var ApiRouteType = /* @__PURE__ */ ((ApiRouteType2) => {
16
- ApiRouteType2["SCHEDULED"] = "experimental-scheduled";
17
- ApiRouteType2["BACKGROUND"] = "experimental-background";
18
- return ApiRouteType2;
19
- })(ApiRouteType || {});
20
- async function getAPIRoutesConfigs(ctx) {
21
- const uniqueApiRoutes = /* @__PURE__ */ new Set();
22
- const functionsConfigManifestPath = join(
23
- ctx.publishDir,
24
- "server",
25
- "functions-config-manifest.json"
26
- );
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) {
45
- return [];
46
- }
47
- const appDir = ctx.resolveFromSiteDir(".");
48
- const pagesDir = join(appDir, "pages");
49
- const srcPagesDir = join(appDir, "src", "pages");
50
- const { pageExtensions } = ctx.requiredServerFiles.config;
51
- return Promise.all(
52
- [...uniqueApiRoutes].map(async (apiRoute) => {
53
- const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir], pageExtensions);
54
- const sharedFields = {
55
- apiRoute,
56
- filePath,
57
- config: {}
58
- };
59
- if (filePath) {
60
- const config = await extractConfigFromFile(filePath, appDir);
61
- return {
62
- ...sharedFields,
63
- config
64
- };
65
- }
66
- return sharedFields;
67
- })
68
- );
69
- }
70
- var SOURCE_FILE_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
71
- var getSourceFileForPage = (page, roots, pageExtensions = SOURCE_FILE_EXTENSIONS) => {
72
- for (const root of roots) {
73
- for (const extension of pageExtensions) {
74
- const file = join(root, `${page}.${extension}`);
75
- if (existsSync(file)) {
76
- return file;
77
- }
78
- const fileAtFolderIndex = join(root, page, `index.${extension}`);
79
- if (existsSync(fileAtFolderIndex)) {
80
- return fileAtFolderIndex;
81
- }
82
- }
83
- }
84
- };
85
- var findModuleFromBase = ({
86
- paths,
87
- candidates
88
- }) => {
89
- for (const candidate of candidates) {
90
- try {
91
- const modulePath = __require.resolve(candidate, { paths });
92
- if (modulePath) {
93
- return modulePath;
94
- }
95
- } catch {
96
- }
97
- }
98
- for (const candidate of candidates) {
99
- try {
100
- const modulePath = __require.resolve(candidate);
101
- if (modulePath) {
102
- return modulePath;
103
- }
104
- } catch {
105
- }
106
- }
107
- return null;
108
- };
109
- var extractConstValue;
110
- var parseModule;
111
- var extractConfigFromFile = async (apiFilePath, appDir) => {
112
- if (!apiFilePath || !existsSync(apiFilePath)) {
113
- return {};
114
- }
115
- const extractConstValueModulePath = findModuleFromBase({
116
- paths: [appDir],
117
- candidates: ["next/dist/build/analysis/extract-const-value"]
118
- });
119
- const parseModulePath = findModuleFromBase({
120
- paths: [appDir],
121
- candidates: ["next/dist/build/analysis/parse-module"]
122
- });
123
- if (!extractConstValueModulePath || !parseModulePath) {
124
- return {};
125
- }
126
- if (!extractConstValue && extractConstValueModulePath) {
127
- extractConstValue = __require(extractConstValueModulePath);
128
- }
129
- if (!parseModule && parseModulePath) {
130
- parseModule = __require(parseModulePath).parseModule;
131
- }
132
- const { extractExportedConstValue } = extractConstValue;
133
- const fileContent = await readFile(apiFilePath, "utf8");
134
- if (!fileContent.includes("config")) {
135
- return {};
136
- }
137
- const ast = await parseModule(apiFilePath, fileContent);
138
- try {
139
- return extractExportedConstValue(ast, "config");
140
- } catch {
141
- return {};
142
- }
143
- };
8
+ ApiRouteType,
9
+ getAPIRoutesConfigs
10
+ } from "../esm-chunks/chunk-ZENB67PD.js";
11
+ import "../esm-chunks/chunk-OEQOKJGE.js";
144
12
  export {
145
13
  ApiRouteType,
146
14
  getAPIRoutesConfigs
@@ -4,32 +4,11 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
+ import {
8
+ restoreBuildCache,
9
+ saveBuildCache
10
+ } from "../esm-chunks/chunk-72ZI2IVI.js";
7
11
  import "../esm-chunks/chunk-OEQOKJGE.js";
8
-
9
- // src/build/cache.ts
10
- import { existsSync } from "node:fs";
11
- import { rm } from "node:fs/promises";
12
- import { join } from "node:path";
13
- var saveBuildCache = async (ctx) => {
14
- const { cache } = ctx.utils;
15
- const cacheDir = join(ctx.publishDir, "cache");
16
- if (existsSync(cacheDir)) {
17
- await rm(join(cacheDir, "fetch-cache"), { recursive: true, force: true });
18
- await cache.save(cacheDir);
19
- console.log("Next.js cache saved");
20
- } else {
21
- console.log("No Next.js cache to save");
22
- }
23
- };
24
- var restoreBuildCache = async (ctx) => {
25
- const { cache } = ctx.utils;
26
- const cacheDir = join(ctx.publishDir, "cache");
27
- if (await cache.restore(cacheDir)) {
28
- console.log("Next.js cache restored");
29
- } else {
30
- console.log("No Next.js cache to restore");
31
- }
32
- };
33
12
  export {
34
13
  restoreBuildCache,
35
14
  saveBuildCache
@@ -5,296 +5,17 @@
5
5
  })();
6
6
 
7
7
  import {
8
- wrapTracer
9
- } from "../../esm-chunks/chunk-5QSXBV7L.js";
10
- import {
11
- init_esm,
12
- trace
13
- } from "../../esm-chunks/chunk-GNGHTHMQ.js";
14
- import {
15
- require_out
16
- } from "../../esm-chunks/chunk-KGYJQ2U2.js";
17
- import {
18
- require_semver
19
- } from "../../esm-chunks/chunk-APO262HE.js";
20
- import {
21
- __toESM
22
- } from "../../esm-chunks/chunk-OEQOKJGE.js";
23
-
24
- // src/build/content/prerendered.ts
25
- init_esm();
26
- import { existsSync } from "node:fs";
27
- import { mkdir, readFile, writeFile } from "node:fs/promises";
28
- import { join } from "node:path";
29
- var import_fast_glob = __toESM(require_out(), 1);
30
-
31
- // node_modules/yocto-queue/index.js
32
- var Node = class {
33
- value;
34
- next;
35
- constructor(value) {
36
- this.value = value;
37
- }
38
- };
39
- var Queue = class {
40
- #head;
41
- #tail;
42
- #size;
43
- constructor() {
44
- this.clear();
45
- }
46
- enqueue(value) {
47
- const node = new Node(value);
48
- if (this.#head) {
49
- this.#tail.next = node;
50
- this.#tail = node;
51
- } else {
52
- this.#head = node;
53
- this.#tail = node;
54
- }
55
- this.#size++;
56
- }
57
- dequeue() {
58
- const current = this.#head;
59
- if (!current) {
60
- return;
61
- }
62
- this.#head = this.#head.next;
63
- this.#size--;
64
- return current.value;
65
- }
66
- clear() {
67
- this.#head = void 0;
68
- this.#tail = void 0;
69
- this.#size = 0;
70
- }
71
- get size() {
72
- return this.#size;
73
- }
74
- *[Symbol.iterator]() {
75
- let current = this.#head;
76
- while (current) {
77
- yield current.value;
78
- current = current.next;
79
- }
80
- }
81
- };
82
-
83
- // node_modules/p-limit/index.js
84
- import { AsyncResource } from "async_hooks";
85
- function pLimit(concurrency) {
86
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
87
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
88
- }
89
- const queue = new Queue();
90
- let activeCount = 0;
91
- const next = () => {
92
- activeCount--;
93
- if (queue.size > 0) {
94
- queue.dequeue()();
95
- }
96
- };
97
- const run = async (function_, resolve, arguments_) => {
98
- activeCount++;
99
- const result = (async () => function_(...arguments_))();
100
- resolve(result);
101
- try {
102
- await result;
103
- } catch {
104
- }
105
- next();
106
- };
107
- const enqueue = (function_, resolve, arguments_) => {
108
- queue.enqueue(
109
- AsyncResource.bind(run.bind(void 0, function_, resolve, arguments_))
110
- );
111
- (async () => {
112
- await Promise.resolve();
113
- if (activeCount < concurrency && queue.size > 0) {
114
- queue.dequeue()();
115
- }
116
- })();
117
- };
118
- const generator = (function_, ...arguments_) => new Promise((resolve) => {
119
- enqueue(function_, resolve, arguments_);
120
- });
121
- Object.defineProperties(generator, {
122
- activeCount: {
123
- get: () => activeCount
124
- },
125
- pendingCount: {
126
- get: () => queue.size
127
- },
128
- clearQueue: {
129
- value() {
130
- queue.clear();
131
- }
132
- }
133
- });
134
- return generator;
135
- }
136
-
137
- // src/build/content/prerendered.ts
138
- var import_semver = __toESM(require_semver(), 1);
139
- import { encodeBlobKey } from "../../shared/blobkey.js";
140
- import { verifyNetlifyForms } from "../verification.js";
141
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
142
- var writeCacheEntry = async (route, value, lastModified, ctx) => {
143
- const path = join(ctx.blobDir, await encodeBlobKey(route));
144
- const entry = JSON.stringify({
145
- lastModified,
146
- value
147
- });
148
- await writeFile(path, entry, "utf-8");
149
- };
150
- var routeToFilePath = (path) => {
151
- if (path === "/") {
152
- return "/index";
153
- }
154
- if (path.startsWith("/")) {
155
- return path;
156
- }
157
- return `/${path}`;
158
- };
159
- var buildPagesCacheValue = async (path, shouldUseEnumKind, shouldSkipJson = false) => ({
160
- kind: shouldUseEnumKind ? "PAGES" : "PAGE",
161
- html: await readFile(`${path}.html`, "utf-8"),
162
- pageData: shouldSkipJson ? {} : JSON.parse(await readFile(`${path}.json`, "utf-8")),
163
- headers: void 0,
164
- status: void 0
165
- });
166
- var buildAppCacheValue = async (path, shouldUseAppPageKind) => {
167
- const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8"));
168
- const html = await readFile(`${path}.html`, "utf-8");
169
- if (shouldUseAppPageKind) {
170
- return {
171
- kind: "APP_PAGE",
172
- html,
173
- rscData: await readFile(`${path}.rsc`, "base64").catch(
174
- () => readFile(`${path}.prefetch.rsc`, "base64")
175
- ),
176
- ...meta
177
- };
178
- }
179
- const rsc = await readFile(`${path}.rsc`, "utf-8").catch(
180
- () => readFile(`${path}.prefetch.rsc`, "utf-8")
181
- );
182
- if (!meta.status && rsc.includes("NEXT_NOT_FOUND") && !meta.headers["x-next-cache-tags"].includes("/@")) {
183
- meta.status = 404;
184
- }
185
- return {
186
- kind: "PAGE",
187
- html,
188
- pageData: rsc,
189
- ...meta
190
- };
191
- };
192
- var buildRouteCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind) => ({
193
- kind: shouldUseEnumKind ? "APP_ROUTE" : "ROUTE",
194
- body: await readFile(`${path}.body`, "base64"),
195
- ...JSON.parse(await readFile(`${path}.meta`, "utf-8")),
196
- revalidate: initialRevalidateSeconds
197
- });
198
- var buildFetchCacheValue = async (path) => ({
199
- kind: "FETCH",
200
- ...JSON.parse(await readFile(path, "utf-8"))
201
- });
202
- var copyPrerenderedContent = async (ctx) => {
203
- return tracer.withActiveSpan("copyPrerenderedContent", async () => {
204
- try {
205
- await mkdir(ctx.blobDir, { recursive: true });
206
- const manifest = await ctx.getPrerenderManifest();
207
- const limitConcurrentPrerenderContentHandling = pLimit(10);
208
- const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", {
209
- includePrerelease: true
210
- }) : false;
211
- const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0", {
212
- includePrerelease: true
213
- }) : false;
214
- await Promise.all([
215
- ...Object.entries(manifest.routes).map(
216
- ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
217
- const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
218
- const key = routeToFilePath(route);
219
- let value;
220
- switch (true) {
221
- // Parallel route default layout has no prerendered page
222
- case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
223
- return;
224
- case meta.dataRoute?.endsWith(".json"):
225
- if (manifest.notFoundRoutes.includes(route)) {
226
- return;
227
- }
228
- value = await buildPagesCacheValue(
229
- join(ctx.publishDir, "server/pages", key),
230
- shouldUseEnumKind
231
- );
232
- break;
233
- case meta.dataRoute?.endsWith(".rsc"):
234
- value = await buildAppCacheValue(
235
- join(ctx.publishDir, "server/app", key),
236
- shouldUseAppPageKind
237
- );
238
- break;
239
- case meta.dataRoute === null:
240
- value = await buildRouteCacheValue(
241
- join(ctx.publishDir, "server/app", key),
242
- meta.initialRevalidateSeconds,
243
- shouldUseEnumKind
244
- );
245
- break;
246
- default:
247
- throw new Error(`Unrecognized content: ${route}`);
248
- }
249
- if (value.kind === "PAGE" || value.kind === "PAGES" || value.kind === "APP_PAGE") {
250
- verifyNetlifyForms(ctx, value.html);
251
- }
252
- await writeCacheEntry(key, value, lastModified, ctx);
253
- })
254
- ),
255
- ...ctx.getFallbacks(manifest).map(async (route) => {
256
- const key = routeToFilePath(route);
257
- const value = await buildPagesCacheValue(
258
- join(ctx.publishDir, "server/pages", key),
259
- shouldUseEnumKind,
260
- true
261
- // there is no corresponding json file for fallback, so we are skipping it for this entry
262
- );
263
- await writeCacheEntry(key, value, Date.now(), ctx);
264
- })
265
- ]);
266
- if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
267
- const lastModified = Date.now();
268
- const key = "/404";
269
- const value = await buildAppCacheValue(
270
- join(ctx.publishDir, "server/app/_not-found"),
271
- shouldUseAppPageKind
272
- );
273
- await writeCacheEntry(key, value, lastModified, ctx);
274
- }
275
- } catch (error) {
276
- ctx.failBuild("Failed assembling prerendered content for upload", error);
277
- }
278
- });
279
- };
280
- var copyFetchContent = async (ctx) => {
281
- try {
282
- const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
283
- cwd: join(ctx.publishDir, "cache/fetch-cache"),
284
- extglob: true
285
- });
286
- await Promise.all(
287
- paths.map(async (key) => {
288
- const lastModified = Date.now() - 31536e6;
289
- const path = join(ctx.publishDir, "cache/fetch-cache", key);
290
- const value = await buildFetchCacheValue(path);
291
- await writeCacheEntry(key, value, lastModified, ctx);
292
- })
293
- );
294
- } catch (error) {
295
- ctx.failBuild("Failed assembling fetch content for upload", error);
296
- }
297
- };
8
+ copyFetchContent,
9
+ copyPrerenderedContent
10
+ } from "../../esm-chunks/chunk-BVYZSEV6.js";
11
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
12
+ import "../../esm-chunks/chunk-5QSXBV7L.js";
13
+ import "../../esm-chunks/chunk-GNGHTHMQ.js";
14
+ import "../../esm-chunks/chunk-ZSVHJNNY.js";
15
+ import "../../esm-chunks/chunk-KGYJQ2U2.js";
16
+ import "../../esm-chunks/chunk-ZENB67PD.js";
17
+ import "../../esm-chunks/chunk-APO262HE.js";
18
+ import "../../esm-chunks/chunk-OEQOKJGE.js";
298
19
  export {
299
20
  copyFetchContent,
300
21
  copyPrerenderedContent