@netlify/plugin-nextjs 5.10.0-fetch-patch-logs → 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.
Files changed (43) hide show
  1. package/dist/build/advanced-api-routes.js +136 -4
  2. package/dist/build/cache.js +25 -4
  3. package/dist/build/content/prerendered.js +293 -11
  4. package/dist/build/content/server.js +219 -11
  5. package/dist/build/content/static.js +112 -15
  6. package/dist/build/functions/edge.js +540 -7
  7. package/dist/build/functions/server.js +130 -11
  8. package/dist/build/image-cdn.js +1599 -3
  9. package/dist/build/plugin-context.js +292 -6
  10. package/dist/build/verification.js +104 -9
  11. package/dist/esm-chunks/{package-F536DQ6H.js → package-UN6EVEHD.js} +1 -1
  12. package/dist/index.js +18 -39
  13. package/dist/run/config.js +1 -4
  14. package/dist/run/constants.js +7 -5
  15. package/dist/run/handlers/cache.cjs +44 -1655
  16. package/dist/run/handlers/server.js +14 -33
  17. package/dist/run/handlers/tracer.cjs +2 -114
  18. package/dist/run/handlers/tracing.js +2 -4
  19. package/dist/run/handlers/wait-until.cjs +2 -116
  20. package/dist/run/headers.js +198 -10
  21. package/dist/run/next.cjs +11 -1624
  22. package/dist/run/regional-blob-store.cjs +37 -5
  23. package/dist/run/revalidate.js +24 -3
  24. package/dist/shared/blobkey.js +15 -3
  25. package/package.json +1 -1
  26. package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
  27. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  28. package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
  29. package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
  30. package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
  31. package/dist/esm-chunks/chunk-HXVWGXWM.js +0 -218
  32. package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
  33. package/dist/esm-chunks/chunk-JPTD4GEB.js +0 -309
  34. package/dist/esm-chunks/chunk-MKMK7FBF.js +0 -132
  35. package/dist/esm-chunks/chunk-RYJYZQ4X.js +0 -610
  36. package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
  37. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  38. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  39. package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
  40. package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
  41. package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
  42. package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
  43. package/dist/esm-chunks/next-LDOXJ7XH.js +0 -567
