@netlify/plugin-nextjs 5.1.2 → 5.2.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.
Files changed (43) 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 +237 -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 +1615 -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-SCUAWNXR.js} +23 -23
  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 +27022 -10456
  21. package/dist/run/headers.js +198 -8
  22. package/dist/run/next.cjs +106 -655
  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/edge-runtime/lib/response.ts +3 -2
  28. package/package.json +1 -1
  29. package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
  30. package/dist/esm-chunks/chunk-4BNHE6TP.js +0 -278
  31. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  32. package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
  33. package/dist/esm-chunks/chunk-HESS57SH.js +0 -127
  34. package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
  35. package/dist/esm-chunks/chunk-K7BTUM7O.js +0 -97
  36. package/dist/esm-chunks/chunk-L6OM53B6.js +0 -238
  37. package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
  38. package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
  39. package/dist/esm-chunks/chunk-RL4K4CVH.js +0 -27
  40. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  41. package/dist/esm-chunks/chunk-UTQSBE5O.js +0 -524
  42. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  43. package/dist/esm-chunks/chunk-V2T6NUOM.js +0 -113
@@ -1,40 +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
- PLUGIN_DIR,
9
- RUN_CONFIG
10
- } from "./chunk-UYKENJEU.js";
11
-
12
- // src/run/config.ts
13
- import { existsSync } from "node:fs";
14
- import { readFile } from "node:fs/promises";
15
- import { join, resolve } from "node:path";
16
- var getRunConfig = async () => {
17
- return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG), "utf-8"));
18
- };
19
- var setRunConfig = (config) => {
20
- const cacheHandler = join(PLUGIN_DIR, ".netlify/dist/run/handlers/cache.cjs");
21
- if (!existsSync(cacheHandler)) {
22
- throw new Error(`Cache handler not found at ${cacheHandler}`);
23
- }
24
- config.experimental = {
25
- ...config.experimental,
26
- incrementalCacheHandlerPath: cacheHandler
27
- };
28
- config.cacheHandler = cacheHandler;
29
- config.cacheMaxMemorySize = 0;
30
- process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
31
- };
32
- var getTagsManifest = async () => {
33
- return JSON.parse(await readFile(resolve(PLUGIN_DIR, ".netlify/tags-manifest.json"), "utf-8"));
34
- };
35
-
36
- export {
37
- getRunConfig,
38
- setRunConfig,
39
- getTagsManifest
40
- };
@@ -1,278 +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-PDPDW32D.js";
10
- import {
11
- init_esm,
12
- trace
13
- } from "./chunk-Y3K5Q6FP.js";
14
- import {
15
- require_out
16
- } from "./chunk-VZNKO4OO.js";
17
- import {
18
- verifyNextVersion
19
- } from "./chunk-K7BTUM7O.js";
20
- import {
21
- require_semver
22
- } from "./chunk-PJG75HGC.js";
23
- import {
24
- RUN_CONFIG
25
- } from "./chunk-UYKENJEU.js";
26
- import {
27
- __toESM
28
- } from "./chunk-5JVNISGM.js";
29
-
30
- // src/build/content/server.ts
31
- init_esm();
32
- import { existsSync } from "node:fs";
33
- import {
34
- cp,
35
- mkdir,
36
- readFile,
37
- readdir,
38
- readlink,
39
- symlink,
40
- writeFile,
41
- access
42
- } from "node:fs/promises";
43
- import { createRequire } from "node:module";
44
- import { dirname, join, resolve, sep } from "node:path";
45
- import { sep as posixSep, join as posixJoin } from "node:path/posix";
46
- var import_fast_glob = __toESM(require_out(), 1);
47
- var import_semver = __toESM(require_semver(), 1);
48
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
49
- var toPosixPath = (path) => path.split(sep).join(posixSep);
50
- function isError(error) {
51
- return error instanceof Error;
52
- }
53
- var copyNextServerCode = async (ctx) => {
54
- await tracer.withActiveSpan("copyNextServerCode", async () => {
55
- const reqServerFilesPath = join(
56
- ctx.standaloneRootDir,
57
- ctx.relativeAppDir,
58
- ctx.requiredServerFiles.config.distDir,
59
- "required-server-files.json"
60
- );
61
- try {
62
- await access(reqServerFilesPath);
63
- } catch (error) {
64
- if (isError(error) && error.code === "ENOENT") {
65
- ctx.failBuild(
66
- `Failed creating server handler. required-server-files.json file not found at expected location "${reqServerFilesPath}". Your repository setup is currently not yet supported.`
67
- );
68
- } else {
69
- throw error;
70
- }
71
- }
72
- const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
73
- if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.relativeAppDir}/?`), "") !== reqServerFiles.config.distDir) {
74
- reqServerFiles.config.distDir = ctx.nextDistDir;
75
- await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
76
- }
77
- await mkdir(ctx.serverHandlerDir, { recursive: true });
78
- await writeFile(
79
- join(ctx.serverHandlerDir, RUN_CONFIG),
80
- JSON.stringify(reqServerFiles.config),
81
- "utf-8"
82
- );
83
- const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
84
- const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
85
- const destDir = join(ctx.serverHandlerDir, nextFolder);
86
- const paths = await (0, import_fast_glob.default)(
87
- [`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
88
- {
89
- cwd: srcDir,
90
- extglob: true
91
- }
92
- );
93
- await Promise.all(
94
- paths.map(async (path) => {
95
- const srcPath = join(srcDir, path);
96
- const destPath = join(destDir, path);
97
- if (path === "server/middleware-manifest.json") {
98
- try {
99
- await replaceMiddlewareManifest(srcPath, destPath);
100
- } catch (error) {
101
- throw new Error("Could not patch middleware manifest file", { cause: error });
102
- }
103
- return;
104
- }
105
- await cp(srcPath, destPath, { recursive: true, force: true });
106
- })
107
- );
108
- });
109
- };
110
- async function recreateNodeModuleSymlinks(src, dest, org) {
111
- const dirents = await readdir(join(src, org || ""), { withFileTypes: true });
112
- await Promise.all(
113
- dirents.map(async (dirent) => {
114
- if (dirent.name.startsWith("@")) {
115
- return recreateNodeModuleSymlinks(src, dest, dirent.name);
116
- }
117
- if (dirent.isSymbolicLink()) {
118
- const symlinkSrc = join(dest, org || "", dirent.name);
119
- const symlinkTarget = await readlink(join(src, org || "", dirent.name));
120
- const symlinkDest = join(dest, org || "", symlinkTarget);
121
- if (existsSync(symlinkDest) && !existsSync(symlinkSrc)) {
122
- if (org) {
123
- await mkdir(join(dest, org), { recursive: true });
124
- }
125
- await symlink(symlinkTarget, symlinkSrc);
126
- }
127
- }
128
- })
129
- );
130
- }
131
- var nextInternalModuleReplacements = [
132
- {
133
- // standalone is loading expensive Telemetry module that is not actually used
134
- // so this replace that module with lightweight no-op shim that doesn't load additional modules
135
- // see https://github.com/vercel/next.js/pull/63574 that removed need for this shim
136
- ongoing: false,
137
- minVersion: "13.5.0-canary.0",
138
- // perf released in https://github.com/vercel/next.js/releases/tag/v14.2.0-canary.43
139
- maxVersion: "14.2.0-canary.42",
140
- nextModule: "next/dist/telemetry/storage.js",
141
- shimModule: "./next-shims/telemetry-storage.cjs"
142
- }
143
- ];
144
- function getPatchesToApply(nextVersion, patches = nextInternalModuleReplacements) {
145
- return patches.filter((patch) => {
146
- if ((0, import_semver.lt)(nextVersion, patch.minVersion)) {
147
- return false;
148
- }
149
- if (patch.ongoing) {
150
- if ((0, import_semver.prerelease)(nextVersion) || process.env.NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES) {
151
- return true;
152
- }
153
- return (0, import_semver.lte)(nextVersion, patch.maxStableVersion);
154
- }
155
- return (0, import_semver.lte)(nextVersion, patch.maxVersion);
156
- });
157
- }
158
- async function patchNextModules(ctx, nextVersion, serverHandlerRequireResolve) {
159
- const moduleReplacementsToApply = getPatchesToApply(nextVersion);
160
- if (moduleReplacementsToApply.length !== 0) {
161
- await Promise.all(
162
- moduleReplacementsToApply.map(async ({ nextModule, shimModule }) => {
163
- try {
164
- const nextModulePath = serverHandlerRequireResolve(nextModule);
165
- const shimModulePath = posixJoin(ctx.pluginDir, "dist", "build", "content", shimModule);
166
- await cp(shimModulePath, nextModulePath, { force: true });
167
- } catch {
168
- }
169
- })
170
- );
171
- }
172
- }
173
- var copyNextDependencies = async (ctx) => {
174
- await tracer.withActiveSpan("copyNextDependencies", async () => {
175
- const entries = await readdir(ctx.standaloneDir);
176
- const promises = entries.map(async (entry) => {
177
- if (entry === "package.json" || entry === ctx.nextDistDir) {
178
- return;
179
- }
180
- const src = join(ctx.standaloneDir, entry);
181
- const dest = join(ctx.serverHandlerDir, entry);
182
- await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
183
- if (entry === "node_modules") {
184
- await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir("node_modules"), dest);
185
- }
186
- });
187
- const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
188
- const rootDestDir = join(ctx.serverHandlerRootDir, "node_modules");
189
- if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
190
- promises.push(
191
- cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(
192
- () => recreateNodeModuleSymlinks(resolve("node_modules"), rootDestDir)
193
- )
194
- );
195
- }
196
- await Promise.all(promises);
197
- const serverHandlerRequire = createRequire(posixJoin(ctx.serverHandlerDir, ":internal:"));
198
- let nextVersion;
199
- try {
200
- const { version } = serverHandlerRequire("next/package.json");
201
- if (version) {
202
- nextVersion = version;
203
- }
204
- } catch {
205
- }
206
- if (nextVersion) {
207
- verifyNextVersion(ctx, nextVersion);
208
- await patchNextModules(ctx, nextVersion, serverHandlerRequire.resolve);
209
- }
210
- try {
211
- const nextEntryAbsolutePath = serverHandlerRequire.resolve("next");
212
- const nextRequire = createRequire(nextEntryAbsolutePath);
213
- nextRequire.resolve("styled-jsx");
214
- } catch {
215
- throw new Error(
216
- "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"
217
- );
218
- }
219
- });
220
- };
221
- var writeTagsManifest = async (ctx) => {
222
- const manifest = await ctx.getPrerenderManifest();
223
- const routes = Object.entries(manifest.routes).map(async ([route, definition]) => {
224
- let tags;
225
- if (definition.dataRoute?.endsWith(".rsc")) {
226
- const path = join(ctx.publishDir, `server/app/${route === "/" ? "/index" : route}.meta`);
227
- try {
228
- const file = await readFile(path, "utf-8");
229
- const meta = JSON.parse(file);
230
- tags = meta.headers["x-next-cache-tags"];
231
- } catch {
232
- if (!definition.dataRoute?.endsWith("/default.rsc")) {
233
- console.log(`Unable to read cache tags for: ${path}`);
234
- }
235
- }
236
- }
237
- if (definition.dataRoute?.endsWith(".json")) {
238
- tags = `_N_T_${route}`;
239
- }
240
- if (definition.dataRoute === null) {
241
- tags = definition.initialHeaders?.["x-next-cache-tags"];
242
- }
243
- return [route, tags];
244
- });
245
- await writeFile(
246
- join(ctx.serverHandlerDir, ".netlify/tags-manifest.json"),
247
- JSON.stringify(Object.fromEntries(await Promise.all(routes))),
248
- "utf-8"
249
- );
250
- };
251
- var replaceMiddlewareManifest = async (sourcePath, destPath) => {
252
- await mkdir(dirname(destPath), { recursive: true });
253
- const data = await readFile(sourcePath, "utf8");
254
- const manifest = JSON.parse(data);
255
- const newManifest = {
256
- ...manifest,
257
- middleware: {}
258
- };
259
- const newData = JSON.stringify(newManifest);
260
- await writeFile(destPath, newData);
261
- };
262
- var verifyHandlerDirStructure = async (ctx) => {
263
- const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
264
- const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
265
- if (!existsSync(expectedBuildIDPath)) {
266
- ctx.failBuild(
267
- `Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".`
268
- );
269
- }
270
- };
271
-
272
- export {
273
- copyNextServerCode,
274
- getPatchesToApply,
275
- copyNextDependencies,
276
- writeTagsManifest,
277
- verifyHandlerDirStructure
278
- };
@@ -1,36 +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/cache.ts
9
- import { existsSync } from "node:fs";
10
- import { rm } from "node:fs/promises";
11
- import { join } from "node:path";
12
- var saveBuildCache = async (ctx) => {
13
- const { cache } = ctx.utils;
14
- const cacheDir = join(ctx.publishDir, "cache");
15
- if (existsSync(cacheDir)) {
16
- await rm(join(cacheDir, "fetch-cache"), { recursive: true, force: true });
17
- await cache.save(cacheDir);
18
- console.log("Next.js cache saved");
19
- } else {
20
- console.log("No Next.js cache to save");
21
- }
22
- };
23
- var restoreBuildCache = async (ctx) => {
24
- const { cache } = ctx.utils;
25
- const cacheDir = join(ctx.publishDir, "cache");
26
- if (await cache.restore(cacheDir)) {
27
- console.log("Next.js cache restored");
28
- } else {
29
- console.log("No Next.js cache to restore");
30
- }
31
- };
32
-
33
- export {
34
- saveBuildCache,
35
- restoreBuildCache
36
- };
@@ -1,133 +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
9
- } from "./chunk-5JVNISGM.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 functionsConfigManifestPath = join(
22
- ctx.publishDir,
23
- "server",
24
- "functions-config-manifest.json"
25
- );
26
- if (!existsSync(functionsConfigManifestPath)) {
27
- return [];
28
- }
29
- const functionsConfigManifest = JSON.parse(
30
- await readFile(functionsConfigManifestPath, "utf-8")
31
- );
32
- const appDir = ctx.resolveFromSiteDir(".");
33
- const pagesDir = join(appDir, "pages");
34
- const srcPagesDir = join(appDir, "src", "pages");
35
- const { pageExtensions } = ctx.requiredServerFiles.config;
36
- return Promise.all(
37
- Object.keys(functionsConfigManifest.functions).map(async (apiRoute) => {
38
- const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir], pageExtensions);
39
- const sharedFields = {
40
- apiRoute,
41
- filePath,
42
- config: {}
43
- };
44
- if (filePath) {
45
- const config = await extractConfigFromFile(filePath, appDir);
46
- return {
47
- ...sharedFields,
48
- config
49
- };
50
- }
51
- return sharedFields;
52
- })
53
- );
54
- }
55
- var SOURCE_FILE_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
56
- var getSourceFileForPage = (page, roots, pageExtensions = SOURCE_FILE_EXTENSIONS) => {
57
- for (const root of roots) {
58
- for (const extension of pageExtensions) {
59
- const file = join(root, `${page}.${extension}`);
60
- if (existsSync(file)) {
61
- return file;
62
- }
63
- const fileAtFolderIndex = join(root, page, `index.${extension}`);
64
- if (existsSync(fileAtFolderIndex)) {
65
- return fileAtFolderIndex;
66
- }
67
- }
68
- }
69
- };
70
- var findModuleFromBase = ({
71
- paths,
72
- candidates
73
- }) => {
74
- for (const candidate of candidates) {
75
- try {
76
- const modulePath = __require.resolve(candidate, { paths });
77
- if (modulePath) {
78
- return modulePath;
79
- }
80
- } catch {
81
- }
82
- }
83
- for (const candidate of candidates) {
84
- try {
85
- const modulePath = __require.resolve(candidate);
86
- if (modulePath) {
87
- return modulePath;
88
- }
89
- } catch {
90
- }
91
- }
92
- return null;
93
- };
94
- var extractConstValue;
95
- var parseModule;
96
- var extractConfigFromFile = async (apiFilePath, appDir) => {
97
- if (!apiFilePath || !existsSync(apiFilePath)) {
98
- return {};
99
- }
100
- const extractConstValueModulePath = findModuleFromBase({
101
- paths: [appDir],
102
- candidates: ["next/dist/build/analysis/extract-const-value"]
103
- });
104
- const parseModulePath = findModuleFromBase({
105
- paths: [appDir],
106
- candidates: ["next/dist/build/analysis/parse-module"]
107
- });
108
- if (!extractConstValueModulePath || !parseModulePath) {
109
- return {};
110
- }
111
- if (!extractConstValue && extractConstValueModulePath) {
112
- extractConstValue = __require(extractConstValueModulePath);
113
- }
114
- if (!parseModule && parseModulePath) {
115
- parseModule = __require(parseModulePath).parseModule;
116
- }
117
- const { extractExportedConstValue } = extractConstValue;
118
- const fileContent = await readFile(apiFilePath, "utf8");
119
- if (!fileContent.includes("config")) {
120
- return {};
121
- }
122
- const ast = await parseModule(apiFilePath, fileContent);
123
- try {
124
- return extractExportedConstValue(ast, "config");
125
- } catch {
126
- return {};
127
- }
128
- };
129
-
130
- export {
131
- ApiRouteType,
132
- getAPIRoutesConfigs
133
- };
@@ -1,127 +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
- writeTagsManifest
12
- } from "./chunk-4BNHE6TP.js";
13
- import {
14
- wrapTracer
15
- } from "./chunk-PDPDW32D.js";
16
- import {
17
- init_esm,
18
- trace
19
- } from "./chunk-Y3K5Q6FP.js";
20
- import {
21
- require_out
22
- } from "./chunk-VZNKO4OO.js";
23
- import {
24
- SERVER_HANDLER_NAME
25
- } from "./chunk-L6OM53B6.js";
26
- import {
27
- __toESM
28
- } from "./chunk-5JVNISGM.js";
29
-
30
- // src/build/functions/server.ts
31
- init_esm();
32
- import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
33
- import { join, relative } from "node:path";
34
- import { join as posixJoin } from "node:path/posix";
35
- var import_fast_glob = __toESM(require_out(), 1);
36
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
37
- var copyHandlerDependencies = async (ctx) => {
38
- await tracer.withActiveSpan("copyHandlerDependencies", async (span) => {
39
- const promises = [];
40
- const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
41
- span.setAttribute("next.includedFiles", includedFiles.join(","));
42
- if (includedFiles.length !== 0) {
43
- const resolvedFiles = await Promise.all(
44
- includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
45
- );
46
- for (const filePath of resolvedFiles.flat()) {
47
- promises.push(
48
- cp(
49
- join(process.cwd(), filePath),
50
- // the serverHandlerDir is aware of the dist dir.
51
- // The distDir must not be the package path therefore we need to rely on the
52
- // serverHandlerDir instead of the serverHandlerRootDir
53
- // therefore we need to remove the package path from the filePath
54
- join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
55
- {
56
- recursive: true,
57
- force: true
58
- }
59
- )
60
- );
61
- }
62
- }
63
- const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
64
- for (const filePath of fileList) {
65
- promises.push(
66
- cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerDir, ".netlify", filePath), {
67
- recursive: true,
68
- force: true
69
- })
70
- );
71
- }
72
- await Promise.all(promises);
73
- });
74
- };
75
- var writeHandlerManifest = async (ctx) => {
76
- await writeFile(
77
- join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.json`),
78
- JSON.stringify({
79
- config: {
80
- name: "Next.js Server Handler",
81
- generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
82
- nodeBundler: "none",
83
- // the folders can vary in monorepos based on the folder structure of the user so we have to glob all
84
- includedFiles: ["**"],
85
- includedFilesBasePath: ctx.serverHandlerRootDir
86
- },
87
- version: 1
88
- }),
89
- "utf-8"
90
- );
91
- };
92
- var writePackageMetadata = async (ctx) => {
93
- await writeFile(
94
- join(ctx.serverHandlerRootDir, "package.json"),
95
- JSON.stringify({ type: "module" })
96
- );
97
- };
98
- var getHandlerFile = async (ctx) => {
99
- const templatesDir = join(ctx.pluginDir, "dist/build/templates");
100
- if (ctx.relativeAppDir.length !== 0) {
101
- const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
102
- return template.replaceAll("{{cwd}}", posixJoin(ctx.lambdaWorkingDirectory)).replace("{{nextServerHandler}}", posixJoin(ctx.nextServerHandler));
103
- }
104
- return await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8");
105
- };
106
- var writeHandlerFile = async (ctx) => {
107
- const handler = await getHandlerFile(ctx);
108
- await writeFile(join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.mjs`), handler);
109
- };
110
- var createServerHandler = async (ctx) => {
111
- await tracer.withActiveSpan("createServerHandler", async () => {
112
- await rm(ctx.serverFunctionsDir, { recursive: true, force: true });
113
- await mkdir(join(ctx.serverHandlerDir, ".netlify"), { recursive: true });
114
- await copyNextServerCode(ctx);
115
- await copyNextDependencies(ctx);
116
- await writeTagsManifest(ctx);
117
- await copyHandlerDependencies(ctx);
118
- await writeHandlerManifest(ctx);
119
- await writePackageMetadata(ctx);
120
- await writeHandlerFile(ctx);
121
- await verifyHandlerDirStructure(ctx);
122
- });
123
- };
124
-
125
- export {
126
- createServerHandler
127
- };