@netlify/plugin-nextjs 5.0.0-beta.1 → 5.0.0-beta.3
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 +5 -2
- package/dist/build/cache.js +1 -1
- package/dist/build/content/prerendered.js +1 -1
- package/dist/build/content/server.js +1 -1
- package/dist/build/functions/edge.js +3 -2
- package/dist/build/functions/server.js +3 -3
- package/dist/build/image-cdn.js +13 -0
- package/dist/build/plugin-context.js +1 -1
- package/dist/esm-chunks/{chunk-A22224GM.js → chunk-5SZ5JD6J.js} +10 -5
- package/dist/esm-chunks/{chunk-NOX2JUQZ.js → chunk-ALO2SSMH.js} +2 -2
- package/dist/esm-chunks/{chunk-UXLNY5XK.js → chunk-FFCTA32Q.js} +31 -4
- package/dist/esm-chunks/chunk-GHDGGK6V.js +105 -0
- package/dist/esm-chunks/chunk-H46DW7YI.js +28 -0
- package/dist/esm-chunks/{chunk-R4NHZWGU.js → chunk-OIL5MDCV.js} +1 -1
- package/dist/esm-chunks/{chunk-G3GM7JNF.js → chunk-S5JXJCXP.js} +2 -0
- package/dist/esm-chunks/{chunk-5N2CWXSJ.js → chunk-SMSOJ2OS.js} +19 -1
- package/dist/esm-chunks/{chunk-VP3PT3VV.js → chunk-TJKO3X6O.js} +6 -0
- package/dist/esm-chunks/{chunk-GGHAQM5D.js → chunk-XQ65S4R2.js} +5 -1
- package/dist/index.js +10 -6
- package/dist/run/config.js +1 -1
- package/dist/run/handlers/cache.cjs +15 -12
- package/dist/run/handlers/server.js +11 -8
- package/dist/run/headers.js +3 -1
- package/dist/run/next.cjs +3 -0
- package/dist/run/systemlog.js +6 -5
- package/edge-runtime/lib/headers.ts +5 -0
- package/edge-runtime/lib/logging.ts +5 -0
- package/edge-runtime/lib/next-request.ts +43 -1
- package/edge-runtime/lib/response.ts +82 -19
- package/edge-runtime/lib/util.test.ts +39 -0
- package/edge-runtime/lib/util.ts +79 -7
- package/edge-runtime/middleware.ts +19 -2
- package/edge-runtime/next.config.json +1 -0
- package/edge-runtime/vendor/import_map.json +2 -1
- package/edge-runtime/vendor/v1-7-0--edge-utils.netlify.app/logger/logger.ts +164 -0
- package/edge-runtime/vendor/v1-7-0--edge-utils.netlify.app/logger/mod.ts +1 -0
- package/edge-runtime/vendor.ts +2 -0
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-YZXA5QBC.js +0 -60
package/README.md
CHANGED
|
@@ -17,8 +17,11 @@ How to add new integration test scenarios to the application:
|
|
|
17
17
|
4. Add your test
|
|
18
18
|
|
|
19
19
|
> Currently the tests require a built version of the `dist/run/handlers/cache.cjs` so you need to
|
|
20
|
-
> run `npm run build` before executing the integration tests.
|
|
21
|
-
|
|
20
|
+
> run `npm run build` before executing the integration tests.
|
|
21
|
+
|
|
22
|
+
In addition, the integration tests need to be prepared before first use. You can do this by running
|
|
23
|
+
`npm run pretest`. To speed up this process and build only the fixtures whose name starts with a
|
|
24
|
+
given prefix, run `npm run pretest -- <prefix>`.
|
|
22
25
|
|
|
23
26
|
### E2E testing
|
|
24
27
|
|
package/dist/build/cache.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
copyNextDependencies,
|
|
9
9
|
copyNextServerCode,
|
|
10
10
|
writeTagsManifest
|
|
11
|
-
} from "../../esm-chunks/chunk-
|
|
11
|
+
} from "../../esm-chunks/chunk-5SZ5JD6J.js";
|
|
12
12
|
import "../../esm-chunks/chunk-AVWFCGVE.js";
|
|
13
13
|
import "../../esm-chunks/chunk-RSKIKBZH.js";
|
|
14
14
|
export {
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
createEdgeHandlers
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
10
|
-
import "../../esm-chunks/chunk-
|
|
9
|
+
} from "../../esm-chunks/chunk-FFCTA32Q.js";
|
|
10
|
+
import "../../esm-chunks/chunk-AVWFCGVE.js";
|
|
11
|
+
import "../../esm-chunks/chunk-TJKO3X6O.js";
|
|
11
12
|
import "../../esm-chunks/chunk-RSKIKBZH.js";
|
|
12
13
|
export {
|
|
13
14
|
createEdgeHandlers
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
createServerHandler
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
10
|
-
import "../../esm-chunks/chunk-
|
|
9
|
+
} from "../../esm-chunks/chunk-ALO2SSMH.js";
|
|
10
|
+
import "../../esm-chunks/chunk-5SZ5JD6J.js";
|
|
11
11
|
import "../../esm-chunks/chunk-AVWFCGVE.js";
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
12
|
+
import "../../esm-chunks/chunk-TJKO3X6O.js";
|
|
13
13
|
import "../../esm-chunks/chunk-RSKIKBZH.js";
|
|
14
14
|
export {
|
|
15
15
|
createServerHandler
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
const require = await (async () => {
|
|
3
|
+
const { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
setImageConfig
|
|
9
|
+
} from "../esm-chunks/chunk-H46DW7YI.js";
|
|
10
|
+
import "../esm-chunks/chunk-RSKIKBZH.js";
|
|
11
|
+
export {
|
|
12
|
+
setImageConfig
|
|
13
|
+
};
|
|
@@ -19,10 +19,13 @@ import { dirname, join } from "node:path";
|
|
|
19
19
|
var copyNextServerCode = async (ctx) => {
|
|
20
20
|
const srcDir = join(ctx.publishDir, "standalone/.next");
|
|
21
21
|
const destDir = join(ctx.serverHandlerDir, ".next");
|
|
22
|
-
const paths = await (0, import_fast_glob.default)(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const paths = await (0, import_fast_glob.default)(
|
|
23
|
+
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
|
|
24
|
+
{
|
|
25
|
+
cwd: srcDir,
|
|
26
|
+
extglob: true
|
|
27
|
+
}
|
|
28
|
+
);
|
|
26
29
|
await Promise.all(
|
|
27
30
|
paths.map(async (path) => {
|
|
28
31
|
const srcPath = join(srcDir, path);
|
|
@@ -77,7 +80,9 @@ var writeTagsManifest = async (ctx) => {
|
|
|
77
80
|
const meta = JSON.parse(file);
|
|
78
81
|
tags = meta.headers["x-next-cache-tags"];
|
|
79
82
|
} catch {
|
|
80
|
-
|
|
83
|
+
if (!definition.dataRoute?.endsWith("/default.rsc")) {
|
|
84
|
+
console.log(`Unable to read cache tags for: ${path}`);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
if (definition.dataRoute?.endsWith(".json")) {
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
copyNextDependencies,
|
|
9
9
|
copyNextServerCode,
|
|
10
10
|
writeTagsManifest
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-5SZ5JD6J.js";
|
|
12
12
|
import {
|
|
13
13
|
require_out
|
|
14
14
|
} from "./chunk-AVWFCGVE.js";
|
|
15
15
|
import {
|
|
16
16
|
SERVER_HANDLER_NAME
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-TJKO3X6O.js";
|
|
18
18
|
import {
|
|
19
19
|
__toESM
|
|
20
20
|
} from "./chunk-RSKIKBZH.js";
|
|
@@ -4,25 +4,52 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
+
import {
|
|
8
|
+
require_out
|
|
9
|
+
} from "./chunk-AVWFCGVE.js";
|
|
7
10
|
import {
|
|
8
11
|
EDGE_HANDLER_NAME
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-TJKO3X6O.js";
|
|
13
|
+
import {
|
|
14
|
+
__toESM
|
|
15
|
+
} from "./chunk-RSKIKBZH.js";
|
|
10
16
|
|
|
11
17
|
// src/build/functions/edge.ts
|
|
18
|
+
var import_fast_glob = __toESM(require_out(), 1);
|
|
12
19
|
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
13
20
|
import { dirname, join } from "node:path";
|
|
14
21
|
var writeEdgeManifest = async (ctx, manifest) => {
|
|
15
22
|
await mkdir(ctx.edgeFunctionsDir, { recursive: true });
|
|
16
23
|
await writeFile(join(ctx.edgeFunctionsDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
17
24
|
};
|
|
25
|
+
var copyRuntime = async (ctx, handlerDirectory) => {
|
|
26
|
+
const files = await (0, import_fast_glob.glob)("edge-runtime/**/*", {
|
|
27
|
+
cwd: ctx.pluginDir,
|
|
28
|
+
ignore: ["**/*.test.ts"],
|
|
29
|
+
dot: true
|
|
30
|
+
});
|
|
31
|
+
await Promise.all(
|
|
32
|
+
files.map(
|
|
33
|
+
(path) => cp(join(ctx.pluginDir, path), join(handlerDirectory, path), { recursive: true })
|
|
34
|
+
)
|
|
35
|
+
);
|
|
36
|
+
};
|
|
18
37
|
var writeHandlerFile = async (ctx, { matchers, name }) => {
|
|
38
|
+
const nextConfig = await ctx.getBuildConfig();
|
|
19
39
|
const handlerName = getHandlerName({ name });
|
|
20
40
|
const handlerDirectory = join(ctx.edgeFunctionsDir, handlerName);
|
|
21
41
|
const handlerRuntimeDirectory = join(handlerDirectory, "edge-runtime");
|
|
22
|
-
await
|
|
23
|
-
recursive: true
|
|
24
|
-
});
|
|
42
|
+
await copyRuntime(ctx, handlerDirectory);
|
|
25
43
|
await writeFile(join(handlerRuntimeDirectory, "matchers.json"), JSON.stringify(matchers));
|
|
44
|
+
const minimalNextConfig = {
|
|
45
|
+
basePath: nextConfig.basePath,
|
|
46
|
+
i18n: nextConfig.i18n,
|
|
47
|
+
trailingSlash: nextConfig.trailingSlash
|
|
48
|
+
};
|
|
49
|
+
await writeFile(
|
|
50
|
+
join(handlerRuntimeDirectory, "next.config.json"),
|
|
51
|
+
JSON.stringify(minimalNextConfig)
|
|
52
|
+
);
|
|
26
53
|
await writeFile(
|
|
27
54
|
join(handlerDirectory, `${handlerName}.js`),
|
|
28
55
|
`
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
|
|
2
|
+
const require = await (async () => {
|
|
3
|
+
const { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
__commonJS,
|
|
9
|
+
__require,
|
|
10
|
+
__toESM
|
|
11
|
+
} from "./chunk-RSKIKBZH.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/@netlify/functions/dist/lib/system_logger.js
|
|
14
|
+
var require_system_logger = __commonJS({
|
|
15
|
+
"node_modules/@netlify/functions/dist/lib/system_logger.js"(exports) {
|
|
16
|
+
"use strict";
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.systemLogger = exports.LogLevel = void 0;
|
|
19
|
+
var process_1 = __require("process");
|
|
20
|
+
var systemLogTag = "__nfSystemLog";
|
|
21
|
+
var serializeError = (error) => {
|
|
22
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
23
|
+
return {
|
|
24
|
+
error: error.message,
|
|
25
|
+
error_cause: cause,
|
|
26
|
+
error_stack: error.stack
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var LogLevel2;
|
|
30
|
+
(function(LogLevel3) {
|
|
31
|
+
LogLevel3[LogLevel3["Debug"] = 1] = "Debug";
|
|
32
|
+
LogLevel3[LogLevel3["Log"] = 2] = "Log";
|
|
33
|
+
LogLevel3[LogLevel3["Error"] = 3] = "Error";
|
|
34
|
+
})(LogLevel2 = exports.LogLevel || (exports.LogLevel = {}));
|
|
35
|
+
var SystemLogger = class _SystemLogger {
|
|
36
|
+
fields;
|
|
37
|
+
logLevel;
|
|
38
|
+
constructor(fields = {}, logLevel = LogLevel2.Log) {
|
|
39
|
+
this.fields = fields;
|
|
40
|
+
this.logLevel = logLevel;
|
|
41
|
+
}
|
|
42
|
+
doLog(logger, message) {
|
|
43
|
+
if (process_1.env.NETLIFY_DEV && !process_1.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
47
|
+
}
|
|
48
|
+
log(message) {
|
|
49
|
+
if (this.logLevel > LogLevel2.Log) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.doLog(console.log, message);
|
|
53
|
+
}
|
|
54
|
+
debug(message) {
|
|
55
|
+
if (this.logLevel > LogLevel2.Debug) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.doLog(console.debug, message);
|
|
59
|
+
}
|
|
60
|
+
error(message) {
|
|
61
|
+
if (this.logLevel > LogLevel2.Error) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this.doLog(console.error, message);
|
|
65
|
+
}
|
|
66
|
+
withLogLevel(level) {
|
|
67
|
+
return new _SystemLogger(this.fields, level);
|
|
68
|
+
}
|
|
69
|
+
withFields(fields) {
|
|
70
|
+
return new _SystemLogger({
|
|
71
|
+
...this.fields,
|
|
72
|
+
...fields
|
|
73
|
+
}, this.logLevel);
|
|
74
|
+
}
|
|
75
|
+
withError(error) {
|
|
76
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
77
|
+
return this.withFields(fields);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
exports.systemLogger = new SystemLogger();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// node_modules/@netlify/functions/dist/internal.js
|
|
85
|
+
var require_internal = __commonJS({
|
|
86
|
+
"node_modules/@netlify/functions/dist/internal.js"(exports) {
|
|
87
|
+
"use strict";
|
|
88
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
|
+
exports.LogLevel = exports.systemLogger = void 0;
|
|
90
|
+
var system_logger_js_1 = require_system_logger();
|
|
91
|
+
Object.defineProperty(exports, "systemLogger", { enumerable: true, get: function() {
|
|
92
|
+
return system_logger_js_1.systemLogger;
|
|
93
|
+
} });
|
|
94
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function() {
|
|
95
|
+
return system_logger_js_1.LogLevel;
|
|
96
|
+
} });
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// src/run/systemlog.ts
|
|
101
|
+
var import_internal = __toESM(require_internal(), 1);
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
import_internal
|
|
105
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
const require = await (async () => {
|
|
3
|
+
const { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
// src/build/image-cdn.ts
|
|
9
|
+
var setImageConfig = async (ctx) => {
|
|
10
|
+
const {
|
|
11
|
+
images: { path: imageEndpointPath, loader: imageLoader }
|
|
12
|
+
} = await ctx.getBuildConfig();
|
|
13
|
+
if (imageLoader === "default") {
|
|
14
|
+
ctx.netlifyConfig.redirects.push({
|
|
15
|
+
from: imageEndpointPath,
|
|
16
|
+
// w and q are too short to be used as params with id-length rule
|
|
17
|
+
// but we are forced to do so because of the next/image loader decides on their names
|
|
18
|
+
// eslint-disable-next-line id-length
|
|
19
|
+
query: { url: ":url", w: ":width", q: ":quality" },
|
|
20
|
+
to: "/.netlify/images?url=:url&w=:width&q=:quality",
|
|
21
|
+
status: 200
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
setImageConfig
|
|
28
|
+
};
|
|
@@ -22,7 +22,7 @@ var setRunConfig = (config) => {
|
|
|
22
22
|
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
|
|
23
23
|
};
|
|
24
24
|
var getTagsManifest = async () => {
|
|
25
|
-
return JSON.parse(await readFile(resolve(".netlify/tags-manifest.json"), "utf-8"));
|
|
25
|
+
return JSON.parse(await readFile(resolve(PLUGIN_DIR, ".netlify/tags-manifest.json"), "utf-8"));
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export {
|
|
@@ -45,6 +45,8 @@ var copyPrerenderedContent = async (ctx) => {
|
|
|
45
45
|
const key = routeToFilePath(route);
|
|
46
46
|
let value;
|
|
47
47
|
switch (true) {
|
|
48
|
+
case (meta.dataRoute?.endsWith("/default.rsc") && !existsSync(join(ctx.publishDir, "server/app", `${key}.html`))):
|
|
49
|
+
return;
|
|
48
50
|
case meta.dataRoute?.endsWith(".json"):
|
|
49
51
|
value = await buildPagesCacheValue(join(ctx.publishDir, "server/pages", key));
|
|
50
52
|
break;
|
|
@@ -13,6 +13,8 @@ import { Buffer } from "buffer";
|
|
|
13
13
|
import { env } from "process";
|
|
14
14
|
import { Buffer as Buffer2 } from "buffer";
|
|
15
15
|
import { Buffer as Buffer3 } from "buffer";
|
|
16
|
+
import stream from "stream";
|
|
17
|
+
import { promisify } from "util";
|
|
16
18
|
var getEnvironmentContext = () => {
|
|
17
19
|
const context = globalThis.netlifyBlobsContext || env.NETLIFY_BLOBS_CONTEXT;
|
|
18
20
|
if (typeof context !== "string" || !context) {
|
|
@@ -469,6 +471,7 @@ var getDeployStore = (options = {}) => {
|
|
|
469
471
|
const client = new Client(clientOptions);
|
|
470
472
|
return new Store({ client, deployID });
|
|
471
473
|
};
|
|
474
|
+
var pipeline = promisify(stream.pipeline);
|
|
472
475
|
|
|
473
476
|
// src/run/headers.ts
|
|
474
477
|
var generateNetlifyVaryValues = ({ headers, languages, cookies }) => {
|
|
@@ -555,10 +558,25 @@ var setCacheTagsHeaders = (headers, request, manifest) => {
|
|
|
555
558
|
const tags = manifest[path];
|
|
556
559
|
headers.set("cache-tag", tags);
|
|
557
560
|
};
|
|
561
|
+
var NEXT_CACHE_TO_CACHE_STATUS = {
|
|
562
|
+
HIT: `hit`,
|
|
563
|
+
MISS: `miss,`
|
|
564
|
+
};
|
|
565
|
+
var handleNextCacheHeader = (headers) => {
|
|
566
|
+
const nextCache = headers.get("x-nextjs-cache");
|
|
567
|
+
if (typeof nextCache === "string") {
|
|
568
|
+
if (nextCache in NEXT_CACHE_TO_CACHE_STATUS) {
|
|
569
|
+
const cacheStatus = NEXT_CACHE_TO_CACHE_STATUS[nextCache];
|
|
570
|
+
headers.set("cache-status", `"Next.js"; ${cacheStatus}`);
|
|
571
|
+
}
|
|
572
|
+
headers.delete("x-nextjs-cache");
|
|
573
|
+
}
|
|
574
|
+
};
|
|
558
575
|
|
|
559
576
|
export {
|
|
560
577
|
setVaryHeaders,
|
|
561
578
|
adjustDateHeader,
|
|
562
579
|
setCacheControlHeaders,
|
|
563
|
-
setCacheTagsHeaders
|
|
580
|
+
setCacheTagsHeaders,
|
|
581
|
+
handleNextCacheHeader
|
|
564
582
|
};
|
|
@@ -17,6 +17,7 @@ var SERVER_HANDLER_NAME = "___netlify-server-handler";
|
|
|
17
17
|
var EDGE_HANDLER_NAME = "___netlify-edge-handler";
|
|
18
18
|
var PluginContext = class {
|
|
19
19
|
utils;
|
|
20
|
+
netlifyConfig;
|
|
20
21
|
pluginName;
|
|
21
22
|
pluginVersion;
|
|
22
23
|
constants;
|
|
@@ -70,6 +71,7 @@ var PluginContext = class {
|
|
|
70
71
|
this.pluginVersion = this.packageJSON.version;
|
|
71
72
|
this.constants = options.constants;
|
|
72
73
|
this.utils = options.utils;
|
|
74
|
+
this.netlifyConfig = options.netlifyConfig;
|
|
73
75
|
}
|
|
74
76
|
/** Resolves a path correctly with mono repository awareness */
|
|
75
77
|
resolve(...args) {
|
|
@@ -87,6 +89,10 @@ var PluginContext = class {
|
|
|
87
89
|
await readFile(join(this.publishDir, "server/middleware-manifest.json"), "utf-8")
|
|
88
90
|
);
|
|
89
91
|
}
|
|
92
|
+
/** Get Next Config from build output **/
|
|
93
|
+
async getBuildConfig() {
|
|
94
|
+
return JSON.parse(await readFile(join(this.publishDir, "required-server-files.json"), "utf-8")).config;
|
|
95
|
+
}
|
|
90
96
|
/**
|
|
91
97
|
* Get Next.js routes manifest from the build output
|
|
92
98
|
*/
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// src/build/cache.ts
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
9
10
|
import { join } from "node:path";
|
|
10
11
|
var saveBuildCache = async (ctx) => {
|
|
11
12
|
if (await ctx.utils.cache.save(join(ctx.publishDir, "cache"))) {
|
|
@@ -15,7 +16,10 @@ var saveBuildCache = async (ctx) => {
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
var restoreBuildCache = async (ctx) => {
|
|
18
|
-
|
|
19
|
+
const { cache } = ctx.utils;
|
|
20
|
+
if (existsSync(join(ctx.publishDir, "cache"))) {
|
|
21
|
+
console.log("Next.js cache found.");
|
|
22
|
+
} else if (await cache.restore(join(ctx.publishDir, "cache"))) {
|
|
19
23
|
console.log("Next.js cache restored.");
|
|
20
24
|
} else {
|
|
21
25
|
console.log("No Next.js cache to restore.");
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import {
|
|
8
8
|
copyFetchContent,
|
|
9
9
|
copyPrerenderedContent
|
|
10
|
-
} from "./esm-chunks/chunk-
|
|
10
|
+
} from "./esm-chunks/chunk-S5JXJCXP.js";
|
|
11
11
|
import {
|
|
12
12
|
copyStaticAssets,
|
|
13
13
|
copyStaticContent,
|
|
@@ -16,19 +16,22 @@ import {
|
|
|
16
16
|
} from "./esm-chunks/chunk-Z7ZMLVTM.js";
|
|
17
17
|
import {
|
|
18
18
|
createEdgeHandlers
|
|
19
|
-
} from "./esm-chunks/chunk-
|
|
19
|
+
} from "./esm-chunks/chunk-FFCTA32Q.js";
|
|
20
20
|
import {
|
|
21
21
|
createServerHandler
|
|
22
|
-
} from "./esm-chunks/chunk-
|
|
23
|
-
import "./esm-chunks/chunk-
|
|
22
|
+
} from "./esm-chunks/chunk-ALO2SSMH.js";
|
|
23
|
+
import "./esm-chunks/chunk-5SZ5JD6J.js";
|
|
24
24
|
import "./esm-chunks/chunk-AVWFCGVE.js";
|
|
25
25
|
import {
|
|
26
26
|
restoreBuildCache,
|
|
27
27
|
saveBuildCache
|
|
28
|
-
} from "./esm-chunks/chunk-
|
|
28
|
+
} from "./esm-chunks/chunk-XQ65S4R2.js";
|
|
29
|
+
import {
|
|
30
|
+
setImageConfig
|
|
31
|
+
} from "./esm-chunks/chunk-H46DW7YI.js";
|
|
29
32
|
import {
|
|
30
33
|
PluginContext
|
|
31
|
-
} from "./esm-chunks/chunk-
|
|
34
|
+
} from "./esm-chunks/chunk-TJKO3X6O.js";
|
|
32
35
|
import "./esm-chunks/chunk-RSKIKBZH.js";
|
|
33
36
|
|
|
34
37
|
// src/index.ts
|
|
@@ -42,6 +45,7 @@ var onBuild = async (options) => {
|
|
|
42
45
|
if (!existsSync(ctx.publishDir)) {
|
|
43
46
|
ctx.failBuild("Publish directory not found, please check your netlify.toml");
|
|
44
47
|
}
|
|
48
|
+
await setImageConfig(ctx);
|
|
45
49
|
await saveBuildCache(ctx);
|
|
46
50
|
await Promise.all([
|
|
47
51
|
copyStaticAssets(ctx),
|
package/dist/run/config.js
CHANGED
|
@@ -174,8 +174,8 @@ var require_stream = __commonJS({
|
|
|
174
174
|
exports2.stream = void 0;
|
|
175
175
|
var node_stream_1 = require("node:stream");
|
|
176
176
|
var node_util_1 = require("node:util");
|
|
177
|
-
var
|
|
178
|
-
var
|
|
177
|
+
var pipeline2 = (0, node_util_1.promisify)(node_stream_1.pipeline);
|
|
178
|
+
var stream2 = (handler) => awslambda.streamifyResponse(async (event, responseStream, context) => {
|
|
179
179
|
const { body, ...httpResponseMetadata } = await handler(event, context);
|
|
180
180
|
const responseBody = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
|
|
181
181
|
if (typeof body === "undefined") {
|
|
@@ -184,10 +184,10 @@ var require_stream = __commonJS({
|
|
|
184
184
|
responseBody.write(body);
|
|
185
185
|
responseBody.end();
|
|
186
186
|
} else {
|
|
187
|
-
await
|
|
187
|
+
await pipeline2(body, responseBody);
|
|
188
188
|
}
|
|
189
189
|
});
|
|
190
|
-
exports2.stream =
|
|
190
|
+
exports2.stream = stream2;
|
|
191
191
|
}
|
|
192
192
|
});
|
|
193
193
|
|
|
@@ -249,7 +249,6 @@ var require_main = __commonJS({
|
|
|
249
249
|
var cache_exports = {};
|
|
250
250
|
__export(cache_exports, {
|
|
251
251
|
NetlifyCacheHandler: () => NetlifyCacheHandler,
|
|
252
|
-
blobStore: () => blobStore,
|
|
253
252
|
default: () => cache_default
|
|
254
253
|
});
|
|
255
254
|
module.exports = __toCommonJS(cache_exports);
|
|
@@ -262,6 +261,8 @@ var import_buffer = require("buffer");
|
|
|
262
261
|
var import_process = require("process");
|
|
263
262
|
var import_buffer2 = require("buffer");
|
|
264
263
|
var import_buffer3 = require("buffer");
|
|
264
|
+
var import_stream = __toESM(require("stream"), 1);
|
|
265
|
+
var import_util = require("util");
|
|
265
266
|
var getEnvironmentContext = () => {
|
|
266
267
|
const context = globalThis.netlifyBlobsContext || import_process.env.NETLIFY_BLOBS_CONTEXT;
|
|
267
268
|
if (typeof context !== "string" || !context) {
|
|
@@ -718,11 +719,11 @@ var getDeployStore = (options = {}) => {
|
|
|
718
719
|
const client = new Client(clientOptions);
|
|
719
720
|
return new Store({ client, deployID });
|
|
720
721
|
};
|
|
722
|
+
var pipeline = (0, import_util.promisify)(import_stream.default.pipeline);
|
|
721
723
|
|
|
722
724
|
// src/run/handlers/cache.cts
|
|
723
725
|
var import_functions = __toESM(require_main());
|
|
724
726
|
var import_constants = require("next/dist/lib/constants.js");
|
|
725
|
-
var blobStore = getDeployStore();
|
|
726
727
|
var prerenderManifest = JSON.parse(
|
|
727
728
|
(0, import_node_fs.readFileSync)((0, import_posix.join)(process.cwd(), ".next/prerender-manifest.json"), "utf-8")
|
|
728
729
|
);
|
|
@@ -732,17 +733,20 @@ function toRoute(cacheKey) {
|
|
|
732
733
|
function encodeBlobKey(key) {
|
|
733
734
|
return import_node_buffer.Buffer.from(key.replace(/^\//, "")).toString("base64");
|
|
734
735
|
}
|
|
736
|
+
var fetchBeforeNextPatchedIt = globalThis.fetch;
|
|
735
737
|
var NetlifyCacheHandler = class {
|
|
736
738
|
options;
|
|
737
739
|
revalidatedTags;
|
|
740
|
+
blobStore;
|
|
738
741
|
constructor(options) {
|
|
739
742
|
this.options = options;
|
|
740
743
|
this.revalidatedTags = options.revalidatedTags;
|
|
744
|
+
this.blobStore = getDeployStore({ fetch: fetchBeforeNextPatchedIt });
|
|
741
745
|
}
|
|
742
746
|
async get(...args) {
|
|
743
747
|
const [key, ctx = {}] = args;
|
|
744
748
|
console.debug(`[NetlifyCacheHandler.get]: ${key}`);
|
|
745
|
-
const blob = await blobStore.get(encodeBlobKey(key), {
|
|
749
|
+
const blob = await this.blobStore.get(encodeBlobKey(key), {
|
|
746
750
|
type: "json"
|
|
747
751
|
});
|
|
748
752
|
if (!blob) {
|
|
@@ -786,7 +790,7 @@ var NetlifyCacheHandler = class {
|
|
|
786
790
|
async set(...args) {
|
|
787
791
|
const [key, data] = args;
|
|
788
792
|
console.debug(`[NetlifyCacheHandler.set]: ${key}`);
|
|
789
|
-
await blobStore.setJSON(encodeBlobKey(key), {
|
|
793
|
+
await this.blobStore.setJSON(encodeBlobKey(key), {
|
|
790
794
|
lastModified: Date.now(),
|
|
791
795
|
value: data
|
|
792
796
|
});
|
|
@@ -798,7 +802,7 @@ var NetlifyCacheHandler = class {
|
|
|
798
802
|
revalidatedAt: Date.now()
|
|
799
803
|
};
|
|
800
804
|
try {
|
|
801
|
-
await blobStore.setJSON(encodeBlobKey(tag), data);
|
|
805
|
+
await this.blobStore.setJSON(encodeBlobKey(tag), data);
|
|
802
806
|
} catch (error) {
|
|
803
807
|
console.warn(`Failed to update tag manifest for ${tag}`, error);
|
|
804
808
|
}
|
|
@@ -814,7 +818,7 @@ var NetlifyCacheHandler = class {
|
|
|
814
818
|
const cacheTags = [...tags, ...softTags];
|
|
815
819
|
const allManifests = await Promise.all(
|
|
816
820
|
cacheTags.map(async (tag) => {
|
|
817
|
-
const res = await blobStore.get(encodeBlobKey(tag), { type: "json" }).then((value) => ({ [tag]: value })).catch(console.error);
|
|
821
|
+
const res = await this.blobStore.get(encodeBlobKey(tag), { type: "json" }).then((value) => ({ [tag]: value })).catch(console.error);
|
|
818
822
|
return res || { [tag]: null };
|
|
819
823
|
})
|
|
820
824
|
);
|
|
@@ -847,6 +851,5 @@ var NetlifyCacheHandler = class {
|
|
|
847
851
|
var cache_default = NetlifyCacheHandler;
|
|
848
852
|
// Annotate the CommonJS export names for ESM import in node:
|
|
849
853
|
0 && (module.exports = {
|
|
850
|
-
NetlifyCacheHandler
|
|
851
|
-
blobStore
|
|
854
|
+
NetlifyCacheHandler
|
|
852
855
|
});
|
|
@@ -4,22 +4,23 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
+
import {
|
|
8
|
+
import_internal
|
|
9
|
+
} from "../../esm-chunks/chunk-GHDGGK6V.js";
|
|
7
10
|
import {
|
|
8
11
|
getTagsManifest
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
12
|
+
} from "../../esm-chunks/chunk-OIL5MDCV.js";
|
|
10
13
|
import "../../esm-chunks/chunk-4AJYXTWN.js";
|
|
11
14
|
import {
|
|
12
15
|
adjustDateHeader,
|
|
16
|
+
handleNextCacheHeader,
|
|
13
17
|
setCacheControlHeaders,
|
|
14
18
|
setCacheTagsHeaders,
|
|
15
19
|
setVaryHeaders
|
|
16
|
-
} from "../../esm-chunks/chunk-
|
|
20
|
+
} from "../../esm-chunks/chunk-SMSOJ2OS.js";
|
|
17
21
|
import {
|
|
18
22
|
nextResponseProxy
|
|
19
23
|
} from "../../esm-chunks/chunk-B6QMRLBH.js";
|
|
20
|
-
import {
|
|
21
|
-
logger
|
|
22
|
-
} from "../../esm-chunks/chunk-YZXA5QBC.js";
|
|
23
24
|
import {
|
|
24
25
|
__commonJS,
|
|
25
26
|
__toESM
|
|
@@ -3277,7 +3278,7 @@ var server_default = async (request) => {
|
|
|
3277
3278
|
try {
|
|
3278
3279
|
await nextHandler(req, resProxy);
|
|
3279
3280
|
} catch (error) {
|
|
3280
|
-
|
|
3281
|
+
import_internal.systemLogger.withError(error).error("next handler error");
|
|
3281
3282
|
console.error(error);
|
|
3282
3283
|
resProxy.statusCode = 500;
|
|
3283
3284
|
resProxy.end("Internal Server Error");
|
|
@@ -3287,8 +3288,10 @@ var server_default = async (request) => {
|
|
|
3287
3288
|
setCacheControlHeaders(response.headers, request);
|
|
3288
3289
|
setCacheTagsHeaders(response.headers, request, tagsManifest);
|
|
3289
3290
|
setVaryHeaders(response.headers, request, nextConfig);
|
|
3290
|
-
|
|
3291
|
-
|
|
3291
|
+
handleNextCacheHeader(response.headers);
|
|
3292
|
+
if (response.status > 300 && response.status < 400 || response.status >= 500) {
|
|
3293
|
+
const body = await response.text();
|
|
3294
|
+
return new Response(body || null, response);
|
|
3292
3295
|
}
|
|
3293
3296
|
return response;
|
|
3294
3297
|
};
|