@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
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2023 Netlify <team@netlify.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -5,10 +5,142 @@
5
5
  })();
6
6
 
7
7
  import {
8
- ApiRouteType,
9
- getAPIRoutesConfigs
10
- } from "../esm-chunks/chunk-ZENB67PD.js";
11
- import "../esm-chunks/chunk-OEQOKJGE.js";
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
+ };
12
144
  export {
13
145
  ApiRouteType,
14
146
  getAPIRoutesConfigs
@@ -4,11 +4,32 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
- import {
8
- restoreBuildCache,
9
- saveBuildCache
10
- } from "../esm-chunks/chunk-72ZI2IVI.js";
11
7
  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
+ };
12
33
  export {
13
34
  restoreBuildCache,
14
35
  saveBuildCache
@@ -5,17 +5,299 @@
5
5
  })();
6
6
 
7
7
  import {
8
- copyFetchContent,
9
- copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-DLBTTDNJ.js";
11
- import "../../esm-chunks/chunk-5QSXBV7L.js";
12
- import "../../esm-chunks/chunk-GNGHTHMQ.js";
13
- import "../../esm-chunks/chunk-ZSVHJNNY.js";
14
- import "../../esm-chunks/chunk-KGYJQ2U2.js";
15
- import "../../esm-chunks/chunk-ZENB67PD.js";
16
- import "../../esm-chunks/chunk-APO262HE.js";
17
- import "../../esm-chunks/chunk-TYCYFZ22.js";
18
- import "../../esm-chunks/chunk-OEQOKJGE.js";
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, initialRevalidateSeconds, 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
+ revalidate: initialRevalidateSeconds
166
+ });
167
+ var buildAppCacheValue = async (path, shouldUseAppPageKind) => {
168
+ const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8"));
169
+ const html = await readFile(`${path}.html`, "utf-8");
170
+ if (shouldUseAppPageKind) {
171
+ return {
172
+ kind: "APP_PAGE",
173
+ html,
174
+ rscData: await readFile(`${path}.rsc`, "base64").catch(
175
+ () => readFile(`${path}.prefetch.rsc`, "base64")
176
+ ),
177
+ ...meta
178
+ };
179
+ }
180
+ const rsc = await readFile(`${path}.rsc`, "utf-8").catch(
181
+ () => readFile(`${path}.prefetch.rsc`, "utf-8")
182
+ );
183
+ if (!meta.status && rsc.includes("NEXT_NOT_FOUND") && !meta.headers["x-next-cache-tags"].includes("/@")) {
184
+ meta.status = 404;
185
+ }
186
+ return {
187
+ kind: "PAGE",
188
+ html,
189
+ pageData: rsc,
190
+ ...meta
191
+ };
192
+ };
193
+ var buildRouteCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind) => ({
194
+ kind: shouldUseEnumKind ? "APP_ROUTE" : "ROUTE",
195
+ body: await readFile(`${path}.body`, "base64"),
196
+ ...JSON.parse(await readFile(`${path}.meta`, "utf-8")),
197
+ revalidate: initialRevalidateSeconds
198
+ });
199
+ var buildFetchCacheValue = async (path) => ({
200
+ kind: "FETCH",
201
+ ...JSON.parse(await readFile(path, "utf-8"))
202
+ });
203
+ var copyPrerenderedContent = async (ctx) => {
204
+ return tracer.withActiveSpan("copyPrerenderedContent", async () => {
205
+ try {
206
+ await mkdir(ctx.blobDir, { recursive: true });
207
+ const manifest = await ctx.getPrerenderManifest();
208
+ const limitConcurrentPrerenderContentHandling = pLimit(10);
209
+ const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", {
210
+ includePrerelease: true
211
+ }) : false;
212
+ const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0", {
213
+ includePrerelease: true
214
+ }) : false;
215
+ await Promise.all([
216
+ ...Object.entries(manifest.routes).map(
217
+ ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
218
+ const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
219
+ const key = routeToFilePath(route);
220
+ let value;
221
+ switch (true) {
222
+ // Parallel route default layout has no prerendered page
223
+ case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
224
+ return;
225
+ case meta.dataRoute?.endsWith(".json"):
226
+ if (manifest.notFoundRoutes.includes(route)) {
227
+ return;
228
+ }
229
+ value = await buildPagesCacheValue(
230
+ join(ctx.publishDir, "server/pages", key),
231
+ meta.initialRevalidateSeconds,
232
+ shouldUseEnumKind
233
+ );
234
+ break;
235
+ case meta.dataRoute?.endsWith(".rsc"):
236
+ value = await buildAppCacheValue(
237
+ join(ctx.publishDir, "server/app", key),
238
+ shouldUseAppPageKind
239
+ );
240
+ break;
241
+ case meta.dataRoute === null:
242
+ value = await buildRouteCacheValue(
243
+ join(ctx.publishDir, "server/app", key),
244
+ meta.initialRevalidateSeconds,
245
+ shouldUseEnumKind
246
+ );
247
+ break;
248
+ default:
249
+ throw new Error(`Unrecognized content: ${route}`);
250
+ }
251
+ if (value.kind === "PAGE" || value.kind === "PAGES" || value.kind === "APP_PAGE") {
252
+ verifyNetlifyForms(ctx, value.html);
253
+ }
254
+ await writeCacheEntry(key, value, lastModified, ctx);
255
+ })
256
+ ),
257
+ ...ctx.getFallbacks(manifest).map(async (route) => {
258
+ const key = routeToFilePath(route);
259
+ const value = await buildPagesCacheValue(
260
+ join(ctx.publishDir, "server/pages", key),
261
+ void 0,
262
+ shouldUseEnumKind,
263
+ true
264
+ // there is no corresponding json file for fallback, so we are skipping it for this entry
265
+ );
266
+ await writeCacheEntry(key, value, Date.now(), ctx);
267
+ })
268
+ ]);
269
+ if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
270
+ const lastModified = Date.now();
271
+ const key = "/404";
272
+ const value = await buildAppCacheValue(
273
+ join(ctx.publishDir, "server/app/_not-found"),
274
+ shouldUseAppPageKind
275
+ );
276
+ await writeCacheEntry(key, value, lastModified, ctx);
277
+ }
278
+ } catch (error) {
279
+ ctx.failBuild("Failed assembling prerendered content for upload", error);
280
+ }
281
+ });
282
+ };
283
+ var copyFetchContent = async (ctx) => {
284
+ try {
285
+ const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
286
+ cwd: join(ctx.publishDir, "cache/fetch-cache"),
287
+ extglob: true
288
+ });
289
+ await Promise.all(
290
+ paths.map(async (key) => {
291
+ const lastModified = Date.now() - 31536e6;
292
+ const path = join(ctx.publishDir, "cache/fetch-cache", key);
293
+ const value = await buildFetchCacheValue(path);
294
+ await writeCacheEntry(key, value, lastModified, ctx);
295
+ })
296
+ );
297
+ } catch (error) {
298
+ ctx.failBuild("Failed assembling fetch content for upload", error);
299
+ }
300
+ };
19
301
  export {
20
302
  copyFetchContent,
21
303
  copyPrerenderedContent