@netlify/plugin-nextjs 5.10.0 → 5.10.2
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/LICENSE +22 -0
- 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-7HACW4PO.js} +11 -10
- package/dist/index.js +19 -40
- package/dist/run/config.js +6 -7
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +93 -1713
- package/dist/run/handlers/request-context.cjs +10 -3
- package/dist/run/handlers/server.js +14 -34
- package/dist/run/handlers/tracer.cjs +17 -116
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +183 -10
- package/dist/run/next.cjs +10 -1625
- package/dist/run/revalidate.js +24 -3
- package/dist/run/{regional-blob-store.cjs → storage/regional-blob-store.cjs} +44 -8
- package/dist/run/storage/request-scoped-in-memory-cache.cjs +1475 -0
- package/dist/run/storage/storage.cjs +84 -0
- package/dist/shared/blob-types.cjs +37 -0
- 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
|
@@ -5,17 +5,225 @@
|
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
|
|
8
|
+
wrapTracer
|
|
9
|
+
} from "../../esm-chunks/chunk-5QSXBV7L.js";
|
|
10
|
+
import {
|
|
11
|
+
init_esm,
|
|
12
|
+
trace
|
|
13
|
+
} from "../../esm-chunks/chunk-GNGHTHMQ.js";
|
|
14
|
+
import {
|
|
15
|
+
require_out
|
|
16
|
+
} from "../../esm-chunks/chunk-KGYJQ2U2.js";
|
|
17
|
+
import {
|
|
18
|
+
require_semver
|
|
19
|
+
} from "../../esm-chunks/chunk-APO262HE.js";
|
|
20
|
+
import {
|
|
21
|
+
__toESM
|
|
22
|
+
} from "../../esm-chunks/chunk-OEQOKJGE.js";
|
|
23
|
+
|
|
24
|
+
// src/build/content/server.ts
|
|
25
|
+
init_esm();
|
|
26
|
+
import { existsSync } from "node:fs";
|
|
27
|
+
import {
|
|
28
|
+
access,
|
|
29
|
+
cp,
|
|
30
|
+
mkdir,
|
|
31
|
+
readdir,
|
|
32
|
+
readFile,
|
|
33
|
+
readlink,
|
|
34
|
+
symlink,
|
|
35
|
+
writeFile
|
|
36
|
+
} from "node:fs/promises";
|
|
37
|
+
import { createRequire } from "node:module";
|
|
38
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
39
|
+
import { join as posixJoin, sep as posixSep } from "node:path/posix";
|
|
40
|
+
var import_fast_glob = __toESM(require_out(), 1);
|
|
41
|
+
var import_semver = __toESM(require_semver(), 1);
|
|
42
|
+
import { RUN_CONFIG } from "../../run/constants.js";
|
|
43
|
+
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
44
|
+
var toPosixPath = (path) => path.split(sep).join(posixSep);
|
|
45
|
+
function isError(error) {
|
|
46
|
+
return error instanceof Error;
|
|
47
|
+
}
|
|
48
|
+
var copyNextServerCode = async (ctx) => {
|
|
49
|
+
await tracer.withActiveSpan("copyNextServerCode", async () => {
|
|
50
|
+
const reqServerFilesPath = join(
|
|
51
|
+
ctx.standaloneRootDir,
|
|
52
|
+
ctx.relativeAppDir,
|
|
53
|
+
ctx.requiredServerFiles.config.distDir,
|
|
54
|
+
"required-server-files.json"
|
|
55
|
+
);
|
|
56
|
+
try {
|
|
57
|
+
await access(reqServerFilesPath);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (isError(error) && error.code === "ENOENT") {
|
|
60
|
+
ctx.failBuild(
|
|
61
|
+
`Failed creating server handler. required-server-files.json file not found at expected location "${reqServerFilesPath}". Your repository setup is currently not yet supported.`
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
|
|
68
|
+
if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.relativeAppDir}/?`), "") !== reqServerFiles.config.distDir) {
|
|
69
|
+
reqServerFiles.config.distDir = ctx.nextDistDir;
|
|
70
|
+
await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
|
|
71
|
+
}
|
|
72
|
+
await mkdir(ctx.serverHandlerDir, { recursive: true });
|
|
73
|
+
await writeFile(
|
|
74
|
+
join(ctx.serverHandlerDir, RUN_CONFIG),
|
|
75
|
+
JSON.stringify(reqServerFiles.config),
|
|
76
|
+
"utf-8"
|
|
77
|
+
);
|
|
78
|
+
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
79
|
+
const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
|
|
80
|
+
const destDir = join(ctx.serverHandlerDir, nextFolder);
|
|
81
|
+
const paths = await (0, import_fast_glob.default)(
|
|
82
|
+
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
|
|
83
|
+
{
|
|
84
|
+
cwd: srcDir,
|
|
85
|
+
extglob: true
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
await Promise.all(
|
|
89
|
+
paths.map(async (path) => {
|
|
90
|
+
const srcPath = join(srcDir, path);
|
|
91
|
+
const destPath = join(destDir, path);
|
|
92
|
+
if (path === "server/middleware-manifest.json") {
|
|
93
|
+
try {
|
|
94
|
+
await replaceMiddlewareManifest(srcPath, destPath);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
throw new Error("Could not patch middleware manifest file", { cause: error });
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
await cp(srcPath, destPath, { recursive: true, force: true });
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
async function recreateNodeModuleSymlinks(src, dest, org) {
|
|
106
|
+
const dirents = await readdir(join(src, org || ""), { withFileTypes: true });
|
|
107
|
+
await Promise.all(
|
|
108
|
+
dirents.map(async (dirent) => {
|
|
109
|
+
if (dirent.name.startsWith("@")) {
|
|
110
|
+
return recreateNodeModuleSymlinks(src, dest, dirent.name);
|
|
111
|
+
}
|
|
112
|
+
if (dirent.isSymbolicLink()) {
|
|
113
|
+
const symlinkSrc = join(dest, org || "", dirent.name);
|
|
114
|
+
const symlinkTarget = await readlink(join(src, org || "", dirent.name));
|
|
115
|
+
const symlinkDest = join(dest, org || "", symlinkTarget);
|
|
116
|
+
if (existsSync(symlinkDest) && !existsSync(symlinkSrc)) {
|
|
117
|
+
if (org) {
|
|
118
|
+
await mkdir(join(dest, org), { recursive: true });
|
|
119
|
+
}
|
|
120
|
+
await symlink(symlinkTarget, symlinkSrc);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
var nextInternalModuleReplacements = [
|
|
127
|
+
{
|
|
128
|
+
// standalone is loading expensive Telemetry module that is not actually used
|
|
129
|
+
// so this replace that module with lightweight no-op shim that doesn't load additional modules
|
|
130
|
+
// see https://github.com/vercel/next.js/pull/63574 that removed need for this shim
|
|
131
|
+
ongoing: false,
|
|
132
|
+
minVersion: "13.5.0-canary.0",
|
|
133
|
+
// perf released in https://github.com/vercel/next.js/releases/tag/v14.2.0-canary.43
|
|
134
|
+
maxVersion: "14.2.0-canary.42",
|
|
135
|
+
nextModule: "next/dist/telemetry/storage.js",
|
|
136
|
+
shimModule: "./next-shims/telemetry-storage.cjs"
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
function getPatchesToApply(nextVersion, patches = nextInternalModuleReplacements) {
|
|
140
|
+
return patches.filter((patch) => {
|
|
141
|
+
if ((0, import_semver.lt)(nextVersion, patch.minVersion)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (patch.ongoing) {
|
|
145
|
+
if ((0, import_semver.prerelease)(nextVersion) || process.env.NETLIFY_NEXT_FORCE_APPLY_ONGOING_PATCHES) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return (0, import_semver.lte)(nextVersion, patch.maxStableVersion);
|
|
149
|
+
}
|
|
150
|
+
return (0, import_semver.lte)(nextVersion, patch.maxVersion);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function patchNextModules(ctx, nextVersion, serverHandlerRequireResolve) {
|
|
154
|
+
const moduleReplacementsToApply = getPatchesToApply(nextVersion);
|
|
155
|
+
if (moduleReplacementsToApply.length !== 0) {
|
|
156
|
+
await Promise.all(
|
|
157
|
+
moduleReplacementsToApply.map(async ({ nextModule, shimModule }) => {
|
|
158
|
+
try {
|
|
159
|
+
const nextModulePath = serverHandlerRequireResolve(nextModule);
|
|
160
|
+
const shimModulePath = posixJoin(ctx.pluginDir, "dist", "build", "content", shimModule);
|
|
161
|
+
await cp(shimModulePath, nextModulePath, { force: true });
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
var copyNextDependencies = async (ctx) => {
|
|
169
|
+
await tracer.withActiveSpan("copyNextDependencies", async () => {
|
|
170
|
+
const entries = await readdir(ctx.standaloneDir);
|
|
171
|
+
const promises = entries.map(async (entry) => {
|
|
172
|
+
if (entry === ctx.nextDistDir) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const src = join(ctx.standaloneDir, entry);
|
|
176
|
+
const dest = join(ctx.serverHandlerDir, entry);
|
|
177
|
+
await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
|
|
178
|
+
if (entry === "node_modules") {
|
|
179
|
+
await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir("node_modules"), dest);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
|
|
183
|
+
const rootDestDir = join(ctx.serverHandlerRootDir, "node_modules");
|
|
184
|
+
if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
|
|
185
|
+
promises.push(
|
|
186
|
+
cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(
|
|
187
|
+
() => recreateNodeModuleSymlinks(resolve("node_modules"), rootDestDir)
|
|
188
|
+
)
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
await Promise.all(promises);
|
|
192
|
+
const serverHandlerRequire = createRequire(posixJoin(ctx.serverHandlerDir, ":internal:"));
|
|
193
|
+
if (ctx.nextVersion) {
|
|
194
|
+
await patchNextModules(ctx, ctx.nextVersion, serverHandlerRequire.resolve);
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const nextEntryAbsolutePath = serverHandlerRequire.resolve("next");
|
|
198
|
+
const nextRequire = createRequire(nextEntryAbsolutePath);
|
|
199
|
+
nextRequire.resolve("styled-jsx");
|
|
200
|
+
} catch {
|
|
201
|
+
throw new Error(
|
|
202
|
+
"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"
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
var replaceMiddlewareManifest = async (sourcePath, destPath) => {
|
|
208
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
209
|
+
const data = await readFile(sourcePath, "utf8");
|
|
210
|
+
const manifest = JSON.parse(data);
|
|
211
|
+
const newManifest = {
|
|
212
|
+
...manifest,
|
|
213
|
+
middleware: {}
|
|
214
|
+
};
|
|
215
|
+
const newData = JSON.stringify(newManifest);
|
|
216
|
+
await writeFile(destPath, newData);
|
|
217
|
+
};
|
|
218
|
+
var verifyHandlerDirStructure = async (ctx) => {
|
|
219
|
+
const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
|
|
220
|
+
const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
|
|
221
|
+
if (!existsSync(expectedBuildIDPath)) {
|
|
222
|
+
ctx.failBuild(
|
|
223
|
+
`Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".`
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
19
227
|
export {
|
|
20
228
|
copyNextDependencies,
|
|
21
229
|
copyNextServerCode,
|
|
@@ -5,21 +5,118 @@
|
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
wrapTracer
|
|
9
|
+
} from "../../esm-chunks/chunk-5QSXBV7L.js";
|
|
10
|
+
import {
|
|
11
|
+
init_esm,
|
|
12
|
+
trace
|
|
13
|
+
} from "../../esm-chunks/chunk-GNGHTHMQ.js";
|
|
14
|
+
import {
|
|
15
|
+
require_out
|
|
16
|
+
} from "../../esm-chunks/chunk-KGYJQ2U2.js";
|
|
17
|
+
import {
|
|
18
|
+
__toESM
|
|
19
|
+
} from "../../esm-chunks/chunk-OEQOKJGE.js";
|
|
20
|
+
|
|
21
|
+
// src/build/content/static.ts
|
|
22
|
+
init_esm();
|
|
23
|
+
import { existsSync } from "node:fs";
|
|
24
|
+
import { cp, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
25
|
+
import { basename, join } from "node:path";
|
|
26
|
+
var import_fast_glob = __toESM(require_out(), 1);
|
|
27
|
+
import { encodeBlobKey } from "../../shared/blobkey.js";
|
|
28
|
+
import { verifyNetlifyForms } from "../verification.js";
|
|
29
|
+
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
30
|
+
var copyStaticContent = async (ctx) => {
|
|
31
|
+
return tracer.withActiveSpan("copyStaticContent", async () => {
|
|
32
|
+
const srcDir = join(ctx.publishDir, "server/pages");
|
|
33
|
+
const destDir = ctx.blobDir;
|
|
34
|
+
const paths = await (0, import_fast_glob.default)("**/*.+(html|json)", {
|
|
35
|
+
cwd: srcDir,
|
|
36
|
+
extglob: true
|
|
37
|
+
});
|
|
38
|
+
const fallbacks = ctx.getFallbacks(await ctx.getPrerenderManifest());
|
|
39
|
+
try {
|
|
40
|
+
await mkdir(destDir, { recursive: true });
|
|
41
|
+
await Promise.all(
|
|
42
|
+
paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
|
|
43
|
+
const html = await readFile(join(srcDir, path), "utf-8");
|
|
44
|
+
verifyNetlifyForms(ctx, html);
|
|
45
|
+
const isFallback = fallbacks.includes(path.slice(0, -5));
|
|
46
|
+
await writeFile(
|
|
47
|
+
join(destDir, await encodeBlobKey(path)),
|
|
48
|
+
JSON.stringify({ html, isFallback }),
|
|
49
|
+
"utf-8"
|
|
50
|
+
);
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
ctx.failBuild("Failed assembling static pages for upload", error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
var copyStaticAssets = async (ctx) => {
|
|
59
|
+
return tracer.withActiveSpan("copyStaticAssets", async (span) => {
|
|
60
|
+
try {
|
|
61
|
+
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
62
|
+
const { basePath } = await ctx.getRoutesManifest();
|
|
63
|
+
if (existsSync(ctx.resolveFromSiteDir("public"))) {
|
|
64
|
+
await cp(ctx.resolveFromSiteDir("public"), join(ctx.staticDir, basePath), {
|
|
65
|
+
recursive: true
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (existsSync(join(ctx.publishDir, "static"))) {
|
|
69
|
+
await cp(join(ctx.publishDir, "static"), join(ctx.staticDir, basePath, "_next/static"), {
|
|
70
|
+
recursive: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} catch (error) {
|
|
74
|
+
span.end();
|
|
75
|
+
ctx.failBuild("Failed copying static assets", error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var setHeadersConfig = async (ctx) => {
|
|
80
|
+
const { basePath } = ctx.buildConfig;
|
|
81
|
+
ctx.netlifyConfig.headers.push({
|
|
82
|
+
for: `${basePath}/_next/static/*`,
|
|
83
|
+
values: {
|
|
84
|
+
"Cache-Control": "public, max-age=31536000, immutable"
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
var copyStaticExport = async (ctx) => {
|
|
89
|
+
await tracer.withActiveSpan("copyStaticExport", async () => {
|
|
90
|
+
if (!ctx.exportDetail?.outDirectory) {
|
|
91
|
+
ctx.failBuild("Export directory not found");
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
95
|
+
await cp(ctx.exportDetail.outDirectory, ctx.staticDir, { recursive: true });
|
|
96
|
+
} catch (error) {
|
|
97
|
+
ctx.failBuild("Failed copying static export", error);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
var publishStaticDir = async (ctx) => {
|
|
102
|
+
try {
|
|
103
|
+
await rm(ctx.tempPublishDir, { recursive: true, force: true });
|
|
104
|
+
await mkdir(basename(ctx.tempPublishDir), { recursive: true });
|
|
105
|
+
await rename(ctx.publishDir, ctx.tempPublishDir);
|
|
106
|
+
await rename(ctx.staticDir, ctx.publishDir);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
ctx.failBuild("Failed publishing static content", error instanceof Error ? { error } : {});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var unpublishStaticDir = async (ctx) => {
|
|
112
|
+
try {
|
|
113
|
+
if (existsSync(ctx.tempPublishDir)) {
|
|
114
|
+
await rename(ctx.publishDir, ctx.staticDir);
|
|
115
|
+
await rename(ctx.tempPublishDir, ctx.publishDir);
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
};
|
|
23
120
|
export {
|
|
24
121
|
copyStaticAssets,
|
|
25
122
|
copyStaticContent,
|