@netlify/plugin-nextjs 5.10.0 → 5.10.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.
Files changed (48) hide show
  1. package/LICENSE +22 -0
  2. package/dist/build/advanced-api-routes.js +136 -4
  3. package/dist/build/cache.js +25 -4
  4. package/dist/build/content/prerendered.js +293 -11
  5. package/dist/build/content/server.js +219 -11
  6. package/dist/build/content/static.js +112 -15
  7. package/dist/build/functions/edge.js +540 -7
  8. package/dist/build/functions/server.js +130 -11
  9. package/dist/build/image-cdn.js +1599 -3
  10. package/dist/build/plugin-context.js +292 -6
  11. package/dist/build/verification.js +104 -9
  12. package/dist/esm-chunks/{package-F536DQ6H.js → package-7HACW4PO.js} +11 -10
  13. package/dist/index.js +19 -40
  14. package/dist/run/config.js +6 -7
  15. package/dist/run/constants.js +7 -5
  16. package/dist/run/handlers/cache.cjs +93 -1713
  17. package/dist/run/handlers/request-context.cjs +10 -3
  18. package/dist/run/handlers/server.js +14 -34
  19. package/dist/run/handlers/tracer.cjs +17 -116
  20. package/dist/run/handlers/tracing.js +2 -4
  21. package/dist/run/handlers/wait-until.cjs +2 -116
  22. package/dist/run/headers.js +183 -10
  23. package/dist/run/next.cjs +10 -1625
  24. package/dist/run/revalidate.js +24 -3
  25. package/dist/run/{regional-blob-store.cjs → storage/regional-blob-store.cjs} +44 -8
  26. package/dist/run/storage/request-scoped-in-memory-cache.cjs +1475 -0
  27. package/dist/run/storage/storage.cjs +84 -0
  28. package/dist/shared/blob-types.cjs +37 -0
  29. package/dist/shared/blobkey.js +15 -3
  30. package/package.json +1 -1
  31. package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
  32. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  33. package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
  34. package/dist/esm-chunks/chunk-DLBTTDNJ.js +0 -309
  35. package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
  36. package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
  37. package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
  38. package/dist/esm-chunks/chunk-K4RDUZYO.js +0 -609
  39. package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
  40. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  41. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  42. package/dist/esm-chunks/chunk-VTKZZRGT.js +0 -132
  43. package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
  44. package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
  45. package/dist/esm-chunks/chunk-YMNWVS6T.js +0 -218
  46. package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
  47. package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
  48. package/dist/esm-chunks/next-7JK63CHT.js +0 -567