@@ -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
- };
@@ -1,309 +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
- encodeBlobKey
9
- } from "./chunk-TYCYFZ22.js";
10
- import {
11
- wrapTracer
12
- } from "./chunk-5QSXBV7L.js";
13
- import {
14
- init_esm,
15
- trace
16
- } from "./chunk-GNGHTHMQ.js";
17
- import {
18
- verifyNetlifyForms
19
- } from "./chunk-ZSVHJNNY.js";
20
- import {
21
- require_out
22
- } from "./chunk-KGYJQ2U2.js";
23
- import {
24
- require_semver
25
- } from "./chunk-APO262HE.js";
26
- import {
27
- __toESM
28
- } from "./chunk-OEQOKJGE.js";
29
-
30
- // src/build/content/prerendered.ts
31
- init_esm();
32
- import { existsSync } from "node:fs";
33
- import { mkdir, readFile, writeFile } from "node:fs/promises";
34
- import { join } from "node:path";
35
- var import_fast_glob = __toESM(require_out(), 1);
36
-
37
- // node_modules/yocto-queue/index.js
38
- var Node = class {
39
- value;
40
- next;
41
- constructor(value) {
42
- this.value = value;
43
- }
44
- };
45
- var Queue = class {
46
- #head;
47
- #tail;
48
- #size;
49
- constructor() {
50
- this.clear();
51
- }
52
- enqueue(value) {
53
- const node = new Node(value);
54
- if (this.#head) {
55
- this.#tail.next = node;
56
- this.#tail = node;
57
- } else {
58
- this.#head = node;
59
- this.#tail = node;
60
- }
61
- this.#size++;
62
- }
63
- dequeue() {
64
- const current = this.#head;
65
- if (!current) {
66
- return;
67
- }
68
- this.#head = this.#head.next;
69
- this.#size--;
70
- return current.value;
71
- }
72
- clear() {
73
- this.#head = void 0;
74
- this.#tail = void 0;
75
- this.#size = 0;
76
- }
77
- get size() {
78
- return this.#size;
79
- }
80
- *[Symbol.iterator]() {
81
- let current = this.#head;
82
- while (current) {
83
- yield current.value;
84
- current = current.next;
85
- }
86
- }
87
- };
88
-
89
- // node_modules/p-limit/index.js
90
- import { AsyncResource } from "async_hooks";
91
- function pLimit(concurrency) {
92
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
93
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
94
- }
95
- const queue = new Queue();
96
- let activeCount = 0;
97
- const next = () => {
98
- activeCount--;
99
- if (queue.size > 0) {
100
- queue.dequeue()();
101
- }
102
- };
103
- const run = async (function_, resolve, arguments_) => {
104
- activeCount++;
105
- const result = (async () => function_(...arguments_))();
106
- resolve(result);
107
- try {
108
- await result;
109
- } catch {
110
- }
111
- next();
112
- };
113
- const enqueue = (function_, resolve, arguments_) => {
114
- queue.enqueue(
115
- AsyncResource.bind(run.bind(void 0, function_, resolve, arguments_))
116
- );
117
- (async () => {
118
- await Promise.resolve();
119
- if (activeCount < concurrency && queue.size > 0) {
120
- queue.dequeue()();
121
- }
122
- })();
123
- };
124
- const generator = (function_, ...arguments_) => new Promise((resolve) => {
125
- enqueue(function_, resolve, arguments_);
126
- });
127
- Object.defineProperties(generator, {
128
- activeCount: {
129
- get: () => activeCount
130
- },
131
- pendingCount: {
132
- get: () => queue.size
133
- },
134
- clearQueue: {
135
- value() {
136
- queue.clear();
137
- }
138
- }
139
- });
140
- return generator;
141
- }
142
-
143
- // src/build/content/prerendered.ts
144
- var import_semver = __toESM(require_semver(), 1);
145
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
146
- var writeCacheEntry = async (route, value, lastModified, ctx) => {
147
- const path = join(ctx.blobDir, await encodeBlobKey(route));
148
- const entry = JSON.stringify({
149
- lastModified,
150
- value
151
- });
152
- await writeFile(path, entry, "utf-8");
153
- };
154
- var routeToFilePath = (path) => {
155
- if (path === "/") {
156
- return "/index";
157
- }
158
- if (path.startsWith("/")) {
159
- return path;
160
- }
161
- return `/${path}`;
162
- };
163
- var buildPagesCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind, shouldSkipJson = false) => ({
164
- kind: shouldUseEnumKind ? "PAGES" : "PAGE",
165
- html: await readFile(`${path}.html`, "utf-8"),
166
- pageData: shouldSkipJson ? {} : JSON.parse(await readFile(`${path}.json`, "utf-8")),
167
- headers: void 0,
168
- status: void 0,
169
- revalidate: initialRevalidateSeconds
170
- });
171
- var buildAppCacheValue = async (path, shouldUseAppPageKind) => {
172
- const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8"));
173
- const html = await readFile(`${path}.html`, "utf-8");
174
- if (shouldUseAppPageKind) {
175
- return {
176
- kind: "APP_PAGE",
177
- html,
178
- rscData: await readFile(`${path}.rsc`, "base64").catch(
179
- () => readFile(`${path}.prefetch.rsc`, "base64")
180
- ),
181
- ...meta
182
- };
183
- }
184
- const rsc = await readFile(`${path}.rsc`, "utf-8").catch(
185
- () => readFile(`${path}.prefetch.rsc`, "utf-8")
186
- );
187
- if (!meta.status && rsc.includes("NEXT_NOT_FOUND") && !meta.headers["x-next-cache-tags"].includes("/@")) {
188
- meta.status = 404;
189
- }
190
- return {
191
- kind: "PAGE",
192
- html,
193
- pageData: rsc,
194
- ...meta
195
- };
196
- };
197
- var buildRouteCacheValue = async (path, initialRevalidateSeconds, shouldUseEnumKind) => ({
198
- kind: shouldUseEnumKind ? "APP_ROUTE" : "ROUTE",
199
- body: await readFile(`${path}.body`, "base64"),
200
- ...JSON.parse(await readFile(`${path}.meta`, "utf-8")),
201
- revalidate: initialRevalidateSeconds
202
- });
203
- var buildFetchCacheValue = async (path) => ({
204
- kind: "FETCH",
205
- ...JSON.parse(await readFile(path, "utf-8"))
206
- });
207
- var copyPrerenderedContent = async (ctx) => {
208
- return tracer.withActiveSpan("copyPrerenderedContent", async () => {
209
- try {
210
- await mkdir(ctx.blobDir, { recursive: true });
211
- const manifest = await ctx.getPrerenderManifest();
212
- const limitConcurrentPrerenderContentHandling = pLimit(10);
213
- const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", {
214
- includePrerelease: true
215
- }) : false;
216
- const shouldUseEnumKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.114 <15.0.0-d || >15.0.0-rc.0", {
217
- includePrerelease: true
218
- }) : false;
219
- await Promise.all([
220
- ...Object.entries(manifest.routes).map(
221
- ([route, meta]) => limitConcurrentPrerenderContentHandling(async () => {
222
- const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
223
- const key = routeToFilePath(route);
224
- let value;
225
- switch (true) {
226
- // Parallel route default layout has no prerendered page
227
- case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
228
- return;
229
- case meta.dataRoute?.endsWith(".json"):
230
- if (manifest.notFoundRoutes.includes(route)) {
231
- return;
232
- }
233
- value = await buildPagesCacheValue(
234
- join(ctx.publishDir, "server/pages", key),
235
- meta.initialRevalidateSeconds,
236
- shouldUseEnumKind
237
- );
238
- break;
239
- case meta.dataRoute?.endsWith(".rsc"):
240
- value = await buildAppCacheValue(
241
- join(ctx.publishDir, "server/app", key),
242
- shouldUseAppPageKind
243
- );
244
- break;
245
- case meta.dataRoute === null:
246
- value = await buildRouteCacheValue(
247
- join(ctx.publishDir, "server/app", key),
248
- meta.initialRevalidateSeconds,
249
- shouldUseEnumKind
250
- );
251
- break;
252
- default:
253
- throw new Error(`Unrecognized content: ${route}`);
254
- }
255
- if (value.kind === "PAGE" || value.kind === "PAGES" || value.kind === "APP_PAGE") {
256
- verifyNetlifyForms(ctx, value.html);
257
- }
258
- await writeCacheEntry(key, value, lastModified, ctx);
259
- })
260
- ),
261
- ...ctx.getFallbacks(manifest).map(async (route) => {
262
- const key = routeToFilePath(route);
263
- const value = await buildPagesCacheValue(
264
- join(ctx.publishDir, "server/pages", key),
265
- void 0,
266
- shouldUseEnumKind,
267
- true
268
- // there is no corresponding json file for fallback, so we are skipping it for this entry
269
- );
270
- await writeCacheEntry(key, value, Date.now(), ctx);
271
- })
272
- ]);
273
- if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
274
- const lastModified = Date.now();
275
- const key = "/404";
276
- const value = await buildAppCacheValue(
277
- join(ctx.publishDir, "server/app/_not-found"),
278
- shouldUseAppPageKind
279
- );
280
- await writeCacheEntry(key, value, lastModified, ctx);
281
- }
282
- } catch (error) {
283
- ctx.failBuild("Failed assembling prerendered content for upload", error);
284
- }
285
- });
286
- };
287
- var copyFetchContent = async (ctx) => {
288
- try {
289
- const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
290
- cwd: join(ctx.publishDir, "cache/fetch-cache"),
291
- extglob: true
292
- });
293
- await Promise.all(
294
- paths.map(async (key) => {
295
- const lastModified = Date.now() - 31536e6;
296
- const path = join(ctx.publishDir, "cache/fetch-cache", key);
297
- const value = await buildFetchCacheValue(path);
298
- await writeCacheEntry(key, value, lastModified, ctx);
299
- })
300
- );
301
- } catch (error) {
302
- ctx.failBuild("Failed assembling fetch content for upload", error);
303
- }
304
- };
305
-
306
- export {
307
- copyPrerenderedContent,
308
- copyFetchContent
309
- };
@@ -1,132 +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
- encodeBlobKey
9
- } from "./chunk-TYCYFZ22.js";
10
- import {
11
- wrapTracer
12
- } from "./chunk-5QSXBV7L.js";
13
- import {
14
- init_esm,
15
- trace
16
- } from "./chunk-GNGHTHMQ.js";
17
- import {
18
- verifyNetlifyForms
19
- } from "./chunk-ZSVHJNNY.js";
20
- import {
21
- require_out
22
- } from "./chunk-KGYJQ2U2.js";
23
- import {
24
- __toESM
25
- } from "./chunk-OEQOKJGE.js";
26
-
27
- // src/build/content/static.ts
28
- init_esm();
29
- import { existsSync } from "node:fs";
30
- import { cp, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
31
- import { basename, join } from "node:path";
32
- var import_fast_glob = __toESM(require_out(), 1);
33
- var tracer = wrapTracer(trace.getTracer("Next runtime"));
34
- var copyStaticContent = async (ctx) => {
35
- return tracer.withActiveSpan("copyStaticContent", async () => {
36
- const srcDir = join(ctx.publishDir, "server/pages");
37
- const destDir = ctx.blobDir;
38
- const paths = await (0, import_fast_glob.default)("**/*.+(html|json)", {
39
- cwd: srcDir,
40
- extglob: true
41
- });
42
- const fallbacks = ctx.getFallbacks(await ctx.getPrerenderManifest());
43
- try {
44
- await mkdir(destDir, { recursive: true });
45
- await Promise.all(
46
- paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
47
- const html = await readFile(join(srcDir, path), "utf-8");
48
- verifyNetlifyForms(ctx, html);
49
- const isFallback = fallbacks.includes(path.slice(0, -5));
50
- await writeFile(
51
- join(destDir, await encodeBlobKey(path)),
52
- JSON.stringify({ html, isFallback }),
53
- "utf-8"
54
- );
55
- })
56
- );
57
- } catch (error) {
58
- ctx.failBuild("Failed assembling static pages for upload", error);
59
- }
60
- });
61
- };
62
- var copyStaticAssets = async (ctx) => {
63
- return tracer.withActiveSpan("copyStaticAssets", async (span) => {
64
- try {
65
- await rm(ctx.staticDir, { recursive: true, force: true });
66
- const { basePath } = await ctx.getRoutesManifest();
67
- if (existsSync(ctx.resolveFromSiteDir("public"))) {
68
- await cp(ctx.resolveFromSiteDir("public"), join(ctx.staticDir, basePath), {
69
- recursive: true
70
- });
71
- }
72
- if (existsSync(join(ctx.publishDir, "static"))) {
73
- await cp(join(ctx.publishDir, "static"), join(ctx.staticDir, basePath, "_next/static"), {
74
- recursive: true
75
- });
76
- }
77
- } catch (error) {
78
- span.end();
79
- ctx.failBuild("Failed copying static assets", error);
80
- }
81
- });
82
- };
83
- var setHeadersConfig = async (ctx) => {
84
- const { basePath } = ctx.buildConfig;
85
- ctx.netlifyConfig.headers.push({
86
- for: `${basePath}/_next/static/*`,
87
- values: {
88
- "Cache-Control": "public, max-age=31536000, immutable"
89
- }
90
- });
91
- };
92
- var copyStaticExport = async (ctx) => {
93
- await tracer.withActiveSpan("copyStaticExport", async () => {
94
- if (!ctx.exportDetail?.outDirectory) {
95
- ctx.failBuild("Export directory not found");
96
- }
97
- try {
98
- await rm(ctx.staticDir, { recursive: true, force: true });
99
- await cp(ctx.exportDetail.outDirectory, ctx.staticDir, { recursive: true });
100
- } catch (error) {
101
- ctx.failBuild("Failed copying static export", error);
102
- }
103
- });
104
- };
105
- var publishStaticDir = async (ctx) => {
106
- try {
107
- await rm(ctx.tempPublishDir, { recursive: true, force: true });
108
- await mkdir(basename(ctx.tempPublishDir), { recursive: true });
109
- await rename(ctx.publishDir, ctx.tempPublishDir);
110
- await rename(ctx.staticDir, ctx.publishDir);
111
- } catch (error) {
112
- ctx.failBuild("Failed publishing static content", error instanceof Error ? { error } : {});
113
- }
114
- };
115
- var unpublishStaticDir = async (ctx) => {
116
- try {
117
- if (existsSync(ctx.tempPublishDir)) {
118
- await rename(ctx.publishDir, ctx.staticDir);
119
- await rename(ctx.tempPublishDir, ctx.publishDir);
120
- }
121
- } catch {
122
- }
123
- };
124
-
125
- export {
126
- copyStaticContent,
127
- copyStaticAssets,
128
- setHeadersConfig,
129
- copyStaticExport,
130
- publishStaticDir,
131
- unpublishStaticDir
132
- };