@netlify/plugin-nextjs 5.1.2 → 5.2.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 (42) hide show
  1. package/dist/build/advanced-api-routes.js +121 -4
  2. package/dist/build/cache.js +25 -4
  3. package/dist/build/content/prerendered.js +234 -8
  4. package/dist/build/content/server.js +259 -14
  5. package/dist/build/content/static.js +96 -11
  6. package/dist/build/functions/edge.js +511 -5
  7. package/dist/build/functions/server.js +131 -12
  8. package/dist/build/image-cdn.js +1626 -3
  9. package/dist/build/plugin-context.js +236 -5
  10. package/dist/build/templates/handler-monorepo.tmpl.js +3 -0
  11. package/dist/build/templates/handler.tmpl.js +3 -0
  12. package/dist/build/verification.js +81 -8
  13. package/dist/esm-chunks/{package-RVJOBSMH.js → package-ZBRSUKN7.js} +5 -5
  14. package/dist/index.js +25 -36
  15. package/dist/run/config.js +25 -6
  16. package/dist/run/constants.js +7 -5
  17. package/dist/run/handlers/cache.cjs +6 -567
  18. package/dist/run/handlers/request-context.cjs +8 -1
  19. package/dist/run/handlers/server.js +20 -22
  20. package/dist/run/handlers/tracing.js +1 -1
  21. package/dist/run/headers.js +198 -8
  22. package/dist/run/next.cjs +49 -567
  23. package/dist/{esm-chunks/chunk-PMRBBOBY.js → run/regional-blob-store.cjs} +117 -263
  24. package/dist/run/revalidate.js +17 -3
  25. package/dist/run/systemlog.js +94 -3
  26. package/dist/shared/blobkey.js +15 -3
  27. package/package.json +1 -1
  28. package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
  29. package/dist/esm-chunks/chunk-4BNHE6TP.js +0 -278
  30. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  31. package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
  32. package/dist/esm-chunks/chunk-HESS57SH.js +0 -127
  33. package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
  34. package/dist/esm-chunks/chunk-K7BTUM7O.js +0 -97
  35. package/dist/esm-chunks/chunk-L6OM53B6.js +0 -238
  36. package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
  37. package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
  38. package/dist/esm-chunks/chunk-RL4K4CVH.js +0 -27
  39. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  40. package/dist/esm-chunks/chunk-UTQSBE5O.js +0 -524
  41. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  42. package/dist/esm-chunks/chunk-V2T6NUOM.js +0 -113
