@netlify/plugin-nextjs 5.8.1 → 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 (46) 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-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-AOKLDA5E.js → package-LCNINN36.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/package.json +4 -4
@@ -0,0 +1,122 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/run/handlers/request-context.cts
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+
11
+ // node_modules/@netlify/functions/dist/chunk-HYMERDCV.mjs
12
+ import { env } from "process";
13
+ var systemLogTag = "__nfSystemLog";
14
+ var serializeError = (error) => {
15
+ const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
16
+ return {
17
+ error: error.message,
18
+ error_cause: cause,
19
+ error_stack: error.stack
20
+ };
21
+ };
22
+ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
23
+ LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
24
+ LogLevel2[LogLevel2["Log"] = 2] = "Log";
25
+ LogLevel2[LogLevel2["Error"] = 3] = "Error";
26
+ return LogLevel2;
27
+ })(LogLevel || {});
28
+ var SystemLogger = class _SystemLogger {
29
+ fields;
30
+ logLevel;
31
+ constructor(fields = {}, logLevel = 2) {
32
+ this.fields = fields;
33
+ this.logLevel = logLevel;
34
+ }
35
+ doLog(logger, message) {
36
+ if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
37
+ return;
38
+ }
39
+ logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
40
+ }
41
+ log(message) {
42
+ if (this.logLevel > 2) {
43
+ return;
44
+ }
45
+ this.doLog(console.log, message);
46
+ }
47
+ debug(message) {
48
+ if (this.logLevel > 1) {
49
+ return;
50
+ }
51
+ this.doLog(console.debug, message);
52
+ }
53
+ error(message) {
54
+ if (this.logLevel > 3) {
55
+ return;
56
+ }
57
+ this.doLog(console.error, message);
58
+ }
59
+ withLogLevel(level) {
60
+ return new _SystemLogger(this.fields, level);
61
+ }
62
+ withFields(fields) {
63
+ return new _SystemLogger(
64
+ {
65
+ ...this.fields,
66
+ ...fields
67
+ },
68
+ this.logLevel
69
+ );
70
+ }
71
+ withError(error) {
72
+ const fields = error instanceof Error ? serializeError(error) : { error };
73
+ return this.withFields(fields);
74
+ }
75
+ };
76
+ var systemLogger = new SystemLogger();
77
+
78
+ // src/run/handlers/request-context.cts
79
+ function createRequestContext(request, context) {
80
+ const backgroundWorkPromises = [];
81
+ return {
82
+ captureServerTiming: request?.headers.has("x-next-debug-logging") ?? false,
83
+ trackBackgroundWork: (promise) => {
84
+ if (context?.waitUntil) {
85
+ context.waitUntil(promise);
86
+ } else {
87
+ backgroundWorkPromises.push(promise);
88
+ }
89
+ },
90
+ get backgroundWorkPromise() {
91
+ return Promise.allSettled(backgroundWorkPromises);
92
+ },
93
+ logger: systemLogger.withLogLevel(
94
+ request?.headers.has("x-nf-debug-logging") || request?.headers.has("x-next-debug-logging") ? LogLevel.Debug : LogLevel.Log
95
+ )
96
+ };
97
+ }
98
+ var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
99
+ var requestContextAsyncLocalStorage;
100
+ function getRequestContextAsyncLocalStorage() {
101
+ if (requestContextAsyncLocalStorage) {
102
+ return requestContextAsyncLocalStorage;
103
+ }
104
+ const extendedGlobalThis = globalThis;
105
+ if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
106
+ return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
107
+ }
108
+ const storage = new AsyncLocalStorage();
109
+ requestContextAsyncLocalStorage = storage;
110
+ extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
111
+ return storage;
112
+ }
113
+ var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
114
+ function getLogger() {
115
+ return getRequestContext()?.logger ?? systemLogger;
116
+ }
117
+
118
+ export {
119
+ createRequestContext,
120
+ getRequestContext,
121
+ getLogger
122
+ };
@@ -0,0 +1,25 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/shared/blobkey.ts
9
+ import { Buffer } from "node:buffer";
10
+ import { webcrypto as crypto } from "node:crypto";
11
+ var maxLength = 180;
12
+ async function encodeBlobKey(key) {
13
+ const buffer = Buffer.from(key);
14
+ const base64 = buffer.toString("base64url");
15
+ if (base64.length <= maxLength) {
16
+ return base64;
17
+ }
18
+ const digest = await crypto.subtle.digest("SHA-256", buffer);
19
+ const hash = Buffer.from(digest).toString("base64url");
20
+ return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
21
+ }
22
+
23
+ export {
24
+ encodeBlobKey
25
+ };
@@ -0,0 +1,19 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/run/constants.ts
9
+ import { resolve } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
12
+ var PLUGIN_DIR = resolve(`${MODULE_DIR}../../..`);
13
+ var RUN_CONFIG = "run-config.json";
14
+
15
+ export {
16
+ MODULE_DIR,
17
+ PLUGIN_DIR,
18
+ RUN_CONFIG
19
+ };
@@ -0,0 +1,34 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/run/revalidate.ts
9
+ import { isPromise } from "node:util/types";
10
+ function isRevalidateMethod(key, nextResponseField) {
11
+ return key === "revalidate" && typeof nextResponseField === "function";
12
+ }
13
+ var nextResponseProxy = (res, requestContext) => {
14
+ return new Proxy(res, {
15
+ get(target, key) {
16
+ const originalValue = Reflect.get(target, key);
17
+ if (isRevalidateMethod(key, originalValue)) {
18
+ return function newRevalidate(...args) {
19
+ requestContext.didPagesRouterOnDemandRevalidate = true;
20
+ const result = originalValue.apply(target, args);
21
+ if (result && isPromise(result)) {
22
+ requestContext.trackBackgroundWork(result);
23
+ }
24
+ return result;
25
+ };
26
+ }
27
+ return originalValue;
28
+ }
29
+ });
30
+ };
31
+
32
+ export {
33
+ nextResponseProxy
34
+ };
@@ -0,0 +1,148 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ __require
9
+ } from "./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
+ };
144
+
145
+ export {
146
+ ApiRouteType,
147
+ getAPIRoutesConfigs
148
+ };
@@ -0,0 +1,120 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+ import {
8
+ require_out
9
+ } from "./chunk-KGYJQ2U2.js";
10
+ import {
11
+ getAPIRoutesConfigs
12
+ } from "./chunk-ZENB67PD.js";
13
+ import {
14
+ require_semver
15
+ } from "./chunk-APO262HE.js";
16
+ import {
17
+ __toESM
18
+ } from "./chunk-OEQOKJGE.js";
19
+
20
+ // src/build/verification.ts
21
+ var import_fast_glob = __toESM(require_out(), 1);
22
+ var import_semver = __toESM(require_semver(), 1);
23
+ import { existsSync } from "node:fs";
24
+ import { readFile } from "node:fs/promises";
25
+ import { join } from "node:path";
26
+ var SUPPORTED_NEXT_VERSIONS = ">=13.5.0";
27
+ var verifications = /* @__PURE__ */ new Set();
28
+ function verifyPublishDir(ctx) {
29
+ if (!existsSync(ctx.publishDir)) {
30
+ ctx.failBuild(
31
+ `Your publish directory was not found at: ${ctx.publishDir}. Please check your build settings`
32
+ );
33
+ }
34
+ if (ctx.publishDir === ctx.resolveFromPackagePath("")) {
35
+ ctx.failBuild(
36
+ `Your publish directory cannot be the same as the base directory of your site. Please check your build settings`
37
+ );
38
+ }
39
+ try {
40
+ ctx.buildConfig;
41
+ } catch {
42
+ ctx.failBuild(
43
+ "Your publish directory does not contain expected Next.js build output. Please check your build settings"
44
+ );
45
+ }
46
+ if (ctx.buildConfig.output === "standalone" || ctx.buildConfig.output === void 0) {
47
+ if (!existsSync(join(ctx.publishDir, "BUILD_ID"))) {
48
+ ctx.failBuild(
49
+ "Your publish directory does not contain expected Next.js build output. Please check your build settings"
50
+ );
51
+ }
52
+ if (!existsSync(ctx.standaloneRootDir)) {
53
+ ctx.failBuild(
54
+ `Your publish directory does not contain expected Next.js build output. Please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`
55
+ );
56
+ }
57
+ if (ctx.nextVersion && !(0, import_semver.satisfies)(ctx.nextVersion, SUPPORTED_NEXT_VERSIONS, { includePrerelease: true })) {
58
+ ctx.failBuild(
59
+ `@netlify/plugin-nextjs@5 requires Next.js version ${SUPPORTED_NEXT_VERSIONS}, but found ${ctx.nextVersion}. Please upgrade your project's Next.js version.`
60
+ );
61
+ }
62
+ }
63
+ if (ctx.buildConfig.output === "export") {
64
+ if (!ctx.exportDetail?.success) {
65
+ ctx.failBuild(`Your export failed to build. Please check your build settings`);
66
+ }
67
+ if (!existsSync(ctx.exportDetail?.outDirectory)) {
68
+ ctx.failBuild(
69
+ `Your export directory was not found at: ${ctx.exportDetail?.outDirectory}. Please check your build settings`
70
+ );
71
+ }
72
+ }
73
+ }
74
+ async function verifyAdvancedAPIRoutes(ctx) {
75
+ const apiRoutesConfigs = await getAPIRoutesConfigs(ctx);
76
+ const unsupportedAPIRoutes = apiRoutesConfigs.filter((apiRouteConfig) => {
77
+ return apiRouteConfig.config.type === "experimental-background" /* BACKGROUND */ || apiRouteConfig.config.type === "experimental-scheduled" /* SCHEDULED */;
78
+ });
79
+ if (unsupportedAPIRoutes.length !== 0) {
80
+ ctx.failBuild(
81
+ `@netlify/plugin-nextjs@5 does not support advanced API routes. The following API routes should be migrated to Netlify background or scheduled functions:
82
+ ${unsupportedAPIRoutes.map((apiRouteConfig) => ` - ${apiRouteConfig.apiRoute} (type: "${apiRouteConfig.config.type}")`).join("\n")}
83
+
84
+ Refer to https://ntl.fyi/next-scheduled-bg-function-migration as migration example.`
85
+ );
86
+ }
87
+ }
88
+ var formDetectionRegex = /<form[^>]*?\s(netlify|data-netlify)[=>\s]/;
89
+ async function verifyNetlifyFormsWorkaround(ctx) {
90
+ const srcDir = ctx.resolveFromSiteDir("public");
91
+ const paths = await (0, import_fast_glob.glob)("**/*.html", {
92
+ cwd: srcDir,
93
+ dot: true
94
+ });
95
+ try {
96
+ for (const path of paths) {
97
+ const html = await readFile(join(srcDir, path), "utf-8");
98
+ if (formDetectionRegex.test(html)) {
99
+ verifications.add("netlifyFormsWorkaround");
100
+ return;
101
+ }
102
+ }
103
+ } catch (error) {
104
+ ctx.failBuild("Failed verifying public files", error);
105
+ }
106
+ }
107
+ function verifyNetlifyForms(ctx, html) {
108
+ if (process.env.NETLIFY_NEXT_VERIFY_FORMS !== "0" && process.env.NETLIFY_NEXT_VERIFY_FORMS?.toUpperCase() !== "FALSE" && !verifications.has("netlifyFormsWorkaround") && formDetectionRegex.test(html)) {
109
+ ctx.failBuild(
110
+ "@netlify/plugin-nextjs@5 requires migration steps to support Netlify Forms. Refer to https://ntl.fyi/next-runtime-forms-migration for migration example."
111
+ );
112
+ }
113
+ }
114
+
115
+ export {
116
+ verifyPublishDir,
117
+ verifyAdvancedAPIRoutes,
118
+ verifyNetlifyFormsWorkaround,
119
+ verifyNetlifyForms
120
+ };