@netlify/plugin-nextjs 5.0.0-rc.0 → 5.0.0-rc.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/dist/build/content/server.js +1 -1
- package/dist/build/content/static.js +1 -1
- package/dist/build/functions/edge.js +2 -2
- package/dist/build/functions/server.js +3 -3
- package/dist/build/plugin-context.js +1 -1
- package/dist/esm-chunks/{chunk-NL5YH5N6.js → chunk-3SUDZQ7L.js} +1 -1
- package/dist/esm-chunks/{chunk-4J4A5OE2.js → chunk-52WMBYKL.js} +8 -5
- package/dist/esm-chunks/{chunk-PGQNT7XM.js → chunk-655Y7ISI.js} +19 -7
- package/dist/esm-chunks/{chunk-FTCARYDZ.js → chunk-E3NFUTWC.js} +34 -9
- package/dist/esm-chunks/{chunk-WQIG4U66.js → chunk-MPZEWLBG.js} +2 -2
- package/dist/esm-chunks/chunk-ZZOGIP2V.js +531 -0
- package/dist/esm-chunks/{package-5SG7C3OT.js → package-V53S3A76.js} +4 -3
- package/dist/index.js +8 -13
- package/dist/run/config.js +1 -1
- package/dist/run/handlers/server.js +1 -1
- package/dist/run/handlers/tracing.js +1 -1
- package/edge-runtime/lib/next-request.ts +14 -9
- package/edge-runtime/lib/response.ts +3 -2
- package/edge-runtime/lib/util.ts +1 -1
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-UX4JCTAE.js +0 -134
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
copyNextDependencies,
|
|
9
9
|
copyNextServerCode,
|
|
10
10
|
writeTagsManifest
|
|
11
|
-
} from "../../esm-chunks/chunk-
|
|
11
|
+
} from "../../esm-chunks/chunk-52WMBYKL.js";
|
|
12
12
|
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
13
13
|
import "../../esm-chunks/chunk-UYKENJEU.js";
|
|
14
14
|
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
copyStaticContent,
|
|
10
10
|
publishStaticDir,
|
|
11
11
|
unpublishStaticDir
|
|
12
|
-
} from "../../esm-chunks/chunk-
|
|
12
|
+
} from "../../esm-chunks/chunk-MPZEWLBG.js";
|
|
13
13
|
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
14
14
|
import "../../esm-chunks/chunk-TYCYFZ22.js";
|
|
15
15
|
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
createEdgeHandlers
|
|
9
|
-
} from "../../esm-chunks/chunk-
|
|
9
|
+
} from "../../esm-chunks/chunk-ZZOGIP2V.js";
|
|
10
10
|
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
11
|
-
import "../../esm-chunks/chunk-
|
|
11
|
+
import "../../esm-chunks/chunk-655Y7ISI.js";
|
|
12
12
|
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
13
13
|
export {
|
|
14
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-E3NFUTWC.js";
|
|
10
|
+
import "../../esm-chunks/chunk-52WMBYKL.js";
|
|
11
11
|
import "../../esm-chunks/chunk-VZNKO4OO.js";
|
|
12
|
-
import "../../esm-chunks/chunk-
|
|
12
|
+
import "../../esm-chunks/chunk-655Y7ISI.js";
|
|
13
13
|
import "../../esm-chunks/chunk-UYKENJEU.js";
|
|
14
14
|
import "../../esm-chunks/chunk-5JVNISGM.js";
|
|
15
15
|
export {
|
|
@@ -14,7 +14,7 @@ import { existsSync } from "node:fs";
|
|
|
14
14
|
import { readFile } from "node:fs/promises";
|
|
15
15
|
import { join, resolve } from "node:path";
|
|
16
16
|
var getRunConfig = async () => {
|
|
17
|
-
return JSON.parse(await readFile(resolve(RUN_CONFIG), "utf-8"));
|
|
17
|
+
return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG), "utf-8"));
|
|
18
18
|
};
|
|
19
19
|
var setRunConfig = (config) => {
|
|
20
20
|
const cacheHandler = join(PLUGIN_DIR, ".netlify/dist/run/handlers/cache.cjs");
|
|
@@ -19,7 +19,9 @@ var import_fast_glob = __toESM(require_out(), 1);
|
|
|
19
19
|
import { existsSync } from "node:fs";
|
|
20
20
|
import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from "node:fs/promises";
|
|
21
21
|
import { createRequire } from "node:module";
|
|
22
|
-
import { dirname, join, resolve } from "node:path";
|
|
22
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
23
|
+
import { sep as posixSep } from "node:path/posix";
|
|
24
|
+
var toPosixPath = (path) => path.split(sep).join(posixSep);
|
|
23
25
|
var copyNextServerCode = async (ctx) => {
|
|
24
26
|
const reqServerFilesPath = join(
|
|
25
27
|
ctx.standaloneRootDir,
|
|
@@ -27,7 +29,7 @@ var copyNextServerCode = async (ctx) => {
|
|
|
27
29
|
"required-server-files.json"
|
|
28
30
|
);
|
|
29
31
|
const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
|
|
30
|
-
if (ctx.distDir.replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
|
|
32
|
+
if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
|
|
31
33
|
reqServerFiles.config.distDir = ctx.nextDistDir;
|
|
32
34
|
await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
|
|
33
35
|
}
|
|
@@ -38,7 +40,7 @@ var copyNextServerCode = async (ctx) => {
|
|
|
38
40
|
"utf-8"
|
|
39
41
|
);
|
|
40
42
|
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
41
|
-
const nextFolder = ctx.distDir === ctx.buildConfig.distDir ? ctx.distDir : ctx.nextDistDir;
|
|
43
|
+
const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
|
|
42
44
|
const destDir = join(ctx.serverHandlerDir, nextFolder);
|
|
43
45
|
const paths = await (0, import_fast_glob.default)(
|
|
44
46
|
[`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
|
|
@@ -109,8 +111,9 @@ var copyNextDependencies = async (ctx) => {
|
|
|
109
111
|
await Promise.all(promises);
|
|
110
112
|
const require2 = createRequire(ctx.serverHandlerDir);
|
|
111
113
|
try {
|
|
112
|
-
require2.resolve("
|
|
113
|
-
|
|
114
|
+
const nextEntryAbsolutePath = require2.resolve("next");
|
|
115
|
+
const nextRequire = createRequire(nextEntryAbsolutePath);
|
|
116
|
+
nextRequire.resolve("styled-jsx");
|
|
114
117
|
} catch {
|
|
115
118
|
throw new Error(
|
|
116
119
|
"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"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
// src/build/plugin-context.ts
|
|
9
|
-
import { readFileSync } from "node:fs";
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
10
10
|
import { readFile } from "node:fs/promises";
|
|
11
11
|
import { join, relative, resolve } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
@@ -47,7 +47,7 @@ var PluginContext = class {
|
|
|
47
47
|
* The working directory inside the lambda that is used for monorepos to execute the serverless function
|
|
48
48
|
*/
|
|
49
49
|
get lambdaWorkingDirectory() {
|
|
50
|
-
return join("/var/task", this.
|
|
50
|
+
return join("/var/task", this.distDirParent);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* Retrieves the root of the `.next/standalone` directory
|
|
@@ -64,17 +64,17 @@ var PluginContext = class {
|
|
|
64
64
|
const dir = this.buildConfig.distDir ?? DEFAULT_PUBLISH_DIR;
|
|
65
65
|
return relative(process.cwd(), resolve(this.packagePath, dir));
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
68
|
-
get
|
|
67
|
+
/** Represents the parent directory of the .next folder or custom distDir */
|
|
68
|
+
get distDirParent() {
|
|
69
69
|
return join(this.distDir, "..");
|
|
70
70
|
}
|
|
71
71
|
/** The `.next` folder or what the custom dist dir is set to */
|
|
72
72
|
get nextDistDir() {
|
|
73
|
-
return relative(this.
|
|
73
|
+
return relative(this.distDirParent, this.distDir);
|
|
74
74
|
}
|
|
75
75
|
/** Retrieves the `.next/standalone/` directory monorepo aware */
|
|
76
76
|
get standaloneDir() {
|
|
77
|
-
return join(this.standaloneRootDir, this.
|
|
77
|
+
return join(this.standaloneRootDir, this.distDirParent);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Absolute path of the directory that is published and deployed to the Netlify CDN
|
|
@@ -106,7 +106,7 @@ var PluginContext = class {
|
|
|
106
106
|
if (this.packagePath.length === 0) {
|
|
107
107
|
return this.serverHandlerRootDir;
|
|
108
108
|
}
|
|
109
|
-
return join(this.serverHandlerRootDir, this.
|
|
109
|
+
return join(this.serverHandlerRootDir, this.distDirParent);
|
|
110
110
|
}
|
|
111
111
|
get nextServerHandler() {
|
|
112
112
|
if (this.packagePath.length !== 0) {
|
|
@@ -170,6 +170,18 @@ var PluginContext = class {
|
|
|
170
170
|
failBuild(message, error) {
|
|
171
171
|
return this.utils.build.failBuild(message, error instanceof Error ? { error } : void 0);
|
|
172
172
|
}
|
|
173
|
+
verifyPublishDir() {
|
|
174
|
+
if (!existsSync(this.publishDir)) {
|
|
175
|
+
this.failBuild(
|
|
176
|
+
`Your publish directory was not found at: ${this.publishDir}, please check your build settings`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
if (this.publishDir === this.resolve(this.packagePath)) {
|
|
180
|
+
this.failBuild(
|
|
181
|
+
`Your publish directory cannot be the same as the base directory of your site, please check your build settings`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
173
185
|
};
|
|
174
186
|
|
|
175
187
|
export {
|
|
@@ -8,13 +8,13 @@ import {
|
|
|
8
8
|
copyNextDependencies,
|
|
9
9
|
copyNextServerCode,
|
|
10
10
|
writeTagsManifest
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-52WMBYKL.js";
|
|
12
12
|
import {
|
|
13
13
|
require_out
|
|
14
14
|
} from "./chunk-VZNKO4OO.js";
|
|
15
15
|
import {
|
|
16
16
|
SERVER_HANDLER_NAME
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-655Y7ISI.js";
|
|
18
18
|
import {
|
|
19
19
|
__toESM
|
|
20
20
|
} from "./chunk-5JVNISGM.js";
|
|
@@ -22,17 +22,42 @@ import {
|
|
|
22
22
|
// src/build/functions/server.ts
|
|
23
23
|
var import_fast_glob = __toESM(require_out(), 1);
|
|
24
24
|
import { cp, mkdir, readFile, rm, writeFile } from "fs/promises";
|
|
25
|
-
import { join } from "node:path";
|
|
25
|
+
import { join, relative } from "node:path";
|
|
26
|
+
import { join as posixJoin } from "node:path/posix";
|
|
26
27
|
var copyHandlerDependencies = async (ctx) => {
|
|
28
|
+
const promises = [];
|
|
29
|
+
const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
|
|
30
|
+
if (includedFiles.length !== 0) {
|
|
31
|
+
const resolvedFiles = await Promise.all(
|
|
32
|
+
includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
|
|
33
|
+
);
|
|
34
|
+
for (const filePath of resolvedFiles.flat()) {
|
|
35
|
+
promises.push(
|
|
36
|
+
cp(
|
|
37
|
+
join(process.cwd(), filePath),
|
|
38
|
+
// the serverHandlerDir is aware of the dist dir.
|
|
39
|
+
// The distDir must not be the package path therefore we need to rely on the
|
|
40
|
+
// serverHandlerDir instead of the serverHandlerRootDir
|
|
41
|
+
// therefore we need to remove the package path from the filePath
|
|
42
|
+
join(ctx.serverHandlerDir, relative(ctx.packagePath, filePath)),
|
|
43
|
+
{
|
|
44
|
+
recursive: true,
|
|
45
|
+
force: true
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
27
51
|
const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
for (const filePath of fileList) {
|
|
53
|
+
promises.push(
|
|
54
|
+
cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerDir, ".netlify", filePath), {
|
|
31
55
|
recursive: true,
|
|
32
56
|
force: true
|
|
33
57
|
})
|
|
34
|
-
)
|
|
35
|
-
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
await Promise.all(promises);
|
|
36
61
|
};
|
|
37
62
|
var writeHandlerManifest = async (ctx) => {
|
|
38
63
|
await writeFile(
|
|
@@ -61,7 +86,7 @@ var getHandlerFile = async (ctx) => {
|
|
|
61
86
|
const templatesDir = join(ctx.pluginDir, "dist/build/templates");
|
|
62
87
|
if (ctx.packagePath.length !== 0) {
|
|
63
88
|
const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
|
|
64
|
-
return template.replaceAll("{{cwd}}", ctx.lambdaWorkingDirectory).replace("{{nextServerHandler}}", ctx.nextServerHandler);
|
|
89
|
+
return template.replaceAll("{{cwd}}", posixJoin(ctx.lambdaWorkingDirectory)).replace("{{nextServerHandler}}", posixJoin(ctx.nextServerHandler));
|
|
65
90
|
}
|
|
66
91
|
return await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8");
|
|
67
92
|
};
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
var import_fast_glob = __toESM(require_out(), 1);
|
|
19
19
|
import { existsSync } from "node:fs";
|
|
20
20
|
import { cp, mkdir, rename, rm } from "node:fs/promises";
|
|
21
|
-
import { join } from "node:path";
|
|
21
|
+
import { basename, join } from "node:path";
|
|
22
22
|
var copyStaticContent = async (ctx) => {
|
|
23
23
|
const srcDir = join(ctx.publishDir, "server/pages");
|
|
24
24
|
const destDir = ctx.blobDir;
|
|
@@ -58,7 +58,7 @@ var copyStaticAssets = async (ctx) => {
|
|
|
58
58
|
var publishStaticDir = async (ctx) => {
|
|
59
59
|
try {
|
|
60
60
|
await rm(ctx.tempPublishDir, { recursive: true, force: true });
|
|
61
|
-
await mkdir(ctx.tempPublishDir, { recursive: true });
|
|
61
|
+
await mkdir(basename(ctx.tempPublishDir), { recursive: true });
|
|
62
62
|
await rename(ctx.publishDir, ctx.tempPublishDir);
|
|
63
63
|
await rename(ctx.staticDir, ctx.publishDir);
|
|
64
64
|
} catch (error) {
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
|
|
2
|
+
var require = await (async () => {
|
|
3
|
+
var { createRequire } = await import("node:module");
|
|
4
|
+
return createRequire(import.meta.url);
|
|
5
|
+
})();
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
require_out
|
|
9
|
+
} from "./chunk-VZNKO4OO.js";
|
|
10
|
+
import {
|
|
11
|
+
EDGE_HANDLER_NAME
|
|
12
|
+
} from "./chunk-655Y7ISI.js";
|
|
13
|
+
import {
|
|
14
|
+
__commonJS,
|
|
15
|
+
__toESM
|
|
16
|
+
} from "./chunk-5JVNISGM.js";
|
|
17
|
+
|
|
18
|
+
// node_modules/path-to-regexp/dist/index.js
|
|
19
|
+
var require_dist = __commonJS({
|
|
20
|
+
"node_modules/path-to-regexp/dist/index.js"(exports) {
|
|
21
|
+
"use strict";
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.pathToRegexp = exports.tokensToRegexp = exports.regexpToFunction = exports.match = exports.tokensToFunction = exports.compile = exports.parse = void 0;
|
|
24
|
+
function lexer(str) {
|
|
25
|
+
var tokens = [];
|
|
26
|
+
var i = 0;
|
|
27
|
+
while (i < str.length) {
|
|
28
|
+
var char = str[i];
|
|
29
|
+
if (char === "*" || char === "+" || char === "?") {
|
|
30
|
+
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (char === "\\") {
|
|
34
|
+
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (char === "{") {
|
|
38
|
+
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (char === "}") {
|
|
42
|
+
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (char === ":") {
|
|
46
|
+
var name = "";
|
|
47
|
+
var j = i + 1;
|
|
48
|
+
while (j < str.length) {
|
|
49
|
+
var code = str.charCodeAt(j);
|
|
50
|
+
if (
|
|
51
|
+
// `0-9`
|
|
52
|
+
code >= 48 && code <= 57 || // `A-Z`
|
|
53
|
+
code >= 65 && code <= 90 || // `a-z`
|
|
54
|
+
code >= 97 && code <= 122 || // `_`
|
|
55
|
+
code === 95
|
|
56
|
+
) {
|
|
57
|
+
name += str[j++];
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (!name)
|
|
63
|
+
throw new TypeError("Missing parameter name at ".concat(i));
|
|
64
|
+
tokens.push({ type: "NAME", index: i, value: name });
|
|
65
|
+
i = j;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (char === "(") {
|
|
69
|
+
var count = 1;
|
|
70
|
+
var pattern = "";
|
|
71
|
+
var j = i + 1;
|
|
72
|
+
if (str[j] === "?") {
|
|
73
|
+
throw new TypeError('Pattern cannot start with "?" at '.concat(j));
|
|
74
|
+
}
|
|
75
|
+
while (j < str.length) {
|
|
76
|
+
if (str[j] === "\\") {
|
|
77
|
+
pattern += str[j++] + str[j++];
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (str[j] === ")") {
|
|
81
|
+
count--;
|
|
82
|
+
if (count === 0) {
|
|
83
|
+
j++;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
} else if (str[j] === "(") {
|
|
87
|
+
count++;
|
|
88
|
+
if (str[j + 1] !== "?") {
|
|
89
|
+
throw new TypeError("Capturing groups are not allowed at ".concat(j));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
pattern += str[j++];
|
|
93
|
+
}
|
|
94
|
+
if (count)
|
|
95
|
+
throw new TypeError("Unbalanced pattern at ".concat(i));
|
|
96
|
+
if (!pattern)
|
|
97
|
+
throw new TypeError("Missing pattern at ".concat(i));
|
|
98
|
+
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
99
|
+
i = j;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
103
|
+
}
|
|
104
|
+
tokens.push({ type: "END", index: i, value: "" });
|
|
105
|
+
return tokens;
|
|
106
|
+
}
|
|
107
|
+
function parse(str, options) {
|
|
108
|
+
if (options === void 0) {
|
|
109
|
+
options = {};
|
|
110
|
+
}
|
|
111
|
+
var tokens = lexer(str);
|
|
112
|
+
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
|
|
113
|
+
var defaultPattern = "[^".concat(escapeString(options.delimiter || "/#?"), "]+?");
|
|
114
|
+
var result = [];
|
|
115
|
+
var key = 0;
|
|
116
|
+
var i = 0;
|
|
117
|
+
var path = "";
|
|
118
|
+
var tryConsume = function(type) {
|
|
119
|
+
if (i < tokens.length && tokens[i].type === type)
|
|
120
|
+
return tokens[i++].value;
|
|
121
|
+
};
|
|
122
|
+
var mustConsume = function(type) {
|
|
123
|
+
var value2 = tryConsume(type);
|
|
124
|
+
if (value2 !== void 0)
|
|
125
|
+
return value2;
|
|
126
|
+
var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
|
|
127
|
+
throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
|
|
128
|
+
};
|
|
129
|
+
var consumeText = function() {
|
|
130
|
+
var result2 = "";
|
|
131
|
+
var value2;
|
|
132
|
+
while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
|
133
|
+
result2 += value2;
|
|
134
|
+
}
|
|
135
|
+
return result2;
|
|
136
|
+
};
|
|
137
|
+
while (i < tokens.length) {
|
|
138
|
+
var char = tryConsume("CHAR");
|
|
139
|
+
var name = tryConsume("NAME");
|
|
140
|
+
var pattern = tryConsume("PATTERN");
|
|
141
|
+
if (name || pattern) {
|
|
142
|
+
var prefix = char || "";
|
|
143
|
+
if (prefixes.indexOf(prefix) === -1) {
|
|
144
|
+
path += prefix;
|
|
145
|
+
prefix = "";
|
|
146
|
+
}
|
|
147
|
+
if (path) {
|
|
148
|
+
result.push(path);
|
|
149
|
+
path = "";
|
|
150
|
+
}
|
|
151
|
+
result.push({
|
|
152
|
+
name: name || key++,
|
|
153
|
+
prefix,
|
|
154
|
+
suffix: "",
|
|
155
|
+
pattern: pattern || defaultPattern,
|
|
156
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
157
|
+
});
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
var value = char || tryConsume("ESCAPED_CHAR");
|
|
161
|
+
if (value) {
|
|
162
|
+
path += value;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (path) {
|
|
166
|
+
result.push(path);
|
|
167
|
+
path = "";
|
|
168
|
+
}
|
|
169
|
+
var open = tryConsume("OPEN");
|
|
170
|
+
if (open) {
|
|
171
|
+
var prefix = consumeText();
|
|
172
|
+
var name_1 = tryConsume("NAME") || "";
|
|
173
|
+
var pattern_1 = tryConsume("PATTERN") || "";
|
|
174
|
+
var suffix = consumeText();
|
|
175
|
+
mustConsume("CLOSE");
|
|
176
|
+
result.push({
|
|
177
|
+
name: name_1 || (pattern_1 ? key++ : ""),
|
|
178
|
+
pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
|
|
179
|
+
prefix,
|
|
180
|
+
suffix,
|
|
181
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
182
|
+
});
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
mustConsume("END");
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
exports.parse = parse;
|
|
190
|
+
function compile(str, options) {
|
|
191
|
+
return tokensToFunction(parse(str, options), options);
|
|
192
|
+
}
|
|
193
|
+
exports.compile = compile;
|
|
194
|
+
function tokensToFunction(tokens, options) {
|
|
195
|
+
if (options === void 0) {
|
|
196
|
+
options = {};
|
|
197
|
+
}
|
|
198
|
+
var reFlags = flags(options);
|
|
199
|
+
var _a = options.encode, encode = _a === void 0 ? function(x) {
|
|
200
|
+
return x;
|
|
201
|
+
} : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
|
|
202
|
+
var matches = tokens.map(function(token) {
|
|
203
|
+
if (typeof token === "object") {
|
|
204
|
+
return new RegExp("^(?:".concat(token.pattern, ")$"), reFlags);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return function(data) {
|
|
208
|
+
var path = "";
|
|
209
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
210
|
+
var token = tokens[i];
|
|
211
|
+
if (typeof token === "string") {
|
|
212
|
+
path += token;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
var value = data ? data[token.name] : void 0;
|
|
216
|
+
var optional = token.modifier === "?" || token.modifier === "*";
|
|
217
|
+
var repeat = token.modifier === "*" || token.modifier === "+";
|
|
218
|
+
if (Array.isArray(value)) {
|
|
219
|
+
if (!repeat) {
|
|
220
|
+
throw new TypeError('Expected "'.concat(token.name, '" to not repeat, but got an array'));
|
|
221
|
+
}
|
|
222
|
+
if (value.length === 0) {
|
|
223
|
+
if (optional)
|
|
224
|
+
continue;
|
|
225
|
+
throw new TypeError('Expected "'.concat(token.name, '" to not be empty'));
|
|
226
|
+
}
|
|
227
|
+
for (var j = 0; j < value.length; j++) {
|
|
228
|
+
var segment = encode(value[j], token);
|
|
229
|
+
if (validate && !matches[i].test(segment)) {
|
|
230
|
+
throw new TypeError('Expected all "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
|
|
231
|
+
}
|
|
232
|
+
path += token.prefix + segment + token.suffix;
|
|
233
|
+
}
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
237
|
+
var segment = encode(String(value), token);
|
|
238
|
+
if (validate && !matches[i].test(segment)) {
|
|
239
|
+
throw new TypeError('Expected "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
|
|
240
|
+
}
|
|
241
|
+
path += token.prefix + segment + token.suffix;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (optional)
|
|
245
|
+
continue;
|
|
246
|
+
var typeOfMessage = repeat ? "an array" : "a string";
|
|
247
|
+
throw new TypeError('Expected "'.concat(token.name, '" to be ').concat(typeOfMessage));
|
|
248
|
+
}
|
|
249
|
+
return path;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
exports.tokensToFunction = tokensToFunction;
|
|
253
|
+
function match(str, options) {
|
|
254
|
+
var keys = [];
|
|
255
|
+
var re = pathToRegexp2(str, keys, options);
|
|
256
|
+
return regexpToFunction(re, keys, options);
|
|
257
|
+
}
|
|
258
|
+
exports.match = match;
|
|
259
|
+
function regexpToFunction(re, keys, options) {
|
|
260
|
+
if (options === void 0) {
|
|
261
|
+
options = {};
|
|
262
|
+
}
|
|
263
|
+
var _a = options.decode, decode = _a === void 0 ? function(x) {
|
|
264
|
+
return x;
|
|
265
|
+
} : _a;
|
|
266
|
+
return function(pathname) {
|
|
267
|
+
var m = re.exec(pathname);
|
|
268
|
+
if (!m)
|
|
269
|
+
return false;
|
|
270
|
+
var path = m[0], index = m.index;
|
|
271
|
+
var params = /* @__PURE__ */ Object.create(null);
|
|
272
|
+
var _loop_1 = function(i2) {
|
|
273
|
+
if (m[i2] === void 0)
|
|
274
|
+
return "continue";
|
|
275
|
+
var key = keys[i2 - 1];
|
|
276
|
+
if (key.modifier === "*" || key.modifier === "+") {
|
|
277
|
+
params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
|
|
278
|
+
return decode(value, key);
|
|
279
|
+
});
|
|
280
|
+
} else {
|
|
281
|
+
params[key.name] = decode(m[i2], key);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
for (var i = 1; i < m.length; i++) {
|
|
285
|
+
_loop_1(i);
|
|
286
|
+
}
|
|
287
|
+
return { path, index, params };
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
exports.regexpToFunction = regexpToFunction;
|
|
291
|
+
function escapeString(str) {
|
|
292
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
293
|
+
}
|
|
294
|
+
function flags(options) {
|
|
295
|
+
return options && options.sensitive ? "" : "i";
|
|
296
|
+
}
|
|
297
|
+
function regexpToRegexp(path, keys) {
|
|
298
|
+
if (!keys)
|
|
299
|
+
return path;
|
|
300
|
+
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
301
|
+
var index = 0;
|
|
302
|
+
var execResult = groupsRegex.exec(path.source);
|
|
303
|
+
while (execResult) {
|
|
304
|
+
keys.push({
|
|
305
|
+
// Use parenthesized substring match if available, index otherwise
|
|
306
|
+
name: execResult[1] || index++,
|
|
307
|
+
prefix: "",
|
|
308
|
+
suffix: "",
|
|
309
|
+
modifier: "",
|
|
310
|
+
pattern: ""
|
|
311
|
+
});
|
|
312
|
+
execResult = groupsRegex.exec(path.source);
|
|
313
|
+
}
|
|
314
|
+
return path;
|
|
315
|
+
}
|
|
316
|
+
function arrayToRegexp(paths, keys, options) {
|
|
317
|
+
var parts = paths.map(function(path) {
|
|
318
|
+
return pathToRegexp2(path, keys, options).source;
|
|
319
|
+
});
|
|
320
|
+
return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
|
|
321
|
+
}
|
|
322
|
+
function stringToRegexp(path, keys, options) {
|
|
323
|
+
return tokensToRegexp(parse(path, options), keys, options);
|
|
324
|
+
}
|
|
325
|
+
function tokensToRegexp(tokens, keys, options) {
|
|
326
|
+
if (options === void 0) {
|
|
327
|
+
options = {};
|
|
328
|
+
}
|
|
329
|
+
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function(x) {
|
|
330
|
+
return x;
|
|
331
|
+
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
|
332
|
+
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
|
333
|
+
var delimiterRe = "[".concat(escapeString(delimiter), "]");
|
|
334
|
+
var route = start ? "^" : "";
|
|
335
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
336
|
+
var token = tokens_1[_i];
|
|
337
|
+
if (typeof token === "string") {
|
|
338
|
+
route += escapeString(encode(token));
|
|
339
|
+
} else {
|
|
340
|
+
var prefix = escapeString(encode(token.prefix));
|
|
341
|
+
var suffix = escapeString(encode(token.suffix));
|
|
342
|
+
if (token.pattern) {
|
|
343
|
+
if (keys)
|
|
344
|
+
keys.push(token);
|
|
345
|
+
if (prefix || suffix) {
|
|
346
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
347
|
+
var mod = token.modifier === "*" ? "?" : "";
|
|
348
|
+
route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
|
|
349
|
+
} else {
|
|
350
|
+
route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
|
|
351
|
+
}
|
|
352
|
+
} else {
|
|
353
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
354
|
+
route += "((?:".concat(token.pattern, ")").concat(token.modifier, ")");
|
|
355
|
+
} else {
|
|
356
|
+
route += "(".concat(token.pattern, ")").concat(token.modifier);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (end) {
|
|
365
|
+
if (!strict)
|
|
366
|
+
route += "".concat(delimiterRe, "?");
|
|
367
|
+
route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
|
|
368
|
+
} else {
|
|
369
|
+
var endToken = tokens[tokens.length - 1];
|
|
370
|
+
var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
|
371
|
+
if (!strict) {
|
|
372
|
+
route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
|
|
373
|
+
}
|
|
374
|
+
if (!isEndDelimited) {
|
|
375
|
+
route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return new RegExp(route, flags(options));
|
|
379
|
+
}
|
|
380
|
+
exports.tokensToRegexp = tokensToRegexp;
|
|
381
|
+
function pathToRegexp2(path, keys, options) {
|
|
382
|
+
if (path instanceof RegExp)
|
|
383
|
+
return regexpToRegexp(path, keys);
|
|
384
|
+
if (Array.isArray(path))
|
|
385
|
+
return arrayToRegexp(path, keys, options);
|
|
386
|
+
return stringToRegexp(path, keys, options);
|
|
387
|
+
}
|
|
388
|
+
exports.pathToRegexp = pathToRegexp2;
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// src/build/functions/edge.ts
|
|
393
|
+
var import_fast_glob = __toESM(require_out(), 1);
|
|
394
|
+
var import_path_to_regexp = __toESM(require_dist(), 1);
|
|
395
|
+
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
396
|
+
import { dirname, join, relative } from "node:path";
|
|
397
|
+
var writeEdgeManifest = async (ctx, manifest) => {
|
|
398
|
+
await mkdir(ctx.edgeFunctionsDir, { recursive: true });
|
|
399
|
+
await writeFile(join(ctx.edgeFunctionsDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
400
|
+
};
|
|
401
|
+
var copyRuntime = async (ctx, handlerDirectory) => {
|
|
402
|
+
const files = await (0, import_fast_glob.glob)("edge-runtime/**/*", {
|
|
403
|
+
cwd: ctx.pluginDir,
|
|
404
|
+
ignore: ["**/*.test.ts"],
|
|
405
|
+
dot: true
|
|
406
|
+
});
|
|
407
|
+
await Promise.all(
|
|
408
|
+
files.map(
|
|
409
|
+
(path) => cp(join(ctx.pluginDir, path), join(handlerDirectory, path), { recursive: true })
|
|
410
|
+
)
|
|
411
|
+
);
|
|
412
|
+
};
|
|
413
|
+
var augmentMatchers = (matchers, ctx) => {
|
|
414
|
+
if (!ctx.buildConfig.i18n) {
|
|
415
|
+
return matchers;
|
|
416
|
+
}
|
|
417
|
+
return matchers.flatMap((matcher) => {
|
|
418
|
+
if (matcher.originalSource && matcher.locale !== false) {
|
|
419
|
+
return [
|
|
420
|
+
matcher,
|
|
421
|
+
{
|
|
422
|
+
...matcher,
|
|
423
|
+
regexp: (0, import_path_to_regexp.pathToRegexp)(matcher.originalSource).source
|
|
424
|
+
}
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
return matcher;
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
var writeHandlerFile = async (ctx, { matchers, name }) => {
|
|
431
|
+
const nextConfig = ctx.buildConfig;
|
|
432
|
+
const handlerName = getHandlerName({ name });
|
|
433
|
+
const handlerDirectory = join(ctx.edgeFunctionsDir, handlerName);
|
|
434
|
+
const handlerRuntimeDirectory = join(handlerDirectory, "edge-runtime");
|
|
435
|
+
await copyRuntime(ctx, handlerDirectory);
|
|
436
|
+
await writeFile(
|
|
437
|
+
join(handlerRuntimeDirectory, "matchers.json"),
|
|
438
|
+
JSON.stringify(augmentMatchers(matchers, ctx))
|
|
439
|
+
);
|
|
440
|
+
const minimalNextConfig = {
|
|
441
|
+
basePath: nextConfig.basePath,
|
|
442
|
+
i18n: nextConfig.i18n,
|
|
443
|
+
trailingSlash: nextConfig.trailingSlash,
|
|
444
|
+
skipMiddlewareUrlNormalize: nextConfig.skipMiddlewareUrlNormalize
|
|
445
|
+
};
|
|
446
|
+
await writeFile(
|
|
447
|
+
join(handlerRuntimeDirectory, "next.config.json"),
|
|
448
|
+
JSON.stringify(minimalNextConfig)
|
|
449
|
+
);
|
|
450
|
+
await writeFile(
|
|
451
|
+
join(handlerDirectory, `${handlerName}.js`),
|
|
452
|
+
`
|
|
453
|
+
import {handleMiddleware} from './edge-runtime/middleware.ts';
|
|
454
|
+
import handler from './server/${name}.js';
|
|
455
|
+
export default (req, context) => handleMiddleware(req, context, handler);
|
|
456
|
+
`
|
|
457
|
+
);
|
|
458
|
+
};
|
|
459
|
+
var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
|
|
460
|
+
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
461
|
+
const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
|
|
462
|
+
await Promise.all(
|
|
463
|
+
files.map(async (file) => {
|
|
464
|
+
if (file === `server/${name}.js`) {
|
|
465
|
+
const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
|
|
466
|
+
const shimPath = join(edgeRuntimeDir, "shim/index.js");
|
|
467
|
+
const shim = await readFile(shimPath, "utf8");
|
|
468
|
+
const importsDir = relative(dirname(join(srcDir, file)), join(srcDir, "server"));
|
|
469
|
+
const importsSrc = `${importsDir || "."}/edge-runtime-webpack.js`;
|
|
470
|
+
const imports = `import '${importsSrc}';`;
|
|
471
|
+
const exports = `export default _ENTRIES["middleware_${name}"].default;`;
|
|
472
|
+
const parts = [shim, imports];
|
|
473
|
+
if (wasm?.length) {
|
|
474
|
+
parts.push(
|
|
475
|
+
`import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`
|
|
476
|
+
);
|
|
477
|
+
for (const wasmChunk of wasm ?? []) {
|
|
478
|
+
const data = await readFile(join(srcDir, wasmChunk.filePath));
|
|
479
|
+
parts.push(
|
|
480
|
+
`const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
|
|
481
|
+
data.toString("base64")
|
|
482
|
+
)}).buffer`
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
const entrypoint = await readFile(join(srcDir, file), "utf8");
|
|
487
|
+
await mkdir(dirname(join(destDir, file)), { recursive: true });
|
|
488
|
+
await writeFile(join(destDir, file), [...parts, entrypoint, exports].join("\n;"));
|
|
489
|
+
} else {
|
|
490
|
+
await cp(join(srcDir, file), join(destDir, file));
|
|
491
|
+
}
|
|
492
|
+
})
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
var createEdgeHandler = async (ctx, definition) => {
|
|
496
|
+
await copyHandlerDependencies(ctx, definition);
|
|
497
|
+
await writeHandlerFile(ctx, definition);
|
|
498
|
+
};
|
|
499
|
+
var getHandlerName = ({ name }) => `${EDGE_HANDLER_NAME}-${name.replace(/\W/g, "-")}`;
|
|
500
|
+
var buildHandlerDefinition = (ctx, { name, matchers, page }) => {
|
|
501
|
+
const fun = getHandlerName({ name });
|
|
502
|
+
const funName = name.endsWith("middleware") ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
|
|
503
|
+
const cache = name.endsWith("middleware") ? void 0 : "manual";
|
|
504
|
+
const generator = `${ctx.pluginName}@${ctx.pluginVersion}`;
|
|
505
|
+
return augmentMatchers(matchers, ctx).map((matcher) => ({
|
|
506
|
+
function: fun,
|
|
507
|
+
name: funName,
|
|
508
|
+
pattern: matcher.regexp,
|
|
509
|
+
cache,
|
|
510
|
+
generator
|
|
511
|
+
}));
|
|
512
|
+
};
|
|
513
|
+
var createEdgeHandlers = async (ctx) => {
|
|
514
|
+
await rm(ctx.edgeFunctionsDir, { recursive: true, force: true });
|
|
515
|
+
const nextManifest = await ctx.getMiddlewareManifest();
|
|
516
|
+
const nextDefinitions = [
|
|
517
|
+
...Object.values(nextManifest.middleware)
|
|
518
|
+
// ...Object.values(nextManifest.functions)
|
|
519
|
+
];
|
|
520
|
+
await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)));
|
|
521
|
+
const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def));
|
|
522
|
+
const netlifyManifest = {
|
|
523
|
+
version: 1,
|
|
524
|
+
functions: netlifyDefinitions
|
|
525
|
+
};
|
|
526
|
+
await writeEdgeManifest(ctx, netlifyManifest);
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
export {
|
|
530
|
+
createEdgeHandlers
|
|
531
|
+
};
|
|
@@ -8,7 +8,7 @@ import "./chunk-5JVNISGM.js";
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "@netlify/plugin-nextjs";
|
|
11
|
-
var version = "5.0.0-rc.
|
|
11
|
+
var version = "5.0.0-rc.2";
|
|
12
12
|
var description = "Run Next.js seamlessly on Netlify";
|
|
13
13
|
var main = "./dist/index.js";
|
|
14
14
|
var type = "module";
|
|
@@ -52,12 +52,12 @@ var devDependencies = {
|
|
|
52
52
|
"@fastly/http-compute-js": "1.1.4",
|
|
53
53
|
"@netlify/blobs": "^6.5.0",
|
|
54
54
|
"@netlify/build": "^29.36.1",
|
|
55
|
-
"@netlify/edge-bundler": "^11.
|
|
55
|
+
"@netlify/edge-bundler": "^11.3.0",
|
|
56
56
|
"@netlify/edge-functions": "^2.3.1",
|
|
57
57
|
"@netlify/eslint-config-node": "^7.0.1",
|
|
58
58
|
"@netlify/functions": "^2.5.1",
|
|
59
59
|
"@netlify/serverless-functions-api": "^1.10.1",
|
|
60
|
-
"@netlify/zip-it-and-ship-it": "^9.
|
|
60
|
+
"@netlify/zip-it-and-ship-it": "^9.30.0",
|
|
61
61
|
"@opentelemetry/api": "^1.7.0",
|
|
62
62
|
"@opentelemetry/exporter-trace-otlp-http": "^0.48.0",
|
|
63
63
|
"@opentelemetry/resources": "^1.21.0",
|
|
@@ -84,6 +84,7 @@ var devDependencies = {
|
|
|
84
84
|
os: "^0.1.2",
|
|
85
85
|
outdent: "^0.8.0",
|
|
86
86
|
"p-limit": "^4.0.0",
|
|
87
|
+
"path-to-regexp": "^6.2.1",
|
|
87
88
|
picomatch: "^3.0.1",
|
|
88
89
|
"regexp-tree": "^0.1.27",
|
|
89
90
|
typescript: "^5.1.6",
|
package/dist/index.js
CHANGED
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
copyStaticContent,
|
|
13
13
|
publishStaticDir,
|
|
14
14
|
unpublishStaticDir
|
|
15
|
-
} from "./esm-chunks/chunk-
|
|
15
|
+
} from "./esm-chunks/chunk-MPZEWLBG.js";
|
|
16
16
|
import {
|
|
17
17
|
createEdgeHandlers
|
|
18
|
-
} from "./esm-chunks/chunk-
|
|
18
|
+
} from "./esm-chunks/chunk-ZZOGIP2V.js";
|
|
19
19
|
import {
|
|
20
20
|
createServerHandler
|
|
21
|
-
} from "./esm-chunks/chunk-
|
|
22
|
-
import "./esm-chunks/chunk-
|
|
21
|
+
} from "./esm-chunks/chunk-E3NFUTWC.js";
|
|
22
|
+
import "./esm-chunks/chunk-52WMBYKL.js";
|
|
23
23
|
import "./esm-chunks/chunk-VZNKO4OO.js";
|
|
24
24
|
import {
|
|
25
25
|
restoreBuildCache,
|
|
@@ -30,13 +30,12 @@ import {
|
|
|
30
30
|
} from "./esm-chunks/chunk-XXBTIYSL.js";
|
|
31
31
|
import {
|
|
32
32
|
PluginContext
|
|
33
|
-
} from "./esm-chunks/chunk-
|
|
33
|
+
} from "./esm-chunks/chunk-655Y7ISI.js";
|
|
34
34
|
import "./esm-chunks/chunk-UYKENJEU.js";
|
|
35
35
|
import "./esm-chunks/chunk-TYCYFZ22.js";
|
|
36
36
|
import "./esm-chunks/chunk-5JVNISGM.js";
|
|
37
37
|
|
|
38
38
|
// src/index.ts
|
|
39
|
-
import { existsSync } from "node:fs";
|
|
40
39
|
var onPreBuild = async (options) => {
|
|
41
40
|
process.env.NEXT_PRIVATE_STANDALONE = "true";
|
|
42
41
|
if (!options.constants.IS_LOCAL) {
|
|
@@ -45,12 +44,7 @@ var onPreBuild = async (options) => {
|
|
|
45
44
|
};
|
|
46
45
|
var onBuild = async (options) => {
|
|
47
46
|
const ctx = new PluginContext(options);
|
|
48
|
-
|
|
49
|
-
ctx.failBuild(
|
|
50
|
-
`Publish directory not found under: ${ctx.publishDir}, please check your netlify.toml`
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
await setImageConfig(ctx);
|
|
47
|
+
ctx.verifyPublishDir();
|
|
54
48
|
if (!options.constants.IS_LOCAL) {
|
|
55
49
|
await saveBuildCache(ctx);
|
|
56
50
|
}
|
|
@@ -59,7 +53,8 @@ var onBuild = async (options) => {
|
|
|
59
53
|
copyStaticContent(ctx),
|
|
60
54
|
copyPrerenderedContent(ctx),
|
|
61
55
|
createServerHandler(ctx),
|
|
62
|
-
createEdgeHandlers(ctx)
|
|
56
|
+
createEdgeHandlers(ctx),
|
|
57
|
+
setImageConfig(ctx)
|
|
63
58
|
]);
|
|
64
59
|
};
|
|
65
60
|
var onPostBuild = async (options) => {
|
package/dist/run/config.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../../esm-chunks/chunk-HYBEXB2Z.js";
|
|
13
13
|
import {
|
|
14
14
|
getTagsManifest
|
|
15
|
-
} from "../../esm-chunks/chunk-
|
|
15
|
+
} from "../../esm-chunks/chunk-3SUDZQ7L.js";
|
|
16
16
|
import "../../esm-chunks/chunk-UYKENJEU.js";
|
|
17
17
|
import {
|
|
18
18
|
adjustDateHeader,
|
|
@@ -52794,7 +52794,7 @@ var import_semantic_conventions = __toESM(require_src2(), 1);
|
|
|
52794
52794
|
var import_api = __toESM(require_src(), 1);
|
|
52795
52795
|
var {
|
|
52796
52796
|
default: { version, name }
|
|
52797
|
-
} = await import("../../esm-chunks/package-
|
|
52797
|
+
} = await import("../../esm-chunks/package-V53S3A76.js");
|
|
52798
52798
|
var sdk = new import_sdk_node.NodeSDK({
|
|
52799
52799
|
resource: new import_resources.Resource({
|
|
52800
52800
|
[import_semantic_conventions.SemanticResourceAttributes.SERVICE_NAME]: name,
|
|
@@ -24,6 +24,7 @@ export interface RequestData {
|
|
|
24
24
|
basePath?: string
|
|
25
25
|
i18n?: I18NConfig | null
|
|
26
26
|
trailingSlash?: boolean
|
|
27
|
+
skipMiddlewareUrlNormalize?: boolean
|
|
27
28
|
}
|
|
28
29
|
page?: {
|
|
29
30
|
name?: string
|
|
@@ -50,19 +51,23 @@ const normalizeRequestURL = (
|
|
|
50
51
|
url.pathname,
|
|
51
52
|
nextConfig?.i18n?.locales,
|
|
52
53
|
)
|
|
53
|
-
|
|
54
|
+
if (!nextConfig?.skipMiddlewareUrlNormalize) {
|
|
55
|
+
url.pathname = pathname || '/'
|
|
56
|
+
}
|
|
54
57
|
detectedLocale = detected
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (!nextConfig?.skipMiddlewareUrlNormalize) {
|
|
61
|
+
// We want to run middleware for data requests and expose the URL of the
|
|
62
|
+
// corresponding pages, so we have to normalize the URLs before running
|
|
63
|
+
// the handler.
|
|
64
|
+
url.pathname = normalizeDataUrl(url.pathname)
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
// Normalizing the trailing slash based on the `trailingSlash` configuration
|
|
67
|
+
// property from the Next.js config.
|
|
68
|
+
if (nextConfig?.trailingSlash && url.pathname !== '/' && !url.pathname.endsWith('/')) {
|
|
69
|
+
url.pathname = `${url.pathname}/`
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
if (didRemoveBasePath) {
|
|
@@ -247,9 +247,10 @@ function normalizeLocalizedTarget({
|
|
|
247
247
|
!normalizedTarget.pathname.startsWith(`/api/`) &&
|
|
248
248
|
!normalizedTarget.pathname.startsWith(`/_next/static/`)
|
|
249
249
|
) {
|
|
250
|
-
targetUrl.pathname =
|
|
250
|
+
targetUrl.pathname =
|
|
251
|
+
addBasePath(`/${locale}${normalizedTarget.pathname}`, nextConfig?.basePath) || `/`
|
|
251
252
|
} else {
|
|
252
|
-
targetUrl.pathname = addBasePath(normalizedTarget.pathname, nextConfig?.basePath)
|
|
253
|
+
targetUrl.pathname = addBasePath(normalizedTarget.pathname, nextConfig?.basePath) || `/`
|
|
253
254
|
}
|
|
254
255
|
return targetUrl.toString()
|
|
255
256
|
}
|
package/edge-runtime/lib/util.ts
CHANGED
|
@@ -56,7 +56,7 @@ export function normalizeLocalePath(pathname: string, locales?: string[]): PathL
|
|
|
56
56
|
if (pathnameParts[1] && pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
|
|
57
57
|
detectedLocale = locale
|
|
58
58
|
pathnameParts.splice(1, 1)
|
|
59
|
-
pathname = pathnameParts.join('/')
|
|
59
|
+
pathname = pathnameParts.join('/')
|
|
60
60
|
return true
|
|
61
61
|
}
|
|
62
62
|
return false
|
package/package.json
CHANGED
|
@@ -1,134 +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
|
-
require_out
|
|
9
|
-
} from "./chunk-VZNKO4OO.js";
|
|
10
|
-
import {
|
|
11
|
-
EDGE_HANDLER_NAME
|
|
12
|
-
} from "./chunk-PGQNT7XM.js";
|
|
13
|
-
import {
|
|
14
|
-
__toESM
|
|
15
|
-
} from "./chunk-5JVNISGM.js";
|
|
16
|
-
|
|
17
|
-
// src/build/functions/edge.ts
|
|
18
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
19
|
-
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
20
|
-
import { dirname, join, relative } from "node:path";
|
|
21
|
-
var writeEdgeManifest = async (ctx, manifest) => {
|
|
22
|
-
await mkdir(ctx.edgeFunctionsDir, { recursive: true });
|
|
23
|
-
await writeFile(join(ctx.edgeFunctionsDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
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
|
-
};
|
|
37
|
-
var writeHandlerFile = async (ctx, { matchers, name }) => {
|
|
38
|
-
const nextConfig = ctx.buildConfig;
|
|
39
|
-
const handlerName = getHandlerName({ name });
|
|
40
|
-
const handlerDirectory = join(ctx.edgeFunctionsDir, handlerName);
|
|
41
|
-
const handlerRuntimeDirectory = join(handlerDirectory, "edge-runtime");
|
|
42
|
-
await copyRuntime(ctx, handlerDirectory);
|
|
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
|
-
);
|
|
53
|
-
await writeFile(
|
|
54
|
-
join(handlerDirectory, `${handlerName}.js`),
|
|
55
|
-
`
|
|
56
|
-
import {handleMiddleware} from './edge-runtime/middleware.ts';
|
|
57
|
-
import handler from './server/${name}.js';
|
|
58
|
-
export default (req, context) => handleMiddleware(req, context, handler);
|
|
59
|
-
`
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
|
|
63
|
-
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
64
|
-
const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
|
|
65
|
-
await Promise.all(
|
|
66
|
-
files.map(async (file) => {
|
|
67
|
-
if (file === `server/${name}.js`) {
|
|
68
|
-
const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
|
|
69
|
-
const shimPath = join(edgeRuntimeDir, "shim/index.js");
|
|
70
|
-
const shim = await readFile(shimPath, "utf8");
|
|
71
|
-
const importsDir = relative(dirname(join(srcDir, file)), join(srcDir, "server"));
|
|
72
|
-
const importsSrc = `${importsDir || "."}/edge-runtime-webpack.js`;
|
|
73
|
-
const imports = `import '${importsSrc}';`;
|
|
74
|
-
const exports = `export default _ENTRIES["middleware_${name}"].default;`;
|
|
75
|
-
const parts = [shim, imports];
|
|
76
|
-
if (wasm?.length) {
|
|
77
|
-
parts.push(
|
|
78
|
-
`import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`
|
|
79
|
-
);
|
|
80
|
-
for (const wasmChunk of wasm ?? []) {
|
|
81
|
-
const data = await readFile(join(srcDir, wasmChunk.filePath));
|
|
82
|
-
parts.push(
|
|
83
|
-
`const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
|
|
84
|
-
data.toString("base64")
|
|
85
|
-
)}).buffer`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
const entrypoint = await readFile(join(srcDir, file), "utf8");
|
|
90
|
-
await mkdir(dirname(join(destDir, file)), { recursive: true });
|
|
91
|
-
await writeFile(join(destDir, file), [...parts, entrypoint, exports].join("\n;"));
|
|
92
|
-
} else {
|
|
93
|
-
await cp(join(srcDir, file), join(destDir, file));
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
var createEdgeHandler = async (ctx, definition) => {
|
|
99
|
-
await copyHandlerDependencies(ctx, definition);
|
|
100
|
-
await writeHandlerFile(ctx, definition);
|
|
101
|
-
};
|
|
102
|
-
var getHandlerName = ({ name }) => `${EDGE_HANDLER_NAME}-${name.replace(/\W/g, "-")}`;
|
|
103
|
-
var buildHandlerDefinition = (ctx, { name, matchers, page }) => {
|
|
104
|
-
const fun = getHandlerName({ name });
|
|
105
|
-
const funName = name.endsWith("middleware") ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
|
|
106
|
-
const cache = name.endsWith("middleware") ? void 0 : "manual";
|
|
107
|
-
const generator = `${ctx.pluginName}@${ctx.pluginVersion}`;
|
|
108
|
-
return matchers.map((matcher) => ({
|
|
109
|
-
function: fun,
|
|
110
|
-
name: funName,
|
|
111
|
-
pattern: matcher.regexp,
|
|
112
|
-
cache,
|
|
113
|
-
generator
|
|
114
|
-
}));
|
|
115
|
-
};
|
|
116
|
-
var createEdgeHandlers = async (ctx) => {
|
|
117
|
-
await rm(ctx.edgeFunctionsDir, { recursive: true, force: true });
|
|
118
|
-
const nextManifest = await ctx.getMiddlewareManifest();
|
|
119
|
-
const nextDefinitions = [
|
|
120
|
-
...Object.values(nextManifest.middleware)
|
|
121
|
-
// ...Object.values(nextManifest.functions)
|
|
122
|
-
];
|
|
123
|
-
await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)));
|
|
124
|
-
const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def));
|
|
125
|
-
const netlifyManifest = {
|
|
126
|
-
version: 1,
|
|
127
|
-
functions: netlifyDefinitions
|
|
128
|
-
};
|
|
129
|
-
await writeEdgeManifest(ctx, netlifyManifest);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
createEdgeHandlers
|
|
134
|
-
};
|