@netlify/plugin-nextjs 5.1.1 → 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-YB7ERSH4.js → package-ZBRSUKN7.js} +6 -6
  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-3NYX5FXN.js +0 -188
  29. package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
  30. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  31. package/dist/esm-chunks/chunk-74THQNRG.js +0 -110
  32. package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
  33. package/dist/esm-chunks/chunk-F5VQRN6L.js +0 -127
  34. package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
  35. package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
  36. package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
  37. package/dist/esm-chunks/chunk-OBKVBMAL.js +0 -524
  38. package/dist/esm-chunks/chunk-PH26UF2W.js +0 -86
  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-UYKENJEU.js +0 -19
  42. package/dist/esm-chunks/chunk-ZKJEJNSJ.js +0 -278
@@ -5,18 +5,137 @@
5
5
  })();
6
6
 
7
7
  import {
8
- createServerHandler
9
- } from "../../esm-chunks/chunk-F5VQRN6L.js";
10
- import "../../esm-chunks/chunk-ZKJEJNSJ.js";
11
- import "../../esm-chunks/chunk-PDPDW32D.js";
12
- import "../../esm-chunks/chunk-Y3K5Q6FP.js";
13
- import "../../esm-chunks/chunk-VZNKO4OO.js";
14
- import "../../esm-chunks/chunk-3NYX5FXN.js";
15
- import "../../esm-chunks/chunk-PH26UF2W.js";
16
- import "../../esm-chunks/chunk-PJG75HGC.js";
17
- import "../../esm-chunks/chunk-BG455SFE.js";
18
- import "../../esm-chunks/chunk-UYKENJEU.js";
19
- import "../../esm-chunks/chunk-5JVNISGM.js";
8
+ require_out
9
+ } from "../../esm-chunks/chunk-VZNKO4OO.js";
10
+ import {
11
+ wrapTracer
12
+ } from "../../esm-chunks/chunk-PDPDW32D.js";
13
+ import {
14
+ init_esm,
15
+ trace
16
+ } from "../../esm-chunks/chunk-Y3K5Q6FP.js";
17
+ import {
18
+ __toESM
19
+ } from "../../esm-chunks/chunk-5JVNISGM.js";
20
+
21
+ // src/build/functions/server.ts
22
+ init_esm();
23
+ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
24
+ import { join, relative } from "node:path";
25
+ import { join as posixJoin } from "node:path/posix";
26
+ var import_fast_glob = __toESM(require_out(), 1);
27
+ import {
28
+ copyNextDependencies,
29
+ copyNextServerCode,
30
+ verifyHandlerDirStructure,
31
+ writeTagsManifest
32
+ } from "../content/server.js";
33
+ import { SERVER_HANDLER_NAME } from "../plugin-context.js";
34
+ var tracer = wrapTracer(trace.getTracer("Next runtime"));
35
+ var copyHandlerDependencies = async (ctx) => {
36
+ await tracer.withActiveSpan("copyHandlerDependencies", async (span) => {
37
+ const promises = [];
38
+ const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
39
+ includedFiles.push(
40
+ posixJoin(ctx.relativeAppDir, ".env"),
41
+ posixJoin(ctx.relativeAppDir, ".env.production"),
42
+ posixJoin(ctx.relativeAppDir, ".env.local"),
43
+ posixJoin(ctx.relativeAppDir, ".env.production.local")
44
+ );
45
+ span.setAttribute("next.includedFiles", includedFiles.join(","));
46
+ const resolvedFiles = await Promise.all(
47
+ includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
48
+ );
49
+ for (const filePath of resolvedFiles.flat()) {
50
+ promises.push(
51
+ cp(
52
+ join(process.cwd(), filePath),
53
+ // the serverHandlerDir is aware of the dist dir.
54
+ // The distDir must not be the package path therefore we need to rely on the
55
+ // serverHandlerDir instead of the serverHandlerRootDir
56
+ // therefore we need to remove the package path from the filePath
57
+ join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
58
+ {
59
+ recursive: true,
60
+ force: true
61
+ }
62
+ )
63
+ );
64
+ }
65
+ const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
66
+ for (const filePath of fileList) {
67
+ promises.push(
68
+ cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerDir, ".netlify", filePath), {
69
+ recursive: true,
70
+ force: true
71
+ })
72
+ );
73
+ }
74
+ await Promise.all(promises);
75
+ });
76
+ };
77
+ var writeHandlerManifest = async (ctx) => {
78
+ await writeFile(
79
+ join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.json`),
80
+ JSON.stringify({
81
+ config: {
82
+ name: "Next.js Server Handler",
83
+ generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
84
+ nodeBundler: "none",
85
+ // the folders can vary in monorepos based on the folder structure of the user so we have to glob all
86
+ includedFiles: ["**"],
87
+ includedFilesBasePath: ctx.serverHandlerRootDir
88
+ },
89
+ version: 1
90
+ }),
91
+ "utf-8"
92
+ );
93
+ };
94
+ var writePackageMetadata = async (ctx) => {
95
+ await writeFile(
96
+ join(ctx.serverHandlerRootDir, "package.json"),
97
+ JSON.stringify({ type: "module" })
98
+ );
99
+ };
100
+ var applyTemplateVariables = (template, variables) => {
101
+ return Object.entries(variables).reduce((acc, [key, value]) => {
102
+ return acc.replaceAll(key, value);
103
+ }, template);
104
+ };
105
+ var getHandlerFile = async (ctx) => {
106
+ const templatesDir = join(ctx.pluginDir, "dist/build/templates");
107
+ const templateVariables = {
108
+ "{{useRegionalBlobs}}": ctx.useRegionalBlobs.toString()
109
+ };
110
+ if (ctx.relativeAppDir.length !== 0) {
111
+ const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
112
+ templateVariables["{{cwd}}"] = posixJoin(ctx.lambdaWorkingDirectory);
113
+ templateVariables["{{nextServerHandler}}"] = posixJoin(ctx.nextServerHandler);
114
+ return applyTemplateVariables(template, templateVariables);
115
+ }
116
+ return applyTemplateVariables(
117
+ await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8"),
118
+ templateVariables
119
+ );
120
+ };
121
+ var writeHandlerFile = async (ctx) => {
122
+ const handler = await getHandlerFile(ctx);
123
+ await writeFile(join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.mjs`), handler);
124
+ };
125
+ var createServerHandler = async (ctx) => {
126
+ await tracer.withActiveSpan("createServerHandler", async () => {
127
+ await rm(ctx.serverFunctionsDir, { recursive: true, force: true });
128
+ await mkdir(join(ctx.serverHandlerDir, ".netlify"), { recursive: true });
129
+ await copyNextServerCode(ctx);
130
+ await copyNextDependencies(ctx);
131
+ await writeTagsManifest(ctx);
132
+ await copyHandlerDependencies(ctx);
133
+ await writeHandlerManifest(ctx);
134
+ await writePackageMetadata(ctx);
135
+ await writeHandlerFile(ctx);
136
+ await verifyHandlerDirStructure(ctx);
137
+ });
138
+ };
20
139
  export {
21
140
  createServerHandler
22
141
  };