@netlify/plugin-nextjs 5.8.0 → 5.9.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.
Files changed (47) 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 -272
  5. package/dist/build/content/server.js +11 -219
  6. package/dist/build/content/static.js +14 -97
  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 -266
  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-BFYMHE3E.js +548 -0
  18. package/dist/esm-chunks/chunk-BVYZSEV6.js +306 -0
  19. package/dist/esm-chunks/chunk-DLVROEVU.js +144 -0
  20. package/dist/esm-chunks/chunk-GFYWJNQR.js +305 -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-4GFWM3PF.js → package-LCNINN36.js} +8 -7
  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 +1604 -18
  44. package/dist/run/regional-blob-store.cjs +1 -1
  45. package/dist/run/revalidate.js +3 -24
  46. package/dist/shared/blobkey.js +3 -15
  47. package/package.json +4 -4
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,278 +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) => path === "/" ? "/index" : path;
151
- var buildPagesCacheValue = async (path, shouldUseEnumKind) => ({
152
- kind: shouldUseEnumKind ? "PAGES" : "PAGE",
153
- html: await readFile(`${path}.html`, "utf-8"),
154
- pageData: JSON.parse(await readFile(`${path}.json`, "utf-8")),
155
- headers: void 0,
156
- status: void 0
157
- });
158
- var buildAppCacheValue = async (path, shouldUseAppPageKind) => {
159
- const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8"));
160
- const html = await readFile(`${path}.html`, "utf-8");
161
- if (shouldUseAppPageKind) {
162
- return {
163
- kind: "APP_PAGE",
164
- html,
165
- rscData: await readFile(`${path}.rsc`, "base64").catch(
166
- () => readFile(`${path}.prefetch.rsc`, "base64")
167
- ),
168
- ...meta
169
- };
170
- }
171
- const rsc = await readFile(`${path}.rsc`, "utf-8").catch(
172
- () => readFile(`${path}.prefetch.rsc`, "utf-8")
173
- );
174
- if (!meta.status && rsc.includes("NEXT_NOT_FOUND") && !meta.headers["x-next-cache-tags"].includes("/@")) {
175
- meta.status = 404;
176
- }
177
- return {
178
- kind: "PAGE",
179
- html,
180
- pageData: rsc,
181
- ...meta
182
- };
183
- };
184
- var buildRouteCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind) => ({
185
- kind: shouldUseEnumKind ? "APP_ROUTE" : "ROUTE",
186
- body: await readFile(`${path}.body`, "base64"),
187
- ...JSON.parse(await readFile(`${path}.meta`, "utf-8")),
188
- revalidate: initialRevalidateSeconds
189
- });
190
- var buildFetchCacheValue = async (path) => ({
191
- kind: "FETCH",
192
- ...JSON.parse(await readFile(path, "utf-8"))
193
- });
194
- var copyPrerenderedContent = async (ctx) => {
195
- return tracer.withActiveSpan("copyPrerenderedContent", async () => {
196
- try {
197
- await mkdir(ctx.blobDir, { recursive: true });
198
- const manifest = await ctx.getPrerenderManifest();
199
- const limitConcurrentPrerenderContentHandling = pLimit(10);
200
- const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", {
201
- includePrerelease: true
202
- }) : false;
203
- const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0", {
204
- includePrerelease: true
205
- }) : false;
206
- await Promise.all(
207
- Object.entries(manifest.routes).map(
208
- ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
209
- const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
210
- const key = routeToFilePath(route);
211
- let value;
212
- switch (true) {
213
- // Parallel route default layout has no prerendered page
214
- case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
215
- return;
216
- case meta.dataRoute?.endsWith(".json"):
217
- if (manifest.notFoundRoutes.includes(route)) {
218
- return;
219
- }
220
- value = await buildPagesCacheValue(
221
- join(ctx.publishDir, "server/pages", key),
222
- shouldUseEnumKind
223
- );
224
- break;
225
- case meta.dataRoute?.endsWith(".rsc"):
226
- value = await buildAppCacheValue(
227
- join(ctx.publishDir, "server/app", key),
228
- shouldUseAppPageKind
229
- );
230
- break;
231
- case meta.dataRoute === null:
232
- value = await buildRouteCacheValue(
233
- join(ctx.publishDir, "server/app", key),
234
- meta.initialRevalidateSeconds,
235
- shouldUseEnumKind
236
- );
237
- break;
238
- default:
239
- throw new Error(`Unrecognized content: ${route}`);
240
- }
241
- if (value.kind === "PAGE" || value.kind === "PAGES" || value.kind === "APP_PAGE") {
242
- verifyNetlifyForms(ctx, value.html);
243
- }
244
- await writeCacheEntry(key, value, lastModified, ctx);
245
- })
246
- )
247
- );
248
- if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
249
- const lastModified = Date.now();
250
- const key = "/404";
251
- const value = await buildAppCacheValue(
252
- join(ctx.publishDir, "server/app/_not-found"),
253
- shouldUseAppPageKind
254
- );
255
- await writeCacheEntry(key, value, lastModified, ctx);
256
- }
257
- } catch (error) {
258
- ctx.failBuild("Failed assembling prerendered content for upload", error);
259
- }
260
- });
261
- };
262
- var copyFetchContent = async (ctx) => {
263
- try {
264
- const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
265
- cwd: join(ctx.publishDir, "cache/fetch-cache"),
266
- extglob: true
267
- });
268
- await Promise.all(
269
- paths.map(async (key) => {
270
- const lastModified = Date.now() - 31536e6;
271
- const path = join(ctx.publishDir, "cache/fetch-cache", key);
272
- const value = await buildFetchCacheValue(path);
273
- await writeCacheEntry(key, value, lastModified, ctx);
274
- })
275
- );
276
- } catch (error) {
277
- ctx.failBuild("Failed assembling fetch content for upload", error);
278
- }
279
- };
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";
280
19
  export {
281
20
  copyFetchContent,
282
21
  copyPrerenderedContent