@@ -1,309 +0,0 @@
1
-
2
- var require = await (async () => {
3
- var { createRequire } = await import("node:module");
4
- return createRequire(import.meta.url);
5
- })();
6
-
7
- import {
8
- wrapTracer
9
- } from "./chunk-5QSXBV7L.js";
10
- import {
11
- init_esm,
12
- trace
13
- } from "./chunk-GNGHTHMQ.js";
14
- import {
15
- verifyNetlifyForms
16
- } from "./chunk-ZSVHJNNY.js";
17
- import {
18
- require_out
19
- } from "./chunk-KGYJQ2U2.js";
20
- import {
21
- require_semver
22
- } from "./chunk-APO262HE.js";
23
- import {
24
- encodeBlobKey
25
- } from "./chunk-TYCYFZ22.js";
26
- import {
27
- __toESM
28
- } from "./chunk-OEQOKJGE.js";
29
-
30
- // src/build/content/prerendered.ts
31
- init_esm();
32
- import { existsSync } from "node:fs";
33
- import { mkdir, readFile, writeFile } from "node:fs/promises";
34
- import { join } from "node:path";
35
- var import_fast_glob = __toESM(require_out(), 1);
36
-
37
- // node_modules/yocto-queue/index.js
38
- var Node = class {
39
- value;
40
- next;
41
- constructor(value) {
42
- this.value = value;
43
- }
44
- };
45
- var Queue = class {
46
- #head;
47
- #tail;
48
- #size;
49
- constructor() {
50
- this.clear();
51
- }
52
- enqueue(value) {
53
- const node = new Node(value);
54
- if (this.#head) {
55
- this.#tail.next = node;
56
- this.#tail = node;
57
- } else {
58
- this.#head = node;
59
- this.#tail = node;
60
- }
61
- this.#size++;
62
- }
63
- dequeue() {
64
- const current = this.#head;
65
- if (!current) {
66
- return;
67
- }
68
- this.#head = this.#head.next;
69
- this.#size--;
70
- return current.value;
71
- }
72
- clear() {
73
- this.#head = void 0;
74
- this.#tail = void 0;
75
- this.#size = 0;
76
- }
77
- get size() {
78
- return this.#size;
79
- }
80
- *[Symbol.iterator]() {
81
- let current = this.#head;
82
- while (current) {
83
- yield current.value;
84
- current = current.next;
85
- }
86
- }
87
- };
88
-
89
- // node_modules/p-limit/index.js
90
- import { AsyncResource } from "async_hooks";
91
- function pLimit(concurrency) {
92
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
93
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
94
- }
95
- const queue = new Queue();
96
- let activeCount = 0;
97
- const next = () => {
98
- activeCount--;
99
- if (queue.size > 0) {
100
- queue.dequeue()();
101
- }
102
- };
103
- const run = async (function_, resolve, arguments_) => {
104
- activeCount++;
105
- const result = (async () => function_(...arguments_))();
106
- resolve(result);
107
- try {
108
- await result;
109
- } catch {
110
- }
111
- next();
112
- };
113
- const enqueue = (function_, resolve, arguments_) => {
114
- queue.enqueue(
115
- AsyncResource.bind(run.bind(void 0, function_, resolve, arguments_))
116
- );
117
- (async () => {
118
- await Promise.resolve();
119
- if (activeCount < concurrency && queue.size > 0) {
120
- queue.dequeue()();
121
- }
122
- })();
123
- };
124
- const generator = (function_, ...arguments_) => new Promise((resolve) => {
125
- enqueue(function_, resolve, arguments_);
126
- });
127
- Object.defineProperties(generator, {
128
- activeCount: {
129
- get: () => activeCount
130
- },
131
- pendingCount: {
132
- get: () => queue.size
133
- },
134
- clearQueue: {
135
- value() {
136
- queue.clear();
137
- }
138
- }
139
- });
140
- return generator;
141
- }
142
-
143
- // src/build/content/prerendered.ts
144
- var import_semver = __toESM(require_semver(), 1);
145
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
146
- var writeCacheEntry = async (route, value, lastModified, ctx) => {
147
- const path = join(ctx.blobDir, await encodeBlobKey(route));
148
- const entry = JSON.stringify({
149
- lastModified,
150
- value
151
- });
152
- await writeFile(path, entry, "utf-8");
153
- };
154
- var routeToFilePath = (path) => {
155
- if (path === "/") {
156
- return "/index";
157
- }
158
- if (path.startsWith("/")) {
159
- return path;
160
- }
161
- return `/${path}`;
162
- };
163
- var buildPagesCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind, shouldSkipJson = false) => ({
164
- kind: shouldUseEnumKind ? "PAGES" : "PAGE",
165
- html: await readFile(`${path}.html`, "utf-8"),
166
- pageData: shouldSkipJson ? {} : JSON.parse(await readFile(`${path}.json`, "utf-8")),
167
- headers: void 0,
168
- status: void 0,
169
- revalidate: initialRevalidateSeconds
170
- });
171
- var buildAppCacheValue = async (path, shouldUseAppPageKind) => {
172
- const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8"));
173
- const html = await readFile(`${path}.html`, "utf-8");
174
- if (shouldUseAppPageKind) {
175
- return {
176
- kind: "APP_PAGE",
177
- html,
178
- rscData: await readFile(`${path}.rsc`, "base64").catch(
179
- () => readFile(`${path}.prefetch.rsc`, "base64")
180
- ),
181
- ...meta
182
- };
183
- }
184
- const rsc = await readFile(`${path}.rsc`, "utf-8").catch(
185
- () => readFile(`${path}.prefetch.rsc`, "utf-8")
186
- );
187
- if (!meta.status && rsc.includes("NEXT_NOT_FOUND") && !meta.headers["x-next-cache-tags"].includes("/@")) {
188
- meta.status = 404;
189
- }
190
- return {
191
- kind: "PAGE",
192
- html,
193
- pageData: rsc,
194
- ...meta
195
- };
196
- };
197
- var buildRouteCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind) => ({
198
- kind: shouldUseEnumKind ? "APP_ROUTE" : "ROUTE",
199
- body: await readFile(`${path}.body`, "base64"),
200
- ...JSON.parse(await readFile(`${path}.meta`, "utf-8")),
201
- revalidate: initialRevalidateSeconds
202
- });
203
- var buildFetchCacheValue = async (path) => ({
204
- kind: "FETCH",
205
- ...JSON.parse(await readFile(path, "utf-8"))
206
- });
207
- var copyPrerenderedContent = async (ctx) => {
208
- return tracer.withActiveSpan("copyPrerenderedContent", async () => {
209
- try {
210
- await mkdir(ctx.blobDir, { recursive: true });
211
- const manifest = await ctx.getPrerenderManifest();
212
- const limitConcurrentPrerenderContentHandling = pLimit(10);
213
- const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", {
214
- includePrerelease: true
215
- }) : false;
216
- const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0", {
217
- includePrerelease: true
218
- }) : false;
219
- await Promise.all([
220
- ...Object.entries(manifest.routes).map(
221
- ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
222
- const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
223
- const key = routeToFilePath(route);
224
- let value;
225
- switch (true) {
226
- // Parallel route default layout has no prerendered page
227
- case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
228
- return;
229
- case meta.dataRoute?.endsWith(".json"):
230
- if (manifest.notFoundRoutes.includes(route)) {
231
- return;
232
- }
233
- value = await buildPagesCacheValue(
234
- join(ctx.publishDir, "server/pages", key),
235
- meta.initialRevalidateSeconds,
236
- shouldUseEnumKind
237
- );
238
- break;
239
- case meta.dataRoute?.endsWith(".rsc"):
240
- value = await buildAppCacheValue(
241
- join(ctx.publishDir, "server/app", key),
242
- shouldUseAppPageKind
243
- );
244
- break;
245
- case meta.dataRoute === null:
246
- value = await buildRouteCacheValue(
247
- join(ctx.publishDir, "server/app", key),
248
- meta.initialRevalidateSeconds,
249
- shouldUseEnumKind
250
- );
251
- break;
252
- default:
253
- throw new Error(`Unrecognized content: ${route}`);
254
- }
255
- if (value.kind === "PAGE" || value.kind === "PAGES" || value.kind === "APP_PAGE") {
256
- verifyNetlifyForms(ctx, value.html);
257
- }
258
- await writeCacheEntry(key, value, lastModified, ctx);
259
- })
260
- ),
261
- ...ctx.getFallbacks(manifest).map(async (route) => {
262
- const key = routeToFilePath(route);
263
- const value = await buildPagesCacheValue(
264
- join(ctx.publishDir, "server/pages", key),
265
- void 0,
266
- shouldUseEnumKind,
267
- true
268
- // there is no corresponding json file for fallback, so we are skipping it for this entry
269
- );
270
- await writeCacheEntry(key, value, Date.now(), ctx);
271
- })
272
- ]);
273
- if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
274
- const lastModified = Date.now();
275
- const key = "/404";
276
- const value = await buildAppCacheValue(
277
- join(ctx.publishDir, "server/app/_not-found"),
278
- shouldUseAppPageKind
279
- );
280
- await writeCacheEntry(key, value, lastModified, ctx);
281
- }
282
- } catch (error) {
283
- ctx.failBuild("Failed assembling prerendered content for upload", error);
284
- }
285
- });
286
- };
287
- var copyFetchContent = async (ctx) => {
288
- try {
289
- const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
290
- cwd: join(ctx.publishDir, "cache/fetch-cache"),
291
- extglob: true
292
- });
293
- await Promise.all(
294
- paths.map(async (key) => {
295
- const lastModified = Date.now() - 31536e6;
296
- const path = join(ctx.publishDir, "cache/fetch-cache", key);
297
- const value = await buildFetchCacheValue(path);
298
- await writeCacheEntry(key, value, lastModified, ctx);
299
- })
300
- );
301
- } catch (error) {
302
- ctx.failBuild("Failed assembling fetch content for upload", error);
303
- }
304
- };
305
-
306
- export {
307
- copyPrerenderedContent,
308
- copyFetchContent
309
- };
@@ -1,144 +0,0 @@
1
-
2
- var require = await (async () => {
3
- var { createRequire } = await import("node:module");
4
- return createRequire(import.meta.url);
5
- })();
6
-
7
- import {
8
- copyNextDependencies,
9
- copyNextServerCode,
10
- verifyHandlerDirStructure
11
- } from "./chunk-IJZEDP6B.js";
12
- import {
13
- wrapTracer
14
- } from "./chunk-5QSXBV7L.js";
15
- import {
16
- init_esm,
17
- trace
18
- } from "./chunk-GNGHTHMQ.js";
19
- import {
20
- SERVER_HANDLER_NAME
21
- } from "./chunk-GFYWJNQR.js";
22
- import {
23
- require_out
24
- } from "./chunk-KGYJQ2U2.js";
25
- import {
26
- __toESM
27
- } from "./chunk-OEQOKJGE.js";
28
-
29
- // src/build/functions/server.ts
30
- init_esm();
31
- import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
32
- import { join, relative } from "node:path";
33
- import { join as posixJoin } from "node:path/posix";
34
- var import_fast_glob = __toESM(require_out(), 1);
35
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
36
- var copyHandlerDependencies = async (ctx) => {
37
- await tracer.withActiveSpan("copyHandlerDependencies", async (span) => {
38
- const promises = [];
39
- const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
40
- includedFiles.push(
41
- posixJoin(ctx.relativeAppDir, ".env"),
42
- posixJoin(ctx.relativeAppDir, ".env.production"),
43
- posixJoin(ctx.relativeAppDir, ".env.local"),
44
- posixJoin(ctx.relativeAppDir, ".env.production.local")
45
- );
46
- span.setAttribute("next.includedFiles", includedFiles.join(","));
47
- const resolvedFiles = await Promise.all(
48
- includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
49
- );
50
- for (const filePath of resolvedFiles.flat()) {
51
- promises.push(
52
- cp(
53
- join(process.cwd(), filePath),
54
- // the serverHandlerDir is aware of the dist dir.
55
- // The distDir must not be the package path therefore we need to rely on the
56
- // serverHandlerDir instead of the serverHandlerRootDir
57
- // therefore we need to remove the package path from the filePath
58
- join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
59
- {
60
- recursive: true,
61
- force: true
62
- }
63
- )
64
- );
65
- }
66
- promises.push(
67
- writeFile(
68
- join(ctx.serverHandlerRuntimeModulesDir, "package.json"),
69
- JSON.stringify({ type: "module" })
70
- )
71
- );
72
- const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
73
- for (const filePath of fileList) {
74
- promises.push(
75
- cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerRuntimeModulesDir, filePath), {
76
- recursive: true,
77
- force: true
78
- })
79
- );
80
- }
81
- await Promise.all(promises);
82
- });
83
- };
84
- var writeHandlerManifest = async (ctx) => {
85
- await writeFile(
86
- join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.json`),
87
- JSON.stringify({
88
- config: {
89
- name: "Next.js Server Handler",
90
- generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
91
- nodeBundler: "none",
92
- // the folders can vary in monorepos based on the folder structure of the user so we have to glob all
93
- includedFiles: ["**"],
94
- includedFilesBasePath: ctx.serverHandlerRootDir
95
- },
96
- version: 1
97
- }),
98
- "utf-8"
99
- );
100
- };
101
- var applyTemplateVariables = (template, variables) => {
102
- return Object.entries(variables).reduce((acc, [key, value]) => {
103
- return acc.replaceAll(key, value);
104
- }, template);
105
- };
106
- var getHandlerFile = async (ctx) => {
107
- const templatesDir = join(ctx.pluginDir, "dist/build/templates");
108
- const templateVariables = {
109
- "{{useRegionalBlobs}}": ctx.useRegionalBlobs.toString()
110
- };
111
- if (ctx.relativeAppDir.length !== 0) {
112
- const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
113
- templateVariables["{{cwd}}"] = posixJoin(ctx.lambdaWorkingDirectory);
114
- templateVariables["{{nextServerHandler}}"] = posixJoin(ctx.nextServerHandler);
115
- return applyTemplateVariables(template, templateVariables);
116
- }
117
- return applyTemplateVariables(
118
- await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8"),
119
- templateVariables
120
- );
121
- };
122
- var writeHandlerFile = async (ctx) => {
123
- const handler = await getHandlerFile(ctx);
124
- await writeFile(join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.mjs`), handler);
125
- };
126
- var clearStaleServerHandlers = async (ctx) => {
127
- await rm(ctx.serverFunctionsDir, { recursive: true, force: true });
128
- };
129
- var createServerHandler = async (ctx) => {
130
- await tracer.withActiveSpan("createServerHandler", async () => {
131
- await mkdir(join(ctx.serverHandlerRuntimeModulesDir), { recursive: true });
132
- await copyNextServerCode(ctx);
133
- await copyNextDependencies(ctx);
134
- await copyHandlerDependencies(ctx);
135
- await writeHandlerManifest(ctx);
136
- await writeHandlerFile(ctx);
137
- await verifyHandlerDirStructure(ctx);
138
- });
139
- };
140
-
141
- export {
142
- clearStaleServerHandlers,
143
- createServerHandler
144
- };