@netlify/plugin-nextjs 5.10.0 → 5.10.1
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.
- package/dist/build/advanced-api-routes.js +136 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +293 -11
- package/dist/build/content/server.js +219 -11
- package/dist/build/content/static.js +112 -15
- package/dist/build/functions/edge.js +540 -7
- package/dist/build/functions/server.js +130 -11
- package/dist/build/image-cdn.js +1599 -3
- package/dist/build/plugin-context.js +292 -6
- package/dist/build/verification.js +104 -9
- package/dist/esm-chunks/{package-F536DQ6H.js → package-UN6EVEHD.js} +1 -1
- package/dist/index.js +19 -40
- package/dist/run/config.js +1 -4
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +44 -1654
- package/dist/run/handlers/server.js +14 -33
- package/dist/run/handlers/tracer.cjs +2 -114
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +198 -10
- package/dist/run/next.cjs +11 -1623
- package/dist/run/regional-blob-store.cjs +37 -4
- package/dist/run/revalidate.js +24 -3
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
- package/dist/esm-chunks/chunk-DLBTTDNJ.js +0 -309
- package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
- package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
- package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
- package/dist/esm-chunks/chunk-K4RDUZYO.js +0 -609
- package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-VTKZZRGT.js +0 -132
- package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
- package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
- package/dist/esm-chunks/chunk-YMNWVS6T.js +0 -218
- package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
- package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
- package/dist/esm-chunks/next-7JK63CHT.js +0 -567
|
@@ -1,305 +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-APO262HE.js";
|
|
10
|
-
import {
|
|
11
|
-
__toESM
|
|
12
|
-
} from "./chunk-OEQOKJGE.js";
|
|
13
|
-
|
|
14
|
-
// src/build/plugin-context.ts
|
|
15
|
-
var import_semver = __toESM(require_semver(), 1);
|
|
16
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
17
|
-
import { readFile } from "node:fs/promises";
|
|
18
|
-
import { createRequire } from "node:module";
|
|
19
|
-
import { join, relative, resolve } from "node:path";
|
|
20
|
-
import { join as posixJoin } from "node:path/posix";
|
|
21
|
-
import { fileURLToPath } from "node:url";
|
|
22
|
-
var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
|
|
23
|
-
var PLUGIN_DIR = join(MODULE_DIR, "../..");
|
|
24
|
-
var DEFAULT_PUBLISH_DIR = ".next";
|
|
25
|
-
var SERVER_HANDLER_NAME = "___netlify-server-handler";
|
|
26
|
-
var EDGE_HANDLER_NAME = "___netlify-edge-handler";
|
|
27
|
-
var PluginContext = class {
|
|
28
|
-
featureFlags;
|
|
29
|
-
netlifyConfig;
|
|
30
|
-
pluginName;
|
|
31
|
-
pluginVersion;
|
|
32
|
-
utils;
|
|
33
|
-
constants;
|
|
34
|
-
packageJSON;
|
|
35
|
-
/** Absolute path of the next runtime plugin directory */
|
|
36
|
-
pluginDir = PLUGIN_DIR;
|
|
37
|
-
get relPublishDir() {
|
|
38
|
-
return this.constants.PUBLISH_DIR ?? join(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR);
|
|
39
|
-
}
|
|
40
|
-
/** Temporary directory for stashing the build output */
|
|
41
|
-
get tempPublishDir() {
|
|
42
|
-
return this.resolveFromPackagePath(".netlify/.next");
|
|
43
|
-
}
|
|
44
|
-
/** Absolute path of the publish directory */
|
|
45
|
-
get publishDir() {
|
|
46
|
-
return resolve(this.relPublishDir);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Relative package path in non monorepo setups this is an empty string
|
|
50
|
-
* This path is provided by Next.js RequiredServerFiles manifest
|
|
51
|
-
* @example ''
|
|
52
|
-
* @example 'apps/my-app'
|
|
53
|
-
*/
|
|
54
|
-
get relativeAppDir() {
|
|
55
|
-
return this.requiredServerFiles.relativeAppDir ?? "";
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The working directory inside the lambda that is used for monorepos to execute the serverless function
|
|
59
|
-
*/
|
|
60
|
-
get lambdaWorkingDirectory() {
|
|
61
|
-
return join("/var/task", this.distDirParent);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Retrieves the root of the `.next/standalone` directory
|
|
65
|
-
*/
|
|
66
|
-
get standaloneRootDir() {
|
|
67
|
-
return join(this.publishDir, "standalone");
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* The resolved relative next dist directory defaults to `.next`,
|
|
71
|
-
* but can be configured through the next.config.js. For monorepos this will include the packagePath
|
|
72
|
-
* If we need just the plain dist dir use the `nextDistDir`
|
|
73
|
-
*/
|
|
74
|
-
get distDir() {
|
|
75
|
-
const dir = this.buildConfig.distDir ?? DEFAULT_PUBLISH_DIR;
|
|
76
|
-
return relative(process.cwd(), resolve(this.relativeAppDir, dir));
|
|
77
|
-
}
|
|
78
|
-
/** Represents the parent directory of the .next folder or custom distDir */
|
|
79
|
-
get distDirParent() {
|
|
80
|
-
return join(this.distDir, "..");
|
|
81
|
-
}
|
|
82
|
-
/** The `.next` folder or what the custom dist dir is set to */
|
|
83
|
-
get nextDistDir() {
|
|
84
|
-
return relative(this.distDirParent, this.distDir);
|
|
85
|
-
}
|
|
86
|
-
/** Retrieves the `.next/standalone/` directory monorepo aware */
|
|
87
|
-
get standaloneDir() {
|
|
88
|
-
return join(this.standaloneRootDir, this.distDirParent);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Absolute path of the directory that is published and deployed to the Netlify CDN
|
|
92
|
-
* Will be swapped with the publish directory
|
|
93
|
-
* `.netlify/static`
|
|
94
|
-
*/
|
|
95
|
-
get staticDir() {
|
|
96
|
-
return this.resolveFromPackagePath(".netlify/static");
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Absolute path of the directory that will be deployed to the blob store
|
|
100
|
-
* region aware: `.netlify/deploy/v1/blobs/deploy`
|
|
101
|
-
* default: `.netlify/blobs/deploy`
|
|
102
|
-
*/
|
|
103
|
-
get blobDir() {
|
|
104
|
-
if (this.useRegionalBlobs) {
|
|
105
|
-
return this.resolveFromPackagePath(".netlify/deploy/v1/blobs/deploy");
|
|
106
|
-
}
|
|
107
|
-
return this.resolveFromPackagePath(".netlify/blobs/deploy");
|
|
108
|
-
}
|
|
109
|
-
get buildVersion() {
|
|
110
|
-
return this.constants.NETLIFY_BUILD_VERSION || "v0.0.0";
|
|
111
|
-
}
|
|
112
|
-
get useRegionalBlobs() {
|
|
113
|
-
const REQUIRED_BUILD_VERSION = ">=29.41.5";
|
|
114
|
-
return (0, import_semver.satisfies)(this.buildVersion, REQUIRED_BUILD_VERSION, { includePrerelease: true });
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Absolute path of the directory containing the files for the serverless lambda function
|
|
118
|
-
* `.netlify/functions-internal`
|
|
119
|
-
*/
|
|
120
|
-
get serverFunctionsDir() {
|
|
121
|
-
return this.resolveFromPackagePath(".netlify/functions-internal");
|
|
122
|
-
}
|
|
123
|
-
/** Absolute path of the server handler */
|
|
124
|
-
get serverHandlerRootDir() {
|
|
125
|
-
return join(this.serverFunctionsDir, SERVER_HANDLER_NAME);
|
|
126
|
-
}
|
|
127
|
-
get serverHandlerDir() {
|
|
128
|
-
if (this.relativeAppDir.length === 0) {
|
|
129
|
-
return this.serverHandlerRootDir;
|
|
130
|
-
}
|
|
131
|
-
return join(this.serverHandlerRootDir, this.distDirParent);
|
|
132
|
-
}
|
|
133
|
-
get serverHandlerRuntimeModulesDir() {
|
|
134
|
-
return join(this.serverHandlerDir, ".netlify");
|
|
135
|
-
}
|
|
136
|
-
get nextServerHandler() {
|
|
137
|
-
if (this.relativeAppDir.length !== 0) {
|
|
138
|
-
return join(this.lambdaWorkingDirectory, ".netlify/dist/run/handlers/server.js");
|
|
139
|
-
}
|
|
140
|
-
return "./.netlify/dist/run/handlers/server.js";
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Absolute path of the directory containing the files for deno edge functions
|
|
144
|
-
* `.netlify/edge-functions`
|
|
145
|
-
*/
|
|
146
|
-
get edgeFunctionsDir() {
|
|
147
|
-
return this.resolveFromPackagePath(".netlify/edge-functions");
|
|
148
|
-
}
|
|
149
|
-
/** Absolute path of the edge handler */
|
|
150
|
-
get edgeHandlerDir() {
|
|
151
|
-
return join(this.edgeFunctionsDir, EDGE_HANDLER_NAME);
|
|
152
|
-
}
|
|
153
|
-
constructor(options) {
|
|
154
|
-
this.constants = options.constants;
|
|
155
|
-
this.featureFlags = options.featureFlags;
|
|
156
|
-
this.netlifyConfig = options.netlifyConfig;
|
|
157
|
-
this.packageJSON = JSON.parse(readFileSync(join(PLUGIN_DIR, "package.json"), "utf-8"));
|
|
158
|
-
this.pluginName = this.packageJSON.name;
|
|
159
|
-
this.pluginVersion = this.packageJSON.version;
|
|
160
|
-
this.utils = options.utils;
|
|
161
|
-
}
|
|
162
|
-
/** Resolves a path correctly with mono repository awareness for .netlify directories mainly */
|
|
163
|
-
resolveFromPackagePath(...args) {
|
|
164
|
-
return resolve(this.constants.PACKAGE_PATH || "", ...args);
|
|
165
|
-
}
|
|
166
|
-
/** Resolves a path correctly from site directory */
|
|
167
|
-
resolveFromSiteDir(...args) {
|
|
168
|
-
return resolve(this.requiredServerFiles.appDir, ...args);
|
|
169
|
-
}
|
|
170
|
-
/** Get the next prerender-manifest.json */
|
|
171
|
-
async getPrerenderManifest() {
|
|
172
|
-
return JSON.parse(await readFile(join(this.publishDir, "prerender-manifest.json"), "utf-8"));
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Uses various heuristics to try to find the .next dir.
|
|
176
|
-
* Works by looking for BUILD_ID, so requires the site to have been built
|
|
177
|
-
*/
|
|
178
|
-
findDotNext() {
|
|
179
|
-
for (const dir of [
|
|
180
|
-
// The publish directory
|
|
181
|
-
this.publishDir,
|
|
182
|
-
// In the root
|
|
183
|
-
resolve(DEFAULT_PUBLISH_DIR),
|
|
184
|
-
// The sibling of the publish directory
|
|
185
|
-
resolve(this.publishDir, "..", DEFAULT_PUBLISH_DIR),
|
|
186
|
-
// In the package dir
|
|
187
|
-
resolve(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR)
|
|
188
|
-
]) {
|
|
189
|
-
if (existsSync(join(dir, "BUILD_ID"))) {
|
|
190
|
-
return dir;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Get Next.js middleware config from the build output
|
|
197
|
-
*/
|
|
198
|
-
async getMiddlewareManifest() {
|
|
199
|
-
return JSON.parse(
|
|
200
|
-
await readFile(join(this.publishDir, "server/middleware-manifest.json"), "utf-8")
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
// don't make private as it is handy inside testing to override the config
|
|
204
|
-
_requiredServerFiles = null;
|
|
205
|
-
/** Get RequiredServerFiles manifest from build output **/
|
|
206
|
-
get requiredServerFiles() {
|
|
207
|
-
if (!this._requiredServerFiles) {
|
|
208
|
-
let requiredServerFilesJson = join(this.publishDir, "required-server-files.json");
|
|
209
|
-
if (!existsSync(requiredServerFilesJson)) {
|
|
210
|
-
const dotNext = this.findDotNext();
|
|
211
|
-
if (dotNext) {
|
|
212
|
-
requiredServerFilesJson = join(dotNext, "required-server-files.json");
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
this._requiredServerFiles = JSON.parse(
|
|
216
|
-
readFileSync(requiredServerFilesJson, "utf-8")
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
return this._requiredServerFiles;
|
|
220
|
-
}
|
|
221
|
-
#exportDetail = null;
|
|
222
|
-
/** Get metadata when output = export */
|
|
223
|
-
get exportDetail() {
|
|
224
|
-
if (this.buildConfig.output !== "export") {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
if (!this.#exportDetail) {
|
|
228
|
-
const detailFile = join(
|
|
229
|
-
this.requiredServerFiles.appDir,
|
|
230
|
-
this.buildConfig.distDir,
|
|
231
|
-
"export-detail.json"
|
|
232
|
-
);
|
|
233
|
-
if (!existsSync(detailFile)) {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
try {
|
|
237
|
-
this.#exportDetail = JSON.parse(readFileSync(detailFile, "utf-8"));
|
|
238
|
-
} catch {
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return this.#exportDetail;
|
|
242
|
-
}
|
|
243
|
-
/** Get Next Config from build output **/
|
|
244
|
-
get buildConfig() {
|
|
245
|
-
return this.requiredServerFiles.config;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Get Next.js routes manifest from the build output
|
|
249
|
-
*/
|
|
250
|
-
async getRoutesManifest() {
|
|
251
|
-
return JSON.parse(await readFile(join(this.publishDir, "routes-manifest.json"), "utf-8"));
|
|
252
|
-
}
|
|
253
|
-
#nextVersion = void 0;
|
|
254
|
-
/**
|
|
255
|
-
* Get Next.js version that was used to build the site
|
|
256
|
-
*/
|
|
257
|
-
get nextVersion() {
|
|
258
|
-
if (this.#nextVersion === void 0) {
|
|
259
|
-
try {
|
|
260
|
-
const serverHandlerRequire = createRequire(posixJoin(this.standaloneRootDir, ":internal:"));
|
|
261
|
-
const { version } = serverHandlerRequire("next/package.json");
|
|
262
|
-
this.#nextVersion = version;
|
|
263
|
-
} catch {
|
|
264
|
-
this.#nextVersion = null;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return this.#nextVersion;
|
|
268
|
-
}
|
|
269
|
-
#fallbacks = null;
|
|
270
|
-
/**
|
|
271
|
-
* Get an array of localized fallback routes
|
|
272
|
-
*
|
|
273
|
-
* Example return value for non-i18n site: `['blog/[slug]']`
|
|
274
|
-
*
|
|
275
|
-
* Example return value for i18n site: `['en/blog/[slug]', 'fr/blog/[slug]']`
|
|
276
|
-
*/
|
|
277
|
-
getFallbacks(prerenderManifest) {
|
|
278
|
-
if (!this.#fallbacks) {
|
|
279
|
-
const locales = this.buildConfig.i18n?.locales ?? [""];
|
|
280
|
-
this.#fallbacks = Object.entries(prerenderManifest.dynamicRoutes).reduce(
|
|
281
|
-
(fallbacks, [route, meta]) => {
|
|
282
|
-
if (typeof meta.fallback === "string") {
|
|
283
|
-
for (const locale of locales) {
|
|
284
|
-
const localizedRoute = posixJoin(locale, route.replace(/^\/+/g, ""));
|
|
285
|
-
fallbacks.push(localizedRoute);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return fallbacks;
|
|
289
|
-
},
|
|
290
|
-
[]
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
return this.#fallbacks;
|
|
294
|
-
}
|
|
295
|
-
/** Fails a build with a message and an optional error */
|
|
296
|
-
failBuild(message, error) {
|
|
297
|
-
return this.utils.build.failBuild(message, error instanceof Error ? { error } : void 0);
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
export {
|
|
302
|
-
SERVER_HANDLER_NAME,
|
|
303
|
-
EDGE_HANDLER_NAME,
|
|
304
|
-
PluginContext
|
|
305
|
-
};
|
|
@@ -1,235 +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
|
-
require_out
|
|
16
|
-
} from "./chunk-KGYJQ2U2.js";
|
|
17
|
-
import {
|
|
18
|
-
require_semver
|
|
19
|
-
} from "./chunk-APO262HE.js";
|
|
20
|
-
import {
|
|
21
|
-
RUN_CONFIG
|
|
22
|
-
} from "./chunk-UYKENJEU.js";
|
|
23
|
-
import {
|
|
24
|
-
__toESM
|
|
25
|
-
} from "./chunk-OEQOKJGE.js";
|
|
26
|
-
|
|
27
|
-
// src/build/content/server.ts
|
|
28
|
-
init_esm();
|
|
29
|
-
import { existsSync } from "node:fs";
|
|
30
|
-
import {
|
|
31
|
-
access,
|
|
32
|
-
cp,
|
|
33
|
-
mkdir,
|
|
34
|
-
readdir,
|
|
35
|
-
readFile,
|
|
36
|
-
readlink,
|
|
37
|
-
symlink,
|
|
38
|
-
writeFile
|
|
39
|
-
} from "node:fs/promises";
|
|
40
|
-
import { createRequire } from "node:module";
|
|
41
|
-
import { dirname, join, resolve, sep } from "node:path";
|
|
42
|
-
import { join as posixJoin, sep as posixSep } from "node:path/posix";
|
|
43
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
44
|
-
var import_semver = __toESM(require_semver(), 1);
|
|
45
|
-
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
46
|
-
var toPosixPath = (path) => path.split(sep).join(posixSep);
|
|
47
|
-
function isError(error) {
|
|
48
|
-
return error instanceof Error;
|
|
49
|
-
}
|
|
50
|
-
var copyNextServerCode = async (ctx) => {
|
|
51
|
-
await tracer.withActiveSpan("copyNextServerCode", async () => {
|
|
52
|
-
const reqServerFilesPath = join(
|
|
53
|
-
ctx.standaloneRootDir,
|
|
54
|
-
ctx.relativeAppDir,
|
|
55
|
-
ctx.requiredServerFiles.config.distDir,
|
|
56
|
-
"required-server-files.json"
|
|
57
|
-
);
|
|
58
|
-
try {
|
|
59
|
-
await access(reqServerFilesPath);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (isError(error) && error.code === "ENOENT") {
|
|
62
|
-
ctx.failBuild(
|
|
63
|
-
`Failed creating server handler. required-server-files.json file not found at expected location "${reqServerFilesPath}". Your repository setup is currently not yet supported.`
|
|
64
|
-
);
|
|
65
|
-
} else {
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
|
|
70
|
-
if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.relativeAppDir}/?`), "") !== reqServerFiles.config.distDir) {
|
|
71
|
-
reqServerFiles.config.distDir = ctx.nextDistDir;
|
|
72
|
-
await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
|
|
73
|
-
}
|
|
74
|
-
await mkdir(ctx.serverHandlerDir, { recursive: true });
|
|
75
|
-
await writeFile(
|
|
76
|
-
join(ctx.serverHandlerDir, RUN_CONFIG),
|
|
77
|
-
JSON.stringify(reqServerFiles.config),
|
|
78
|
-
"utf-8"
|
|
79
|
-
);
|
|
80
|
-
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
81
|
-
const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
|
|
82
|
-
const destDir = join(ctx.serverHandlerDir, nextFolder);
|
|
83
|
-
const paths = await (0, import_fast_glob.default)(
|
|
84
|
-
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
|
|
85
|
-
{
|
|
86
|
-
cwd: srcDir,
|
|
87
|
-
extglob: true
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
await Promise.all(
|
|
91
|
-
paths.map(async (path) => {
|
|
92
|
-
const srcPath = join(srcDir, path);
|
|
93
|
-
const destPath = join(destDir, path);
|
|
94
|
-
if (path === "server/middleware-manifest.json") {
|
|
95
|
-
try {
|
|
96
|
-
await replaceMiddlewareManifest(srcPath, destPath);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
throw new Error("Could not patch middleware manifest file", { cause: error });
|
|
99
|
-
}
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
await cp(srcPath, destPath, { recursive: true, force: true });
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
async function recreateNodeModuleSymlinks(src, dest, org) {
|
|
108
|
-
const dirents = await readdir(join(src, org || ""), { withFileTypes: true });
|
|
109
|
-
await Promise.all(
|
|
110
|
-
dirents.map(async (dirent) => {
|
|
111
|
-
if (dirent.name.startsWith("@")) {
|
|
112
|
-
return recreateNodeModuleSymlinks(src, dest, dirent.name);
|
|
113
|
-
}
|
|
114
|
-
if (dirent.isSymbolicLink()) {
|
|
115
|
-
const symlinkSrc = join(dest, org || "", dirent.name);
|
|
116
|
-
const symlinkTarget = await readlink(join(src, org || "", dirent.name));
|
|
117
|
-
const symlinkDest = join(dest, org || "", symlinkTarget);
|
|
118
|
-
if (existsSync(symlinkDest) && !existsSync(symlinkSrc)) {
|
|
119
|
-
if (org) {
|
|
120
|
-
await mkdir(join(dest, org), { recursive: true });
|
|
121
|
-
}
|
|
122
|
-
await symlink(symlinkTarget, symlinkSrc);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
var nextInternalModuleReplacements = [
|
|
129
|
-
{
|
|
130
|
-
// standalone is loading expensive Telemetry module that is not actually used
|
|
131
|
-
// so this replace that module with lightweight no-op shim that doesn't load additional modules
|
|
132
|
-
// see https://github.com/vercel/next.js/pull/63574 that removed need for this shim
|
|
133
|
-
ongoing: false,
|
|
134
|
-
minVersion: "13.5.0-canary.0",
|
|
135
|
-
// perf released in https://github.com/vercel/next.js/releases/tag/v14.2.0-canary.43
|
|
136
|
-
maxVersion: "14.2.0-canary.42",
|
|
137
|
-
nextModule: "next/dist/telemetry/storage.js",
|
|
138
|
-
shimModule: "./next-shims/telemetry-storage.cjs"
|
|
139
|
-
}
|
|
140
|
-
];
|
|
141
|
-
function getPatchesToApply(nextVersion, patches = nextInternalModuleReplacements) {
|
|
142
|
-
return patches.filter((patch) => {
|
|
143
|
-
if ((0, import_semver.lt)(nextVersion, patch.minVersion)) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
if (patch.ongoing) {
|
|
147
|
-
if ((0, import_semver.prerelease)(nextVersion) || process.env.NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
return (0, import_semver.lte)(nextVersion, patch.maxStableVersion);
|
|
151
|
-
}
|
|
152
|
-
return (0, import_semver.lte)(nextVersion, patch.maxVersion);
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
async function patchNextModules(ctx, nextVersion, serverHandlerRequireResolve) {
|
|
156
|
-
const moduleReplacementsToApply = getPatchesToApply(nextVersion);
|
|
157
|
-
if (moduleReplacementsToApply.length !== 0) {
|
|
158
|
-
await Promise.all(
|
|
159
|
-
moduleReplacementsToApply.map(async ({ nextModule, shimModule }) => {
|
|
160
|
-
try {
|
|
161
|
-
const nextModulePath = serverHandlerRequireResolve(nextModule);
|
|
162
|
-
const shimModulePath = posixJoin(ctx.pluginDir, "dist", "build", "content", shimModule);
|
|
163
|
-
await cp(shimModulePath, nextModulePath, { force: true });
|
|
164
|
-
} catch {
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
var copyNextDependencies = async (ctx) => {
|
|
171
|
-
await tracer.withActiveSpan("copyNextDependencies", async () => {
|
|
172
|
-
const entries = await readdir(ctx.standaloneDir);
|
|
173
|
-
const promises = entries.map(async (entry) => {
|
|
174
|
-
if (entry === ctx.nextDistDir) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const src = join(ctx.standaloneDir, entry);
|
|
178
|
-
const dest = join(ctx.serverHandlerDir, entry);
|
|
179
|
-
await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
|
|
180
|
-
if (entry === "node_modules") {
|
|
181
|
-
await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir("node_modules"), dest);
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
|
|
185
|
-
const rootDestDir = join(ctx.serverHandlerRootDir, "node_modules");
|
|
186
|
-
if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
|
|
187
|
-
promises.push(
|
|
188
|
-
cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(
|
|
189
|
-
() => recreateNodeModuleSymlinks(resolve("node_modules"), rootDestDir)
|
|
190
|
-
)
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
await Promise.all(promises);
|
|
194
|
-
const serverHandlerRequire = createRequire(posixJoin(ctx.serverHandlerDir, ":internal:"));
|
|
195
|
-
if (ctx.nextVersion) {
|
|
196
|
-
await patchNextModules(ctx, ctx.nextVersion, serverHandlerRequire.resolve);
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
const nextEntryAbsolutePath = serverHandlerRequire.resolve("next");
|
|
200
|
-
const nextRequire = createRequire(nextEntryAbsolutePath);
|
|
201
|
-
nextRequire.resolve("styled-jsx");
|
|
202
|
-
} catch {
|
|
203
|
-
throw new Error(
|
|
204
|
-
"node_modules are not installed correctly, if you are using pnpm please set the public hoist pattern to: `public-hoist-pattern[]=*`.\nRefer to your docs for more details: https://docs.netlify.com/integrations/frameworks/next-js/overview/#pnpm-support"
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
var replaceMiddlewareManifest = async (sourcePath, destPath) => {
|
|
210
|
-
await mkdir(dirname(destPath), { recursive: true });
|
|
211
|
-
const data = await readFile(sourcePath, "utf8");
|
|
212
|
-
const manifest = JSON.parse(data);
|
|
213
|
-
const newManifest = {
|
|
214
|
-
...manifest,
|
|
215
|
-
middleware: {}
|
|
216
|
-
};
|
|
217
|
-
const newData = JSON.stringify(newManifest);
|
|
218
|
-
await writeFile(destPath, newData);
|
|
219
|
-
};
|
|
220
|
-
var verifyHandlerDirStructure = async (ctx) => {
|
|
221
|
-
const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
|
|
222
|
-
const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
|
|
223
|
-
if (!existsSync(expectedBuildIDPath)) {
|
|
224
|
-
ctx.failBuild(
|
|
225
|
-
`Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".`
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
export {
|
|
231
|
-
copyNextServerCode,
|
|
232
|
-
getPatchesToApply,
|
|
233
|
-
copyNextDependencies,
|
|
234
|
-
verifyHandlerDirStructure
|
|
235
|
-
};
|