@netlify/plugin-nextjs 5.10.0-fetch-patch-logs → 5.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/advanced-api-routes.js +136 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +293 -11
- package/dist/build/content/server.js +219 -11
- package/dist/build/content/static.js +112 -15
- package/dist/build/functions/edge.js +540 -7
- package/dist/build/functions/server.js +130 -11
- package/dist/build/image-cdn.js +1599 -3
- package/dist/build/plugin-context.js +292 -6
- package/dist/build/verification.js +104 -9
- package/dist/esm-chunks/{package-F536DQ6H.js → package-UN6EVEHD.js} +1 -1
- package/dist/index.js +18 -39
- package/dist/run/config.js +1 -4
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +44 -1655
- package/dist/run/handlers/server.js +14 -33
- package/dist/run/handlers/tracer.cjs +2 -114
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +198 -10
- package/dist/run/next.cjs +11 -1624
- package/dist/run/regional-blob-store.cjs +37 -5
- package/dist/run/revalidate.js +24 -3
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
- package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
- package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
- package/dist/esm-chunks/chunk-HXVWGXWM.js +0 -218
- package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
- package/dist/esm-chunks/chunk-JPTD4GEB.js +0 -309
- package/dist/esm-chunks/chunk-MKMK7FBF.js +0 -132
- package/dist/esm-chunks/chunk-RYJYZQ4X.js +0 -610
- package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
- package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
- package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
- package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
- package/dist/esm-chunks/next-LDOXJ7XH.js +0 -567
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/run/regional-blob-store.cts
|
|
21
21
|
var regional_blob_store_exports = {};
|
|
22
22
|
__export(regional_blob_store_exports, {
|
|
23
|
-
getRegionalBlobStore: () => getRegionalBlobStore
|
|
23
|
+
getRegionalBlobStore: () => getRegionalBlobStore,
|
|
24
|
+
setFetchBeforeNextPatchedIt: () => setFetchBeforeNextPatchedIt
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(regional_blob_store_exports);
|
|
26
27
|
|
|
@@ -614,16 +615,47 @@ var getDeployStore = (input = {}) => {
|
|
|
614
615
|
};
|
|
615
616
|
|
|
616
617
|
// src/run/regional-blob-store.cts
|
|
617
|
-
var
|
|
618
|
+
var FETCH_BEFORE_NEXT_PATCHED_IT = Symbol.for("nf-not-patched-fetch");
|
|
619
|
+
var extendedGlobalThis = globalThis;
|
|
620
|
+
function attemptToGetOriginalFetch(fetch) {
|
|
621
|
+
return fetch._nextOriginalFetch ?? fetch;
|
|
622
|
+
}
|
|
623
|
+
function forceOptOutOfUsingDataCache(fetch) {
|
|
624
|
+
return (input, init) => {
|
|
625
|
+
return fetch(input, {
|
|
626
|
+
...init,
|
|
627
|
+
next: {
|
|
628
|
+
...init?.next,
|
|
629
|
+
// setting next.internal = true should prevent from trying to use data cache
|
|
630
|
+
// https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L174
|
|
631
|
+
// https://github.com/vercel/next.js/blob/fa214c74c1d8023098c0e94e57f917ef9f1afd1a/packages/next/src/server/lib/patch-fetch.ts#L210-L213
|
|
632
|
+
// this is last line of defense in case we didn't manage to get unpatched fetch that will not affect
|
|
633
|
+
// fetch if it's unpatched so it should be safe to apply always if we aren't sure if we use patched fetch
|
|
634
|
+
// @ts-expect-error - this is an internal field that Next.js doesn't add to its global
|
|
635
|
+
// type overrides for RequestInit type (like `next.revalidate` or `next.tags`)
|
|
636
|
+
internal: true
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
var setFetchBeforeNextPatchedIt = (fetch) => {
|
|
642
|
+
extendedGlobalThis[FETCH_BEFORE_NEXT_PATCHED_IT] = forceOptOutOfUsingDataCache(
|
|
643
|
+
attemptToGetOriginalFetch(fetch)
|
|
644
|
+
);
|
|
645
|
+
};
|
|
646
|
+
var fetchBeforeNextPatchedItFallback = forceOptOutOfUsingDataCache(
|
|
647
|
+
attemptToGetOriginalFetch(globalThis.fetch)
|
|
648
|
+
);
|
|
649
|
+
var getFetchBeforeNextPatchedIt = () => extendedGlobalThis[FETCH_BEFORE_NEXT_PATCHED_IT] ?? fetchBeforeNextPatchedItFallback;
|
|
618
650
|
var getRegionalBlobStore = (args = {}) => {
|
|
619
|
-
console.log("Blob store fetch patched", fetchBeforeNextPatchedIt.__nextPatched);
|
|
620
651
|
return getDeployStore({
|
|
621
652
|
...args,
|
|
622
|
-
fetch:
|
|
653
|
+
fetch: getFetchBeforeNextPatchedIt(),
|
|
623
654
|
region: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? void 0 : "us-east-2"
|
|
624
655
|
});
|
|
625
656
|
};
|
|
626
657
|
// Annotate the CommonJS export names for ESM import in node:
|
|
627
658
|
0 && (module.exports = {
|
|
628
|
-
getRegionalBlobStore
|
|
659
|
+
getRegionalBlobStore,
|
|
660
|
+
setFetchBeforeNextPatchedIt
|
|
629
661
|
});
|
package/dist/run/revalidate.js
CHANGED
|
@@ -4,10 +4,31 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
nextResponseProxy
|
|
9
|
-
} from "../esm-chunks/chunk-XS27YRA5.js";
|
|
10
7
|
import "../esm-chunks/chunk-OEQOKJGE.js";
|
|
8
|
+
|
|
9
|
+
// src/run/revalidate.ts
|
|
10
|
+
import { isPromise } from "node:util/types";
|
|
11
|
+
function isRevalidateMethod(key, nextResponseField) {
|
|
12
|
+
return key === "revalidate" && typeof nextResponseField === "function";
|
|
13
|
+
}
|
|
14
|
+
var nextResponseProxy = (res, requestContext) => {
|
|
15
|
+
return new Proxy(res, {
|
|
16
|
+
get(target, key) {
|
|
17
|
+
const originalValue = Reflect.get(target, key);
|
|
18
|
+
if (isRevalidateMethod(key, originalValue)) {
|
|
19
|
+
return function newRevalidate(...args) {
|
|
20
|
+
requestContext.didPagesRouterOnDemandRevalidate = true;
|
|
21
|
+
const result = originalValue.apply(target, args);
|
|
22
|
+
if (result && isPromise(result)) {
|
|
23
|
+
requestContext.trackBackgroundWork(result);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return originalValue;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
11
32
|
export {
|
|
12
33
|
nextResponseProxy
|
|
13
34
|
};
|
package/dist/shared/blobkey.js
CHANGED
|
@@ -4,10 +4,22 @@
|
|
|
4
4
|
return createRequire(import.meta.url);
|
|
5
5
|
})();
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
encodeBlobKey
|
|
9
|
-
} from "../esm-chunks/chunk-TYCYFZ22.js";
|
|
10
7
|
import "../esm-chunks/chunk-OEQOKJGE.js";
|
|
8
|
+
|
|
9
|
+
// src/shared/blobkey.ts
|
|
10
|
+
import { Buffer } from "node:buffer";
|
|
11
|
+
import { webcrypto as crypto } from "node:crypto";
|
|
12
|
+
var maxLength = 180;
|
|
13
|
+
async function encodeBlobKey(key) {
|
|
14
|
+
const buffer = Buffer.from(key);
|
|
15
|
+
const base64 = buffer.toString("base64url");
|
|
16
|
+
if (base64.length <= maxLength) {
|
|
17
|
+
return base64;
|
|
18
|
+
}
|
|
19
|
+
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
20
|
+
const hash = Buffer.from(digest).toString("base64url");
|
|
21
|
+
return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
|
|
22
|
+
}
|
|
11
23
|
export {
|
|
12
24
|
encodeBlobKey
|
|
13
25
|
};
|
package/package.json
CHANGED
|
@@ -1,554 +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
|
-
EDGE_HANDLER_NAME
|
|
9
|
-
} from "./chunk-GFYWJNQR.js";
|
|
10
|
-
import {
|
|
11
|
-
require_out
|
|
12
|
-
} from "./chunk-KGYJQ2U2.js";
|
|
13
|
-
import {
|
|
14
|
-
__commonJS,
|
|
15
|
-
__toESM
|
|
16
|
-
} from "./chunk-OEQOKJGE.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, _b = options.delimiter, delimiter = _b === void 0 ? "/#?" : _b;
|
|
113
|
-
var result = [];
|
|
114
|
-
var key = 0;
|
|
115
|
-
var i = 0;
|
|
116
|
-
var path = "";
|
|
117
|
-
var tryConsume = function(type) {
|
|
118
|
-
if (i < tokens.length && tokens[i].type === type)
|
|
119
|
-
return tokens[i++].value;
|
|
120
|
-
};
|
|
121
|
-
var mustConsume = function(type) {
|
|
122
|
-
var value2 = tryConsume(type);
|
|
123
|
-
if (value2 !== void 0)
|
|
124
|
-
return value2;
|
|
125
|
-
var _a2 = tokens[i], nextType = _a2.type, index = _a2.index;
|
|
126
|
-
throw new TypeError("Unexpected ".concat(nextType, " at ").concat(index, ", expected ").concat(type));
|
|
127
|
-
};
|
|
128
|
-
var consumeText = function() {
|
|
129
|
-
var result2 = "";
|
|
130
|
-
var value2;
|
|
131
|
-
while (value2 = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR")) {
|
|
132
|
-
result2 += value2;
|
|
133
|
-
}
|
|
134
|
-
return result2;
|
|
135
|
-
};
|
|
136
|
-
var isSafe = function(value2) {
|
|
137
|
-
for (var _i = 0, delimiter_1 = delimiter; _i < delimiter_1.length; _i++) {
|
|
138
|
-
var char2 = delimiter_1[_i];
|
|
139
|
-
if (value2.indexOf(char2) > -1)
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
return false;
|
|
143
|
-
};
|
|
144
|
-
var safePattern = function(prefix2) {
|
|
145
|
-
var prev = result[result.length - 1];
|
|
146
|
-
var prevText = prefix2 || (prev && typeof prev === "string" ? prev : "");
|
|
147
|
-
if (prev && !prevText) {
|
|
148
|
-
throw new TypeError('Must have text between two parameters, missing text after "'.concat(prev.name, '"'));
|
|
149
|
-
}
|
|
150
|
-
if (!prevText || isSafe(prevText))
|
|
151
|
-
return "[^".concat(escapeString(delimiter), "]+?");
|
|
152
|
-
return "(?:(?!".concat(escapeString(prevText), ")[^").concat(escapeString(delimiter), "])+?");
|
|
153
|
-
};
|
|
154
|
-
while (i < tokens.length) {
|
|
155
|
-
var char = tryConsume("CHAR");
|
|
156
|
-
var name = tryConsume("NAME");
|
|
157
|
-
var pattern = tryConsume("PATTERN");
|
|
158
|
-
if (name || pattern) {
|
|
159
|
-
var prefix = char || "";
|
|
160
|
-
if (prefixes.indexOf(prefix) === -1) {
|
|
161
|
-
path += prefix;
|
|
162
|
-
prefix = "";
|
|
163
|
-
}
|
|
164
|
-
if (path) {
|
|
165
|
-
result.push(path);
|
|
166
|
-
path = "";
|
|
167
|
-
}
|
|
168
|
-
result.push({
|
|
169
|
-
name: name || key++,
|
|
170
|
-
prefix,
|
|
171
|
-
suffix: "",
|
|
172
|
-
pattern: pattern || safePattern(prefix),
|
|
173
|
-
modifier: tryConsume("MODIFIER") || ""
|
|
174
|
-
});
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
var value = char || tryConsume("ESCAPED_CHAR");
|
|
178
|
-
if (value) {
|
|
179
|
-
path += value;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
if (path) {
|
|
183
|
-
result.push(path);
|
|
184
|
-
path = "";
|
|
185
|
-
}
|
|
186
|
-
var open = tryConsume("OPEN");
|
|
187
|
-
if (open) {
|
|
188
|
-
var prefix = consumeText();
|
|
189
|
-
var name_1 = tryConsume("NAME") || "";
|
|
190
|
-
var pattern_1 = tryConsume("PATTERN") || "";
|
|
191
|
-
var suffix = consumeText();
|
|
192
|
-
mustConsume("CLOSE");
|
|
193
|
-
result.push({
|
|
194
|
-
name: name_1 || (pattern_1 ? key++ : ""),
|
|
195
|
-
pattern: name_1 && !pattern_1 ? safePattern(prefix) : pattern_1,
|
|
196
|
-
prefix,
|
|
197
|
-
suffix,
|
|
198
|
-
modifier: tryConsume("MODIFIER") || ""
|
|
199
|
-
});
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
mustConsume("END");
|
|
203
|
-
}
|
|
204
|
-
return result;
|
|
205
|
-
}
|
|
206
|
-
exports.parse = parse;
|
|
207
|
-
function compile(str, options) {
|
|
208
|
-
return tokensToFunction(parse(str, options), options);
|
|
209
|
-
}
|
|
210
|
-
exports.compile = compile;
|
|
211
|
-
function tokensToFunction(tokens, options) {
|
|
212
|
-
if (options === void 0) {
|
|
213
|
-
options = {};
|
|
214
|
-
}
|
|
215
|
-
var reFlags = flags(options);
|
|
216
|
-
var _a = options.encode, encode = _a === void 0 ? function(x) {
|
|
217
|
-
return x;
|
|
218
|
-
} : _a, _b = options.validate, validate = _b === void 0 ? true : _b;
|
|
219
|
-
var matches = tokens.map(function(token) {
|
|
220
|
-
if (typeof token === "object") {
|
|
221
|
-
return new RegExp("^(?:".concat(token.pattern, ")$"), reFlags);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
return function(data) {
|
|
225
|
-
var path = "";
|
|
226
|
-
for (var i = 0; i < tokens.length; i++) {
|
|
227
|
-
var token = tokens[i];
|
|
228
|
-
if (typeof token === "string") {
|
|
229
|
-
path += token;
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
var value = data ? data[token.name] : void 0;
|
|
233
|
-
var optional = token.modifier === "?" || token.modifier === "*";
|
|
234
|
-
var repeat = token.modifier === "*" || token.modifier === "+";
|
|
235
|
-
if (Array.isArray(value)) {
|
|
236
|
-
if (!repeat) {
|
|
237
|
-
throw new TypeError('Expected "'.concat(token.name, '" to not repeat, but got an array'));
|
|
238
|
-
}
|
|
239
|
-
if (value.length === 0) {
|
|
240
|
-
if (optional)
|
|
241
|
-
continue;
|
|
242
|
-
throw new TypeError('Expected "'.concat(token.name, '" to not be empty'));
|
|
243
|
-
}
|
|
244
|
-
for (var j = 0; j < value.length; j++) {
|
|
245
|
-
var segment = encode(value[j], token);
|
|
246
|
-
if (validate && !matches[i].test(segment)) {
|
|
247
|
-
throw new TypeError('Expected all "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
|
|
248
|
-
}
|
|
249
|
-
path += token.prefix + segment + token.suffix;
|
|
250
|
-
}
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
254
|
-
var segment = encode(String(value), token);
|
|
255
|
-
if (validate && !matches[i].test(segment)) {
|
|
256
|
-
throw new TypeError('Expected "'.concat(token.name, '" to match "').concat(token.pattern, '", but got "').concat(segment, '"'));
|
|
257
|
-
}
|
|
258
|
-
path += token.prefix + segment + token.suffix;
|
|
259
|
-
continue;
|
|
260
|
-
}
|
|
261
|
-
if (optional)
|
|
262
|
-
continue;
|
|
263
|
-
var typeOfMessage = repeat ? "an array" : "a string";
|
|
264
|
-
throw new TypeError('Expected "'.concat(token.name, '" to be ').concat(typeOfMessage));
|
|
265
|
-
}
|
|
266
|
-
return path;
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
exports.tokensToFunction = tokensToFunction;
|
|
270
|
-
function match(str, options) {
|
|
271
|
-
var keys = [];
|
|
272
|
-
var re = pathToRegexp2(str, keys, options);
|
|
273
|
-
return regexpToFunction(re, keys, options);
|
|
274
|
-
}
|
|
275
|
-
exports.match = match;
|
|
276
|
-
function regexpToFunction(re, keys, options) {
|
|
277
|
-
if (options === void 0) {
|
|
278
|
-
options = {};
|
|
279
|
-
}
|
|
280
|
-
var _a = options.decode, decode = _a === void 0 ? function(x) {
|
|
281
|
-
return x;
|
|
282
|
-
} : _a;
|
|
283
|
-
return function(pathname) {
|
|
284
|
-
var m = re.exec(pathname);
|
|
285
|
-
if (!m)
|
|
286
|
-
return false;
|
|
287
|
-
var path = m[0], index = m.index;
|
|
288
|
-
var params = /* @__PURE__ */ Object.create(null);
|
|
289
|
-
var _loop_1 = function(i2) {
|
|
290
|
-
if (m[i2] === void 0)
|
|
291
|
-
return "continue";
|
|
292
|
-
var key = keys[i2 - 1];
|
|
293
|
-
if (key.modifier === "*" || key.modifier === "+") {
|
|
294
|
-
params[key.name] = m[i2].split(key.prefix + key.suffix).map(function(value) {
|
|
295
|
-
return decode(value, key);
|
|
296
|
-
});
|
|
297
|
-
} else {
|
|
298
|
-
params[key.name] = decode(m[i2], key);
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
for (var i = 1; i < m.length; i++) {
|
|
302
|
-
_loop_1(i);
|
|
303
|
-
}
|
|
304
|
-
return { path, index, params };
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
exports.regexpToFunction = regexpToFunction;
|
|
308
|
-
function escapeString(str) {
|
|
309
|
-
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
310
|
-
}
|
|
311
|
-
function flags(options) {
|
|
312
|
-
return options && options.sensitive ? "" : "i";
|
|
313
|
-
}
|
|
314
|
-
function regexpToRegexp(path, keys) {
|
|
315
|
-
if (!keys)
|
|
316
|
-
return path;
|
|
317
|
-
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
318
|
-
var index = 0;
|
|
319
|
-
var execResult = groupsRegex.exec(path.source);
|
|
320
|
-
while (execResult) {
|
|
321
|
-
keys.push({
|
|
322
|
-
// Use parenthesized substring match if available, index otherwise
|
|
323
|
-
name: execResult[1] || index++,
|
|
324
|
-
prefix: "",
|
|
325
|
-
suffix: "",
|
|
326
|
-
modifier: "",
|
|
327
|
-
pattern: ""
|
|
328
|
-
});
|
|
329
|
-
execResult = groupsRegex.exec(path.source);
|
|
330
|
-
}
|
|
331
|
-
return path;
|
|
332
|
-
}
|
|
333
|
-
function arrayToRegexp(paths, keys, options) {
|
|
334
|
-
var parts = paths.map(function(path) {
|
|
335
|
-
return pathToRegexp2(path, keys, options).source;
|
|
336
|
-
});
|
|
337
|
-
return new RegExp("(?:".concat(parts.join("|"), ")"), flags(options));
|
|
338
|
-
}
|
|
339
|
-
function stringToRegexp(path, keys, options) {
|
|
340
|
-
return tokensToRegexp(parse(path, options), keys, options);
|
|
341
|
-
}
|
|
342
|
-
function tokensToRegexp(tokens, keys, options) {
|
|
343
|
-
if (options === void 0) {
|
|
344
|
-
options = {};
|
|
345
|
-
}
|
|
346
|
-
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) {
|
|
347
|
-
return x;
|
|
348
|
-
} : _d, _e = options.delimiter, delimiter = _e === void 0 ? "/#?" : _e, _f = options.endsWith, endsWith = _f === void 0 ? "" : _f;
|
|
349
|
-
var endsWithRe = "[".concat(escapeString(endsWith), "]|$");
|
|
350
|
-
var delimiterRe = "[".concat(escapeString(delimiter), "]");
|
|
351
|
-
var route = start ? "^" : "";
|
|
352
|
-
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
353
|
-
var token = tokens_1[_i];
|
|
354
|
-
if (typeof token === "string") {
|
|
355
|
-
route += escapeString(encode(token));
|
|
356
|
-
} else {
|
|
357
|
-
var prefix = escapeString(encode(token.prefix));
|
|
358
|
-
var suffix = escapeString(encode(token.suffix));
|
|
359
|
-
if (token.pattern) {
|
|
360
|
-
if (keys)
|
|
361
|
-
keys.push(token);
|
|
362
|
-
if (prefix || suffix) {
|
|
363
|
-
if (token.modifier === "+" || token.modifier === "*") {
|
|
364
|
-
var mod = token.modifier === "*" ? "?" : "";
|
|
365
|
-
route += "(?:".concat(prefix, "((?:").concat(token.pattern, ")(?:").concat(suffix).concat(prefix, "(?:").concat(token.pattern, "))*)").concat(suffix, ")").concat(mod);
|
|
366
|
-
} else {
|
|
367
|
-
route += "(?:".concat(prefix, "(").concat(token.pattern, ")").concat(suffix, ")").concat(token.modifier);
|
|
368
|
-
}
|
|
369
|
-
} else {
|
|
370
|
-
if (token.modifier === "+" || token.modifier === "*") {
|
|
371
|
-
throw new TypeError('Can not repeat "'.concat(token.name, '" without a prefix and suffix'));
|
|
372
|
-
}
|
|
373
|
-
route += "(".concat(token.pattern, ")").concat(token.modifier);
|
|
374
|
-
}
|
|
375
|
-
} else {
|
|
376
|
-
route += "(?:".concat(prefix).concat(suffix, ")").concat(token.modifier);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (end) {
|
|
381
|
-
if (!strict)
|
|
382
|
-
route += "".concat(delimiterRe, "?");
|
|
383
|
-
route += !options.endsWith ? "$" : "(?=".concat(endsWithRe, ")");
|
|
384
|
-
} else {
|
|
385
|
-
var endToken = tokens[tokens.length - 1];
|
|
386
|
-
var isEndDelimited = typeof endToken === "string" ? delimiterRe.indexOf(endToken[endToken.length - 1]) > -1 : endToken === void 0;
|
|
387
|
-
if (!strict) {
|
|
388
|
-
route += "(?:".concat(delimiterRe, "(?=").concat(endsWithRe, "))?");
|
|
389
|
-
}
|
|
390
|
-
if (!isEndDelimited) {
|
|
391
|
-
route += "(?=".concat(delimiterRe, "|").concat(endsWithRe, ")");
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return new RegExp(route, flags(options));
|
|
395
|
-
}
|
|
396
|
-
exports.tokensToRegexp = tokensToRegexp;
|
|
397
|
-
function pathToRegexp2(path, keys, options) {
|
|
398
|
-
if (path instanceof RegExp)
|
|
399
|
-
return regexpToRegexp(path, keys);
|
|
400
|
-
if (Array.isArray(path))
|
|
401
|
-
return arrayToRegexp(path, keys, options);
|
|
402
|
-
return stringToRegexp(path, keys, options);
|
|
403
|
-
}
|
|
404
|
-
exports.pathToRegexp = pathToRegexp2;
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
// src/build/functions/edge.ts
|
|
409
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
410
|
-
var import_path_to_regexp = __toESM(require_dist(), 1);
|
|
411
|
-
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
412
|
-
import { dirname, join } from "node:path";
|
|
413
|
-
var writeEdgeManifest = async (ctx, manifest) => {
|
|
414
|
-
await mkdir(ctx.edgeFunctionsDir, { recursive: true });
|
|
415
|
-
await writeFile(join(ctx.edgeFunctionsDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
416
|
-
};
|
|
417
|
-
var copyRuntime = async (ctx, handlerDirectory) => {
|
|
418
|
-
const files = await (0, import_fast_glob.glob)("edge-runtime/**/*", {
|
|
419
|
-
cwd: ctx.pluginDir,
|
|
420
|
-
ignore: ["**/*.test.ts"],
|
|
421
|
-
dot: true
|
|
422
|
-
});
|
|
423
|
-
await Promise.all(
|
|
424
|
-
files.map(
|
|
425
|
-
(path) => cp(join(ctx.pluginDir, path), join(handlerDirectory, path), { recursive: true })
|
|
426
|
-
)
|
|
427
|
-
);
|
|
428
|
-
};
|
|
429
|
-
var augmentMatchers = (matchers, ctx) => {
|
|
430
|
-
const i18NConfig = ctx.buildConfig.i18n;
|
|
431
|
-
if (!i18NConfig) {
|
|
432
|
-
return matchers;
|
|
433
|
-
}
|
|
434
|
-
return matchers.flatMap((matcher) => {
|
|
435
|
-
if (matcher.originalSource && matcher.locale !== false) {
|
|
436
|
-
return [
|
|
437
|
-
matcher.regexp ? {
|
|
438
|
-
...matcher,
|
|
439
|
-
// https://github.com/vercel/next.js/blob/5e236c9909a768dc93856fdfad53d4f4adc2db99/packages/next/src/build/analysis/get-page-static-info.ts#L332-L336
|
|
440
|
-
// Next is producing pretty broad matcher for i18n locale. Presumably rest of their infrastructure protects this broad matcher
|
|
441
|
-
// from matching on non-locale paths. For us this becomes request entry point, so we need to narrow it down to just defined locales
|
|
442
|
-
// otherwise users might get unexpected matches on paths like `/api*`
|
|
443
|
-
regexp: matcher.regexp.replace(/\[\^\/\.]+/g, `(${i18NConfig.locales.join("|")})`)
|
|
444
|
-
} : matcher,
|
|
445
|
-
{
|
|
446
|
-
...matcher,
|
|
447
|
-
regexp: (0, import_path_to_regexp.pathToRegexp)(matcher.originalSource).source
|
|
448
|
-
}
|
|
449
|
-
];
|
|
450
|
-
}
|
|
451
|
-
return matcher;
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
var writeHandlerFile = async (ctx, { matchers, name }) => {
|
|
455
|
-
const nextConfig = ctx.buildConfig;
|
|
456
|
-
const handlerName = getHandlerName({ name });
|
|
457
|
-
const handlerDirectory = join(ctx.edgeFunctionsDir, handlerName);
|
|
458
|
-
const handlerRuntimeDirectory = join(handlerDirectory, "edge-runtime");
|
|
459
|
-
await copyRuntime(ctx, handlerDirectory);
|
|
460
|
-
await writeFile(join(handlerRuntimeDirectory, "matchers.json"), JSON.stringify(matchers));
|
|
461
|
-
const minimalNextConfig = {
|
|
462
|
-
basePath: nextConfig.basePath,
|
|
463
|
-
i18n: nextConfig.i18n,
|
|
464
|
-
trailingSlash: nextConfig.trailingSlash,
|
|
465
|
-
skipMiddlewareUrlNormalize: nextConfig.skipMiddlewareUrlNormalize
|
|
466
|
-
};
|
|
467
|
-
await writeFile(
|
|
468
|
-
join(handlerRuntimeDirectory, "next.config.json"),
|
|
469
|
-
JSON.stringify(minimalNextConfig)
|
|
470
|
-
);
|
|
471
|
-
const htmlRewriterWasm = await readFile(
|
|
472
|
-
join(
|
|
473
|
-
ctx.pluginDir,
|
|
474
|
-
"edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/pkg/htmlrewriter_bg.wasm"
|
|
475
|
-
)
|
|
476
|
-
);
|
|
477
|
-
await writeFile(
|
|
478
|
-
join(handlerDirectory, `${handlerName}.js`),
|
|
479
|
-
`
|
|
480
|
-
import { init as htmlRewriterInit } from './edge-runtime/vendor/deno.land/x/htmlrewriter@v1.0.0/src/index.ts'
|
|
481
|
-
import { handleMiddleware } from './edge-runtime/middleware.ts';
|
|
482
|
-
import handler from './server/${name}.js';
|
|
483
|
-
|
|
484
|
-
await htmlRewriterInit({ module_or_path: Uint8Array.from(${JSON.stringify([
|
|
485
|
-
...htmlRewriterWasm
|
|
486
|
-
])}) });
|
|
487
|
-
|
|
488
|
-
export default (req, context) => handleMiddleware(req, context, handler);
|
|
489
|
-
`
|
|
490
|
-
);
|
|
491
|
-
};
|
|
492
|
-
var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
|
|
493
|
-
const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
|
|
494
|
-
const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
|
|
495
|
-
const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
|
|
496
|
-
const shimPath = join(edgeRuntimeDir, "shim/index.js");
|
|
497
|
-
const shim = await readFile(shimPath, "utf8");
|
|
498
|
-
const parts = [shim];
|
|
499
|
-
const outputFile = join(destDir, `server/${name}.js`);
|
|
500
|
-
if (wasm?.length) {
|
|
501
|
-
for (const wasmChunk of wasm ?? []) {
|
|
502
|
-
const data = await readFile(join(srcDir, wasmChunk.filePath));
|
|
503
|
-
parts.push(`const ${wasmChunk.name} = Uint8Array.from(${JSON.stringify([...data])})`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
for (const file of files) {
|
|
507
|
-
const entrypoint = await readFile(join(srcDir, file), "utf8");
|
|
508
|
-
parts.push(`;// Concatenated file: ${file}
|
|
509
|
-
`, entrypoint);
|
|
510
|
-
}
|
|
511
|
-
const exports = `const middlewareEntryKey = Object.keys(_ENTRIES).find(entryKey => entryKey.startsWith("middleware_${name}")); export default _ENTRIES[middlewareEntryKey].default;`;
|
|
512
|
-
await mkdir(dirname(outputFile), { recursive: true });
|
|
513
|
-
await writeFile(outputFile, [...parts, exports].join("\n"));
|
|
514
|
-
};
|
|
515
|
-
var createEdgeHandler = async (ctx, definition) => {
|
|
516
|
-
await copyHandlerDependencies(ctx, definition);
|
|
517
|
-
await writeHandlerFile(ctx, definition);
|
|
518
|
-
};
|
|
519
|
-
var getHandlerName = ({ name }) => `${EDGE_HANDLER_NAME}-${name.replace(/\W/g, "-")}`;
|
|
520
|
-
var buildHandlerDefinition = (ctx, { name, matchers, page }) => {
|
|
521
|
-
const fun = getHandlerName({ name });
|
|
522
|
-
const funName = name.endsWith("middleware") ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
|
|
523
|
-
const cache = name.endsWith("middleware") ? void 0 : "manual";
|
|
524
|
-
const generator = `${ctx.pluginName}@${ctx.pluginVersion}`;
|
|
525
|
-
return augmentMatchers(matchers, ctx).map((matcher) => ({
|
|
526
|
-
function: fun,
|
|
527
|
-
name: funName,
|
|
528
|
-
pattern: matcher.regexp,
|
|
529
|
-
cache,
|
|
530
|
-
generator
|
|
531
|
-
}));
|
|
532
|
-
};
|
|
533
|
-
var clearStaleEdgeHandlers = async (ctx) => {
|
|
534
|
-
await rm(ctx.edgeFunctionsDir, { recursive: true, force: true });
|
|
535
|
-
};
|
|
536
|
-
var createEdgeHandlers = async (ctx) => {
|
|
537
|
-
const nextManifest = await ctx.getMiddlewareManifest();
|
|
538
|
-
const nextDefinitions = [
|
|
539
|
-
...Object.values(nextManifest.middleware)
|
|
540
|
-
// ...Object.values(nextManifest.functions)
|
|
541
|
-
];
|
|
542
|
-
await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)));
|
|
543
|
-
const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def));
|
|
544
|
-
const netlifyManifest = {
|
|
545
|
-
version: 1,
|
|
546
|
-
functions: netlifyDefinitions
|
|
547
|
-
};
|
|
548
|
-
await writeEdgeManifest(ctx, netlifyManifest);
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
export {
|
|
552
|
-
clearStaleEdgeHandlers,
|
|
553
|
-
createEdgeHandlers
|
|
554
|
-
};
|