@@ -1,105 +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
- __commonJS,
9
- __require,
10
- __toESM
11
- } from "./chunk-5JVNISGM.js";
12
-
13
- // node_modules/@netlify/functions/dist/lib/system_logger.js
14
- var require_system_logger = __commonJS({
15
- "node_modules/@netlify/functions/dist/lib/system_logger.js"(exports) {
16
- "use strict";
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.systemLogger = exports.LogLevel = void 0;
19
- var process_1 = __require("process");
20
- var systemLogTag = "__nfSystemLog";
21
- var serializeError = (error) => {
22
- const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
23
- return {
24
- error: error.message,
25
- error_cause: cause,
26
- error_stack: error.stack
27
- };
28
- };
29
- var LogLevel2;
30
- (function(LogLevel3) {
31
- LogLevel3[LogLevel3["Debug"] = 1] = "Debug";
32
- LogLevel3[LogLevel3["Log"] = 2] = "Log";
33
- LogLevel3[LogLevel3["Error"] = 3] = "Error";
34
- })(LogLevel2 = exports.LogLevel || (exports.LogLevel = {}));
35
- var SystemLogger = class _SystemLogger {
36
- fields;
37
- logLevel;
38
- constructor(fields = {}, logLevel = LogLevel2.Log) {
39
- this.fields = fields;
40
- this.logLevel = logLevel;
41
- }
42
- doLog(logger, message) {
43
- if (process_1.env.NETLIFY_DEV && !process_1.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
44
- return;
45
- }
46
- logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
47
- }
48
- log(message) {
49
- if (this.logLevel > LogLevel2.Log) {
50
- return;
51
- }
52
- this.doLog(console.log, message);
53
- }
54
- debug(message) {
55
- if (this.logLevel > LogLevel2.Debug) {
56
- return;
57
- }
58
- this.doLog(console.debug, message);
59
- }
60
- error(message) {
61
- if (this.logLevel > LogLevel2.Error) {
62
- return;
63
- }
64
- this.doLog(console.error, message);
65
- }
66
- withLogLevel(level) {
67
- return new _SystemLogger(this.fields, level);
68
- }
69
- withFields(fields) {
70
- return new _SystemLogger({
71
- ...this.fields,
72
- ...fields
73
- }, this.logLevel);
74
- }
75
- withError(error) {
76
- const fields = error instanceof Error ? serializeError(error) : { error };
77
- return this.withFields(fields);
78
- }
79
- };
80
- exports.systemLogger = new SystemLogger();
81
- }
82
- });
83
-
84
- // node_modules/@netlify/functions/dist/internal.js
85
- var require_internal = __commonJS({
86
- "node_modules/@netlify/functions/dist/internal.js"(exports) {
87
- "use strict";
88
- Object.defineProperty(exports, "__esModule", { value: true });
89
- exports.LogLevel = exports.systemLogger = void 0;
90
- var system_logger_js_1 = require_system_logger();
91
- Object.defineProperty(exports, "systemLogger", { enumerable: true, get: function() {
92
- return system_logger_js_1.systemLogger;
93
- } });
94
- Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function() {
95
- return system_logger_js_1.LogLevel;
96
- } });
97
- }
98
- });
99
-
100
- // src/run/systemlog.ts
101
- var import_internal = __toESM(require_internal(), 1);
102
-
103
- export {
104
- import_internal
105
- };
@@ -1,97 +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
- require_semver
9
- } from "./chunk-PJG75HGC.js";
10
- import {
11
- getAPIRoutesConfigs
12
- } from "./chunk-BG455SFE.js";
13
- import {
14
- __toESM
15
- } from "./chunk-5JVNISGM.js";
16
-
17
- // src/build/verification.ts
18
- var import_semver = __toESM(require_semver(), 1);
19
- import { existsSync } from "node:fs";
20
- import { join } from "node:path";
21
- var SUPPORTED_NEXT_VERSIONS = ">=13.5.0";
22
- function verifyPublishDir(ctx) {
23
- if (!existsSync(ctx.publishDir)) {
24
- ctx.failBuild(
25
- `Your publish directory was not found at: ${ctx.publishDir}. Please check your build settings`
26
- );
27
- }
28
- if (ctx.publishDir === ctx.resolveFromPackagePath("")) {
29
- ctx.failBuild(
30
- `Your publish directory cannot be the same as the base directory of your site. Please check your build settings`
31
- );
32
- }
33
- try {
34
- ctx.buildConfig;
35
- } catch {
36
- ctx.failBuild(
37
- "Your publish directory does not contain expected Next.js build output. Please check your build settings"
38
- );
39
- }
40
- if (ctx.buildConfig.output === "standalone" || ctx.buildConfig.output === void 0) {
41
- if (!existsSync(join(ctx.publishDir, "BUILD_ID"))) {
42
- ctx.failBuild(
43
- "Your publish directory does not contain expected Next.js build output. Please check your build settings"
44
- );
45
- }
46
- if (!existsSync(ctx.standaloneRootDir)) {
47
- ctx.failBuild(
48
- `Your publish directory does not contain expected Next.js build output. Please make sure you are using Next.js version (${SUPPORTED_NEXT_VERSIONS})`
49
- );
50
- }
51
- }
52
- if (ctx.buildConfig.output === "export") {
53
- if (!ctx.exportDetail?.success) {
54
- ctx.failBuild(`Your export failed to build. Please check your build settings`);
55
- }
56
- if (!existsSync(ctx.exportDetail?.outDirectory)) {
57
- ctx.failBuild(
58
- `Your export directory was not found at: ${ctx.exportDetail?.outDirectory}. Please check your build settings`
59
- );
60
- }
61
- }
62
- }
63
- function verifyNextVersion(ctx, nextVersion) {
64
- if (!(0, import_semver.satisfies)(nextVersion, SUPPORTED_NEXT_VERSIONS, { includePrerelease: true })) {
65
- ctx.failBuild(
66
- `@netlify/plugin-next@5 requires Next.js version ${SUPPORTED_NEXT_VERSIONS}, but found ${nextVersion}. Please upgrade your project's Next.js version.`
67
- );
68
- }
69
- }
70
- function verifyBuildConfig(ctx) {
71
- if (ctx.buildConfig.experimental.ppr) {
72
- console.log(
73
- `Partial prerendering is not yet fully supported on Netlify, see https://ntl.fyi/nextjs-ppr for details`
74
- );
75
- }
76
- }
77
- async function verifyNoAdvancedAPIRoutes(ctx) {
78
- const apiRoutesConfigs = await getAPIRoutesConfigs(ctx);
79
- const unsupportedAPIRoutes = apiRoutesConfigs.filter((apiRouteConfig) => {
80
- return apiRouteConfig.config.type === "experimental-background" /* BACKGROUND */ || apiRouteConfig.config.type === "experimental-scheduled" /* SCHEDULED */;
81
- });
82
- if (unsupportedAPIRoutes.length !== 0) {
83
- ctx.failBuild(
84
- `@netlify/plugin-next@5 does not support advanced API routes. The following API routes should be migrated to Netlify background or scheduled functions:
85
- ${unsupportedAPIRoutes.map((apiRouteConfig) => ` - ${apiRouteConfig.apiRoute} (type: "${apiRouteConfig.config.type}")`).join("\n")}
86
-
87
- Refer to https://ntl.fyi/next-scheduled-bg-function-migration as migration example.`
88
- );
89
- }
90
- }
91
-
92
- export {
93
- verifyPublishDir,
94
- verifyNextVersion,
95
- verifyBuildConfig,
96
- verifyNoAdvancedAPIRoutes
97
- };
@@ -1,238 +0,0 @@
1
-
2
- var require = await (async () => {
3
- var { createRequire } = await import("node:module");
4
- return createRequire(import.meta.url);
5
- })();
6
-
7
-
8
- // src/build/plugin-context.ts
9
- import { existsSync, readFileSync } from "node:fs";
10
- import { readFile } from "node:fs/promises";
11
- import { join, relative, resolve } from "node:path";
12
- import { fileURLToPath } from "node:url";
13
- var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
14
- var PLUGIN_DIR = join(MODULE_DIR, "../..");
15
- var DEFAULT_PUBLISH_DIR = ".next";
16
- var SERVER_HANDLER_NAME = "___netlify-server-handler";
17
- var EDGE_HANDLER_NAME = "___netlify-edge-handler";
18
- var PluginContext = class {
19
- utils;
20
- netlifyConfig;
21
- pluginName;
22
- pluginVersion;
23
- constants;
24
- packageJSON;
25
- /** Absolute path of the next runtime plugin directory */
26
- pluginDir = PLUGIN_DIR;
27
- get relPublishDir() {
28
- return this.constants.PUBLISH_DIR ?? join(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR);
29
- }
30
- /** Temporary directory for stashing the build output */
31
- get tempPublishDir() {
32
- return this.resolveFromPackagePath(".netlify/.next");
33
- }
34
- /** Absolute path of the publish directory */
35
- get publishDir() {
36
- return resolve(this.relPublishDir);
37
- }
38
- /**
39
- * Relative package path in non monorepo setups this is an empty string
40
- * This path is provided by Next.js RequiredServerFiles manifest
41
- * @example ''
42
- * @example 'apps/my-app'
43
- */
44
- get relativeAppDir() {
45
- return this.requiredServerFiles.relativeAppDir ?? "";
46
- }
47
- /**
48
- * The working directory inside the lambda that is used for monorepos to execute the serverless function
49
- */
50
- get lambdaWorkingDirectory() {
51
- return join("/var/task", this.distDirParent);
52
- }
53
- /**
54
- * Retrieves the root of the `.next/standalone` directory
55
- */
56
- get standaloneRootDir() {
57
- return join(this.publishDir, "standalone");
58
- }
59
- /**
60
- * The resolved relative next dist directory defaults to `.next`,
61
- * but can be configured through the next.config.js. For monorepos this will include the packagePath
62
- * If we need just the plain dist dir use the `nextDistDir`
63
- */
64
- get distDir() {
65
- const dir = this.buildConfig.distDir ?? DEFAULT_PUBLISH_DIR;
66
- return relative(process.cwd(), resolve(this.relativeAppDir, dir));
67
- }
68
- /** Represents the parent directory of the .next folder or custom distDir */
69
- get distDirParent() {
70
- return join(this.distDir, "..");
71
- }
72
- /** The `.next` folder or what the custom dist dir is set to */
73
- get nextDistDir() {
74
- return relative(this.distDirParent, this.distDir);
75
- }
76
- /** Retrieves the `.next/standalone/` directory monorepo aware */
77
- get standaloneDir() {
78
- return join(this.standaloneRootDir, this.distDirParent);
79
- }
80
- /**
81
- * Absolute path of the directory that is published and deployed to the Netlify CDN
82
- * Will be swapped with the publish directory
83
- * `.netlify/static`
84
- */
85
- get staticDir() {
86
- return this.resolveFromPackagePath(".netlify/static");
87
- }
88
- /**
89
- * Absolute path of the directory that will be deployed to the blob store
90
- * `.netlify/blobs/deploy`
91
- */
92
- get blobDir() {
93
- return this.resolveFromPackagePath(".netlify/blobs/deploy");
94
- }
95
- /**
96
- * Absolute path of the directory containing the files for the serverless lambda function
97
- * `.netlify/functions-internal`
98
- */
99
- get serverFunctionsDir() {
100
- return this.resolveFromPackagePath(".netlify/functions-internal");
101
- }
102
- /** Absolute path of the server handler */
103
- get serverHandlerRootDir() {
104
- return join(this.serverFunctionsDir, SERVER_HANDLER_NAME);
105
- }
106
- get serverHandlerDir() {
107
- if (this.relativeAppDir.length === 0) {
108
- return this.serverHandlerRootDir;
109
- }
110
- return join(this.serverHandlerRootDir, this.distDirParent);
111
- }
112
- get nextServerHandler() {
113
- if (this.relativeAppDir.length !== 0) {
114
- return join(this.lambdaWorkingDirectory, ".netlify/dist/run/handlers/server.js");
115
- }
116
- return "./.netlify/dist/run/handlers/server.js";
117
- }
118
- /**
119
- * Absolute path of the directory containing the files for deno edge functions
120
- * `.netlify/edge-functions`
121
- */
122
- get edgeFunctionsDir() {
123
- return this.resolveFromPackagePath(".netlify/edge-functions");
124
- }
125
- /** Absolute path of the edge handler */
126
- get edgeHandlerDir() {
127
- return join(this.edgeFunctionsDir, EDGE_HANDLER_NAME);
128
- }
129
- constructor(options) {
130
- this.packageJSON = JSON.parse(readFileSync(join(PLUGIN_DIR, "package.json"), "utf-8"));
131
- this.pluginName = this.packageJSON.name;
132
- this.pluginVersion = this.packageJSON.version;
133
- this.constants = options.constants;
134
- this.utils = options.utils;
135
- this.netlifyConfig = options.netlifyConfig;
136
- }
137
- /** Resolves a path correctly with mono repository awareness for .netlify directories mainly */
138
- resolveFromPackagePath(...args) {
139
- return resolve(this.constants.PACKAGE_PATH || "", ...args);
140
- }
141
- /** Resolves a path correctly from site directory */
142
- resolveFromSiteDir(...args) {
143
- return resolve(this.requiredServerFiles.appDir, ...args);
144
- }
145
- /** Get the next prerender-manifest.json */
146
- async getPrerenderManifest() {
147
- return JSON.parse(await readFile(join(this.publishDir, "prerender-manifest.json"), "utf-8"));
148
- }
149
- /**
150
- * Uses various heuristics to try to find the .next dir.
151
- * Works by looking for BUILD_ID, so requires the site to have been built
152
- */
153
- findDotNext() {
154
- for (const dir of [
155
- // The publish directory
156
- this.publishDir,
157
- // In the root
158
- resolve(DEFAULT_PUBLISH_DIR),
159
- // The sibling of the publish directory
160
- resolve(this.publishDir, "..", DEFAULT_PUBLISH_DIR),
161
- // In the package dir
162
- resolve(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR)
163
- ]) {
164
- if (existsSync(join(dir, "BUILD_ID"))) {
165
- return dir;
166
- }
167
- }
168
- return false;
169
- }
170
- /**
171
- * Get Next.js middleware config from the build output
172
- */
173
- async getMiddlewareManifest() {
174
- return JSON.parse(
175
- await readFile(join(this.publishDir, "server/middleware-manifest.json"), "utf-8")
176
- );
177
- }
178
- // don't make private as it is handy inside testing to override the config
179
- _requiredServerFiles = null;
180
- /** Get RequiredServerFiles manifest from build output **/
181
- get requiredServerFiles() {
182
- if (!this._requiredServerFiles) {
183
- let requiredServerFilesJson = join(this.publishDir, "required-server-files.json");
184
- if (!existsSync(requiredServerFilesJson)) {
185
- const dotNext = this.findDotNext();
186
- if (dotNext) {
187
- requiredServerFilesJson = join(dotNext, "required-server-files.json");
188
- }
189
- }
190
- this._requiredServerFiles = JSON.parse(
191
- readFileSync(requiredServerFilesJson, "utf-8")
192
- );
193
- }
194
- return this._requiredServerFiles;
195
- }
196
- #exportDetail = null;
197
- /** Get metadata when output = export */
198
- get exportDetail() {
199
- if (this.buildConfig.output !== "export") {
200
- return null;
201
- }
202
- if (!this.#exportDetail) {
203
- const detailFile = join(
204
- this.requiredServerFiles.appDir,
205
- this.buildConfig.distDir,
206
- "export-detail.json"
207
- );
208
- if (!existsSync(detailFile)) {
209
- return null;
210
- }
211
- try {
212
- this.#exportDetail = JSON.parse(readFileSync(detailFile, "utf-8"));
213
- } catch {
214
- }
215
- }
216
- return this.#exportDetail;
217
- }
218
- /** Get Next Config from build output **/
219
- get buildConfig() {
220
- return this.requiredServerFiles.config;
221
- }
222
- /**
223
- * Get Next.js routes manifest from the build output
224
- */
225
- async getRoutesManifest() {
226
- return JSON.parse(await readFile(join(this.publishDir, "routes-manifest.json"), "utf-8"));
227
- }
228
- /** Fails a build with a message and an optional error */
229
- failBuild(message, error) {
230
- return this.utils.build.failBuild(message, error instanceof Error ? { error } : void 0);
231
- }
232
- };
233
-
234
- export {
235
- SERVER_HANDLER_NAME,
236
- EDGE_HANDLER_NAME,
237
- PluginContext
238
- };