@netlify/plugin-nextjs 5.0.0-beta.7 → 5.0.0-beta.9
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/README.md +23 -0
- package/dist/build/cache.js +2 -2
- package/dist/build/content/prerendered.js +4 -3
- package/dist/build/content/server.js +4 -3
- package/dist/build/content/static.js +3 -3
- package/dist/build/functions/edge.js +4 -5
- package/dist/build/functions/server.js +6 -6
- package/dist/build/image-cdn.js +2 -2
- package/dist/build/plugin-context.js +2 -3
- package/dist/build/templates/handler-monorepo.tmpl.js +49 -0
- package/dist/build/templates/handler.tmpl.js +43 -0
- package/dist/esm-chunks/{chunk-COJ526HO.js → chunk-4J4A5OE2.js} +27 -7
- package/dist/esm-chunks/{chunk-WELZ7LFO.js → chunk-5JVNISGM.js} +12 -1
- package/dist/esm-chunks/{chunk-UDWVXRI2.js → chunk-67EWAGDQ.js} +32 -23
- package/dist/esm-chunks/chunk-72ZI2IVI.js +36 -0
- package/dist/esm-chunks/{chunk-W5TLWQMF.js → chunk-AU7XDLZH.js} +111 -27
- package/dist/esm-chunks/{chunk-IZ2AVCVF.js → chunk-DWC6JSN7.js} +48 -24
- package/dist/esm-chunks/{chunk-X7XIMV6B.js → chunk-HYBEXB2Z.js} +1 -1
- package/dist/esm-chunks/{chunk-XIP2W57K.js → chunk-NL5YH5N6.js} +5 -4
- package/dist/esm-chunks/{chunk-KDRFBPAR.js → chunk-T6AZTXZF.js} +16 -28
- package/dist/esm-chunks/{chunk-EPSI5TTB.js → chunk-TOK7TKP3.js} +1 -1
- package/dist/esm-chunks/{chunk-K233JI4O.js → chunk-UYKENJEU.js} +4 -2
- package/dist/esm-chunks/chunk-VDDK7MXY.js +1661 -0
- package/dist/esm-chunks/{chunk-MFN4GH7U.js → chunk-VZNKO4OO.js} +1 -1
- package/dist/esm-chunks/{chunk-NE4HYI2D.js → chunk-WT2HN3M6.js} +1 -1
- package/dist/esm-chunks/{chunk-PCJY2SS7.js → chunk-YIE34LVX.js} +5 -5
- package/dist/esm-chunks/{chunk-AMJYZZKR.js → chunk-ZWFKLYLH.js} +6 -3
- package/dist/esm-chunks/package-6DFWHFJA.js +133 -0
- package/dist/index.js +11 -12
- package/dist/run/config.js +3 -3
- package/dist/run/constants.js +6 -4
- package/dist/run/handlers/cache.cjs +1858 -96
- package/dist/run/handlers/request-context.cjs +56 -0
- package/dist/run/handlers/server.js +76 -40
- package/dist/run/handlers/tracing.js +52883 -0
- package/dist/run/headers.js +4 -4
- package/dist/run/next.cjs +1722 -34
- package/dist/run/revalidate.js +2 -2
- package/dist/run/systemlog.js +2 -2
- package/dist/shared/blobkey.js +1 -1
- package/edge-runtime/lib/response.ts +24 -20
- package/edge-runtime/lib/util.ts +6 -1
- package/edge-runtime/shim/index.js +27 -0
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-XA2CZH5Y.js +0 -32
package/README.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
Next.js is supported natively on Netlify, and in most cases you will not need to install or
|
|
4
4
|
configure anything. This repo includes the packages used to support Next.js on Netlify.
|
|
5
5
|
|
|
6
|
+
## Lambda Folder structure:
|
|
7
|
+
|
|
8
|
+
For a simple next.js app
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
/___netlify-server-handler
|
|
12
|
+
├── .netlify
|
|
13
|
+
│ ├── tags-manifest.json
|
|
14
|
+
│ └── dist // the compiled runtime code
|
|
15
|
+
│ └── run
|
|
16
|
+
│ ├── handlers
|
|
17
|
+
│ │ ├── server.js
|
|
18
|
+
│ │ └── cache.cjs
|
|
19
|
+
│ └── next.cjs
|
|
20
|
+
├── .next // or distDir name from the next.config.js
|
|
21
|
+
│ └── // content from standalone
|
|
22
|
+
├── run-config.json // the config object from the required-server-files.json
|
|
23
|
+
├── node_modules
|
|
24
|
+
├── ___netlify-server-handler.json
|
|
25
|
+
├── ___netlify-server-handler.mjs
|
|
26
|
+
└── package.json
|
|
27
|
+
```
|
|
28
|
+
|
|
6
29
|
## Testing
|
|
7
30
|
|
|
8
31
|
### Integration testing
|
package/dist/build/cache.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import {
|
|
8
8
|
restoreBuildCache,
|
|
9
9
|
saveBuildCache
|
|
10
|
-
} from "../esm-chunks/chunk-
|
|
11
|
-
import "../esm-chunks/chunk-
|
|
10
|
+
} from "../esm-chunks/chunk-72ZI2IVI.js";
|
|
11
|
+
import "../esm-chunks/chunk-5JVNISGM.js";
|
|
12
12
|
export {
|
|
13
13
|
restoreBuildCache,
|
|
14
14
|
saveBuildCache
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
import {
|
|
8
8
|
copyFetchContent,
|
|
9
9
|
copyPrerenderedContent
|
|
10
|
-
} from "../../esm-chunks/chunk-
|
|
11
|
-
import "../../esm-chunks/chunk-
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
10
|
+
} from "../../esm-chunks/chunk-67EWAGDQ.js";
|
|
11
|
+
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
12
|
+
import "../../esm-chunks/chunk-TYCYFZ22.js";
|
|
13
|
+
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
13
14
|
export {
|
|
14
15
|
copyFetchContent,
|
|
15
16
|
copyPrerenderedContent
|
|
@@ -8,9 +8,10 @@ import {
|
|
|
8
8
|
copyNextDependencies,
|
|
9
9
|
copyNextServerCode,
|
|
10
10
|
writeTagsManifest
|
|
11
|
-
} from "../../esm-chunks/chunk-
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
13
|
-
import "../../esm-chunks/chunk-
|
|
11
|
+
} from "../../esm-chunks/chunk-4J4A5OE2.js";
|
|
12
|
+
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
13
|
+
import "../../esm-chunks/chunk-UYKENJEU.js";
|
|
14
|
+
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
14
15
|
export {
|
|
15
16
|
copyNextDependencies,
|
|
16
17
|
copyNextServerCode,
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
copyStaticContent,
|
|
10
10
|
publishStaticDir,
|
|
11
11
|
unpublishStaticDir
|
|
12
|
-
} from "../../esm-chunks/chunk-
|
|
13
|
-
import "../../esm-chunks/chunk-
|
|
12
|
+
} from "../../esm-chunks/chunk-ZWFKLYLH.js";
|
|
13
|
+
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
14
14
|
import "../../esm-chunks/chunk-TYCYFZ22.js";
|
|
15
|
-
import "../../esm-chunks/chunk-
|
|
15
|
+
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
16
16
|
export {
|
|
17
17
|
copyStaticAssets,
|
|
18
18
|
copyStaticContent,
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
createEdgeHandlers
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
10
|
-
import "../../esm-chunks/chunk-
|
|
11
|
-
import "../../esm-chunks/chunk-
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
13
|
-
import "../../esm-chunks/chunk-WELZ7LFO.js";
|
|
9
|
+
} from "../../esm-chunks/chunk-YIE34LVX.js";
|
|
10
|
+
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
11
|
+
import "../../esm-chunks/chunk-DWC6JSN7.js";
|
|
12
|
+
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
14
13
|
export {
|
|
15
14
|
createEdgeHandlers
|
|
16
15
|
};
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
createServerHandler
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
10
|
-
import "../../esm-chunks/chunk-
|
|
11
|
-
import "../../esm-chunks/chunk-
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
13
|
-
import "../../esm-chunks/chunk-
|
|
14
|
-
import "../../esm-chunks/chunk-
|
|
9
|
+
} from "../../esm-chunks/chunk-T6AZTXZF.js";
|
|
10
|
+
import "../../esm-chunks/chunk-4J4A5OE2.js";
|
|
11
|
+
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
12
|
+
import "../../esm-chunks/chunk-DWC6JSN7.js";
|
|
13
|
+
import "../../esm-chunks/chunk-UYKENJEU.js";
|
|
14
|
+
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
15
15
|
export {
|
|
16
16
|
createServerHandler
|
|
17
17
|
};
|
package/dist/build/image-cdn.js
CHANGED
|
@@ -8,9 +8,8 @@ import {
|
|
|
8
8
|
EDGE_HANDLER_NAME,
|
|
9
9
|
PluginContext,
|
|
10
10
|
SERVER_HANDLER_NAME
|
|
11
|
-
} from "../esm-chunks/chunk-
|
|
12
|
-
import "../esm-chunks/chunk-
|
|
13
|
-
import "../esm-chunks/chunk-WELZ7LFO.js";
|
|
11
|
+
} from "../esm-chunks/chunk-DWC6JSN7.js";
|
|
12
|
+
import "../esm-chunks/chunk-5JVNISGM.js";
|
|
14
13
|
export {
|
|
15
14
|
EDGE_HANDLER_NAME,
|
|
16
15
|
PluginContext,
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import tracing, { trace } from '{{cwd}}/.netlify/dist/run/handlers/tracing.js'
|
|
2
|
+
|
|
3
|
+
process.chdir('{{cwd}}')
|
|
4
|
+
|
|
5
|
+
let cachedHandler
|
|
6
|
+
export default async function (req, context) {
|
|
7
|
+
if (process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL) {
|
|
8
|
+
tracing.start()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @type {import('@opentelemetry/api').Tracer} */
|
|
12
|
+
const tracer = trace.getTracer('Next.js Runtime')
|
|
13
|
+
return tracer.startActiveSpan('Next.js Server Handler', async (span) => {
|
|
14
|
+
try {
|
|
15
|
+
span.setAttributes({
|
|
16
|
+
'account.id': context.account.id,
|
|
17
|
+
'deploy.id': context.deploy.id,
|
|
18
|
+
'request.id': context.requestId,
|
|
19
|
+
'site.id': context.site.id,
|
|
20
|
+
'http.method': req.method,
|
|
21
|
+
'http.target': req.url,
|
|
22
|
+
monorepo: true,
|
|
23
|
+
cwd: '{{cwd}}',
|
|
24
|
+
})
|
|
25
|
+
if (!cachedHandler) {
|
|
26
|
+
const { default: handler } = await import('{{nextServerHandler}}')
|
|
27
|
+
cachedHandler = handler
|
|
28
|
+
}
|
|
29
|
+
const response = await cachedHandler(req, context)
|
|
30
|
+
span.setAttributes({
|
|
31
|
+
'http.status_code': response.status,
|
|
32
|
+
})
|
|
33
|
+
return response
|
|
34
|
+
} catch (error) {
|
|
35
|
+
span.recordException(error)
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
span.addEvent({ name: error.name, message: error.message })
|
|
38
|
+
}
|
|
39
|
+
throw error
|
|
40
|
+
} finally {
|
|
41
|
+
span.end()
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const config = {
|
|
47
|
+
path: '/*',
|
|
48
|
+
preferStatic: true,
|
|
49
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import serverHandler from './.netlify/dist/run/handlers/server.js'
|
|
2
|
+
import tracing, { trace } from './.netlify/dist/run/handlers/tracing.js'
|
|
3
|
+
|
|
4
|
+
export default async function handler(req, context) {
|
|
5
|
+
if (process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL) {
|
|
6
|
+
tracing.start()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** @type {import('@opentelemetry/api').Tracer} */
|
|
10
|
+
const tracer = trace.getTracer('Next.js Runtime')
|
|
11
|
+
return tracer.startActiveSpan('Next.js Server Handler', async (span) => {
|
|
12
|
+
try {
|
|
13
|
+
span.setAttributes({
|
|
14
|
+
'account.id': context.account.id,
|
|
15
|
+
'deploy.id': context.deploy.id,
|
|
16
|
+
'request.id': context.requestId,
|
|
17
|
+
'site.id': context.site.id,
|
|
18
|
+
'http.method': req.method,
|
|
19
|
+
'http.target': req.url,
|
|
20
|
+
monorepo: false,
|
|
21
|
+
cwd: process.cwd(),
|
|
22
|
+
})
|
|
23
|
+
const response = await serverHandler(req, context)
|
|
24
|
+
span.setAttributes({
|
|
25
|
+
'http.status_code': response.status,
|
|
26
|
+
})
|
|
27
|
+
return response
|
|
28
|
+
} catch (error) {
|
|
29
|
+
span.recordException(error)
|
|
30
|
+
if (error instanceof Error) {
|
|
31
|
+
span.addEvent({ name: error.name, message: error.message })
|
|
32
|
+
}
|
|
33
|
+
throw error
|
|
34
|
+
} finally {
|
|
35
|
+
span.end()
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const config = {
|
|
41
|
+
path: '/*',
|
|
42
|
+
preferStatic: true,
|
|
43
|
+
}
|
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
require_out
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VZNKO4OO.js";
|
|
10
|
+
import {
|
|
11
|
+
RUN_CONFIG
|
|
12
|
+
} from "./chunk-UYKENJEU.js";
|
|
10
13
|
import {
|
|
11
14
|
__toESM
|
|
12
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5JVNISGM.js";
|
|
13
16
|
|
|
14
17
|
// src/build/content/server.ts
|
|
15
18
|
var import_fast_glob = __toESM(require_out(), 1);
|
|
@@ -18,8 +21,25 @@ import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from "node
|
|
|
18
21
|
import { createRequire } from "node:module";
|
|
19
22
|
import { dirname, join, resolve } from "node:path";
|
|
20
23
|
var copyNextServerCode = async (ctx) => {
|
|
21
|
-
const
|
|
22
|
-
|
|
24
|
+
const reqServerFilesPath = join(
|
|
25
|
+
ctx.standaloneRootDir,
|
|
26
|
+
ctx.relPublishDir,
|
|
27
|
+
"required-server-files.json"
|
|
28
|
+
);
|
|
29
|
+
const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
|
|
30
|
+
if (ctx.distDir.replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
|
|
31
|
+
reqServerFiles.config.distDir = ctx.nextDistDir;
|
|
32
|
+
await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
|
|
33
|
+
}
|
|
34
|
+
await mkdir(ctx.serverHandlerDir, { recursive: true });
|
|
35
|
+
await writeFile(
|
|
36
|
+
join(ctx.serverHandlerDir, RUN_CONFIG),
|
|
37
|
+
JSON.stringify(reqServerFiles.config),
|
|
38
|
+
"utf-8"
|
|
39
|
+
);
|
|
40
|
+
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
41
|
+
const nextFolder = ctx.distDir === ctx.buildConfig.distDir ? ctx.distDir : ctx.nextDistDir;
|
|
42
|
+
const destDir = join(ctx.serverHandlerDir, nextFolder);
|
|
23
43
|
const paths = await (0, import_fast_glob.default)(
|
|
24
44
|
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
|
|
25
45
|
{
|
|
@@ -39,7 +59,7 @@ var copyNextServerCode = async (ctx) => {
|
|
|
39
59
|
}
|
|
40
60
|
return;
|
|
41
61
|
}
|
|
42
|
-
await cp(srcPath, destPath, { recursive: true });
|
|
62
|
+
await cp(srcPath, destPath, { recursive: true, force: true });
|
|
43
63
|
})
|
|
44
64
|
);
|
|
45
65
|
};
|
|
@@ -67,12 +87,12 @@ async function recreateNodeModuleSymlinks(src, dest, org) {
|
|
|
67
87
|
var copyNextDependencies = async (ctx) => {
|
|
68
88
|
const entries = await readdir(ctx.standaloneDir);
|
|
69
89
|
const promises = entries.map(async (entry) => {
|
|
70
|
-
if (entry === "package.json" || entry ===
|
|
90
|
+
if (entry === "package.json" || entry === ctx.nextDistDir) {
|
|
71
91
|
return;
|
|
72
92
|
}
|
|
73
93
|
const src = join(ctx.standaloneDir, entry);
|
|
74
94
|
const dest = join(ctx.serverHandlerDir, entry);
|
|
75
|
-
await cp(src, dest, { recursive: true, verbatimSymlinks: true });
|
|
95
|
+
await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
|
|
76
96
|
if (entry === "node_modules") {
|
|
77
97
|
await recreateNodeModuleSymlinks(ctx.resolve("node_modules"), dest);
|
|
78
98
|
}
|
|
@@ -17,9 +17,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
17
17
|
return require.apply(this, arguments);
|
|
18
18
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
19
19
|
});
|
|
20
|
+
var __esm = (fn, res) => function __init() {
|
|
21
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
22
|
+
};
|
|
20
23
|
var __commonJS = (cb, mod) => function __require2() {
|
|
21
24
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
22
25
|
};
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
23
30
|
var __copyProps = (to, from, except, desc) => {
|
|
24
31
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
32
|
for (let key of __getOwnPropNames(from))
|
|
@@ -36,9 +43,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
43
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
44
|
mod
|
|
38
45
|
));
|
|
46
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
47
|
|
|
40
48
|
export {
|
|
41
49
|
__require,
|
|
50
|
+
__esm,
|
|
42
51
|
__commonJS,
|
|
43
|
-
|
|
52
|
+
__export,
|
|
53
|
+
__toESM,
|
|
54
|
+
__toCommonJS
|
|
44
55
|
};
|
|
@@ -6,21 +6,36 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
require_out
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-VZNKO4OO.js";
|
|
10
|
+
import {
|
|
11
|
+
encodeBlobKey
|
|
12
|
+
} from "./chunk-TYCYFZ22.js";
|
|
10
13
|
import {
|
|
11
14
|
__toESM
|
|
12
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-5JVNISGM.js";
|
|
13
16
|
|
|
14
17
|
// src/build/content/prerendered.ts
|
|
15
18
|
var import_fast_glob = __toESM(require_out(), 1);
|
|
16
19
|
import { existsSync } from "node:fs";
|
|
17
|
-
import { readFile } from "node:fs/promises";
|
|
18
|
-
import { join } from "node:path";
|
|
20
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
21
|
+
import { dirname, join } from "node:path";
|
|
22
|
+
var writeCacheEntry = async (route, value, lastModified, ctx) => {
|
|
23
|
+
const path = join(ctx.blobDir, await encodeBlobKey(route));
|
|
24
|
+
const entry = JSON.stringify({
|
|
25
|
+
lastModified,
|
|
26
|
+
value
|
|
27
|
+
});
|
|
28
|
+
await mkdir(dirname(path), { recursive: true });
|
|
29
|
+
await writeFile(path, entry, "utf-8");
|
|
30
|
+
};
|
|
19
31
|
var routeToFilePath = (path) => path === "/" ? "/index" : path;
|
|
20
32
|
var buildPagesCacheValue = async (path) => ({
|
|
21
33
|
kind: "PAGE",
|
|
22
34
|
html: await readFile(`${path}.html`, "utf-8"),
|
|
23
|
-
pageData: JSON.parse(await readFile(`${path}.json`, "utf-8"))
|
|
35
|
+
pageData: JSON.parse(await readFile(`${path}.json`, "utf-8")),
|
|
36
|
+
postponed: void 0,
|
|
37
|
+
headers: void 0,
|
|
38
|
+
status: void 0
|
|
24
39
|
});
|
|
25
40
|
var buildAppCacheValue = async (path) => ({
|
|
26
41
|
kind: "PAGE",
|
|
@@ -30,7 +45,7 @@ var buildAppCacheValue = async (path) => ({
|
|
|
30
45
|
});
|
|
31
46
|
var buildRouteCacheValue = async (path) => ({
|
|
32
47
|
kind: "ROUTE",
|
|
33
|
-
body: await readFile(`${path}.body`, "
|
|
48
|
+
body: await readFile(`${path}.body`, "base64"),
|
|
34
49
|
...JSON.parse(await readFile(`${path}.meta`, "utf-8"))
|
|
35
50
|
});
|
|
36
51
|
var buildFetchCacheValue = async (path) => ({
|
|
@@ -42,39 +57,32 @@ var copyPrerenderedContent = async (ctx) => {
|
|
|
42
57
|
const manifest = await ctx.getPrerenderManifest();
|
|
43
58
|
await Promise.all(
|
|
44
59
|
Object.entries(manifest.routes).map(async ([route, meta]) => {
|
|
60
|
+
const lastModified = meta.initialRevalidateSeconds ? Date.now() - 31536e6 : Date.now();
|
|
45
61
|
const key = routeToFilePath(route);
|
|
46
62
|
let value;
|
|
47
|
-
let path;
|
|
48
63
|
switch (true) {
|
|
49
64
|
case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
|
|
50
65
|
return;
|
|
51
66
|
case meta.dataRoute?.endsWith(".json"):
|
|
52
|
-
|
|
53
|
-
value = await buildPagesCacheValue(path);
|
|
67
|
+
value = await buildPagesCacheValue(join(ctx.publishDir, "server/pages", key));
|
|
54
68
|
break;
|
|
55
69
|
case meta.dataRoute?.endsWith(".rsc"):
|
|
56
|
-
|
|
57
|
-
value = await buildAppCacheValue(path);
|
|
70
|
+
value = await buildAppCacheValue(join(ctx.publishDir, "server/app", key));
|
|
58
71
|
break;
|
|
59
72
|
case meta.dataRoute === null:
|
|
60
|
-
|
|
61
|
-
value = await buildRouteCacheValue(path);
|
|
73
|
+
value = await buildRouteCacheValue(join(ctx.publishDir, "server/app", key));
|
|
62
74
|
break;
|
|
63
75
|
default:
|
|
64
76
|
throw new Error(`Unrecognized content: ${route}`);
|
|
65
77
|
}
|
|
66
|
-
await
|
|
67
|
-
key,
|
|
68
|
-
value,
|
|
69
|
-
meta.dataRoute === null ? `${path}.body` : `${path}.html`
|
|
70
|
-
);
|
|
78
|
+
await writeCacheEntry(key, value, lastModified, ctx);
|
|
71
79
|
})
|
|
72
80
|
);
|
|
73
81
|
if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
|
|
82
|
+
const lastModified = Date.now();
|
|
74
83
|
const key = "/404";
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
await ctx.writeCacheEntry(key, value, `${path}.html`);
|
|
84
|
+
const value = await buildAppCacheValue(join(ctx.publishDir, "server/app/_not-found"));
|
|
85
|
+
await writeCacheEntry(key, value, lastModified, ctx);
|
|
78
86
|
}
|
|
79
87
|
} catch (error) {
|
|
80
88
|
ctx.failBuild("Failed assembling prerendered content for upload", error);
|
|
@@ -82,15 +90,16 @@ var copyPrerenderedContent = async (ctx) => {
|
|
|
82
90
|
};
|
|
83
91
|
var copyFetchContent = async (ctx) => {
|
|
84
92
|
try {
|
|
85
|
-
const paths = await (0, import_fast_glob.
|
|
93
|
+
const paths = await (0, import_fast_glob.glob)(["!(*.*)"], {
|
|
86
94
|
cwd: join(ctx.publishDir, "cache/fetch-cache"),
|
|
87
95
|
extglob: true
|
|
88
96
|
});
|
|
89
97
|
await Promise.all(
|
|
90
98
|
paths.map(async (key) => {
|
|
99
|
+
const lastModified = Date.now() - 31536e6;
|
|
91
100
|
const path = join(ctx.publishDir, "cache/fetch-cache", key);
|
|
92
101
|
const value = await buildFetchCacheValue(path);
|
|
93
|
-
await
|
|
102
|
+
await writeCacheEntry(key, value, lastModified, ctx);
|
|
94
103
|
})
|
|
95
104
|
);
|
|
96
105
|
} catch (error) {
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
};
|