@edgeone/opennextjs-pages 0.1.5-beta.4 → 0.1.6-beta.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.
|
@@ -3539,28 +3539,61 @@ function matchesPath(pathname, matcher) {
|
|
|
3539
3539
|
continue;
|
|
3540
3540
|
}
|
|
3541
3541
|
} else {
|
|
3542
|
-
// \u8DEF\u5F84\u6A21\u5F0F\uFF0C\u9700\u8981\u8F6C\u6362
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
regexPattern =
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3542
|
+
// \u8DEF\u5F84\u6A21\u5F0F\uFF0C\u9700\u8981\u8F6C\u6362\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F
|
|
3543
|
+
// Next.js middleware matcher \u4F7F\u7528\u7C7B\u4F3C path-to-regexp \u7684\u8BED\u6CD5:
|
|
3544
|
+
// /dashboard/:path* -> \u5339\u914D /dashboard \u548C /dashboard/xxx\uFF08\u96F6\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
3545
|
+
// /api/:path -> \u5339\u914D /api/xxx\uFF08\u4E00\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
3546
|
+
// /api/:path+ -> \u5339\u914D /api/xxx/yyy\uFF08\u4E00\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
3547
|
+
let regexPattern = '';
|
|
3548
|
+
let ci = 0;
|
|
3549
|
+
const p = pattern;
|
|
3550
|
+
while (ci < p.length) {
|
|
3551
|
+
if (p[ci] === ':') {
|
|
3552
|
+
// \u89E3\u6790\u53C2\u6570\u540D
|
|
3553
|
+
ci++;
|
|
3554
|
+
while (ci < p.length && /[a-zA-Z0-9_]/.test(p[ci])) {
|
|
3555
|
+
ci++;
|
|
3556
|
+
}
|
|
3557
|
+
// \u68C0\u67E5\u4FEE\u9970\u7B26
|
|
3558
|
+
if (ci < p.length && p[ci] === '*') {
|
|
3559
|
+
// :param* -> \u96F6\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF0C\u524D\u9762\u7684 / \u4E5F\u53D8\u4E3A\u53EF\u9009
|
|
3560
|
+
if (regexPattern.endsWith('\\\\/')) {
|
|
3561
|
+
regexPattern = regexPattern.slice(0, -2);
|
|
3562
|
+
}
|
|
3563
|
+
regexPattern += '(?:\\\\/.*)?';
|
|
3564
|
+
ci++;
|
|
3565
|
+
} else if (ci < p.length && p[ci] === '+') {
|
|
3566
|
+
// :param+ -> \u4E00\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5
|
|
3567
|
+
regexPattern += '.+';
|
|
3568
|
+
ci++;
|
|
3569
|
+
} else {
|
|
3570
|
+
// :param -> \u5339\u914D\u4E00\u4E2A\u8DEF\u5F84\u6BB5
|
|
3571
|
+
regexPattern += '[^/]+';
|
|
3572
|
+
}
|
|
3573
|
+
} else if (p[ci] === '/') {
|
|
3574
|
+
regexPattern += '\\\\/';
|
|
3575
|
+
ci++;
|
|
3576
|
+
} else if (p[ci] === '*') {
|
|
3577
|
+
if (ci + 1 < p.length && p[ci + 1] === '*') {
|
|
3578
|
+
regexPattern += '.*';
|
|
3579
|
+
ci += 2;
|
|
3580
|
+
} else {
|
|
3581
|
+
regexPattern += '[^/]*';
|
|
3582
|
+
ci++;
|
|
3583
|
+
}
|
|
3556
3584
|
} else {
|
|
3557
|
-
|
|
3585
|
+
// \u8F6C\u4E49\u6B63\u5219\u7279\u6B8A\u5B57\u7B26
|
|
3586
|
+
const ch = p[ci];
|
|
3587
|
+
const specialChars = '.+?^$|(){}[]\\\\';
|
|
3588
|
+
if (specialChars.indexOf(ch) !== -1) {
|
|
3589
|
+
regexPattern += '\\\\' + ch;
|
|
3590
|
+
} else {
|
|
3591
|
+
regexPattern += ch;
|
|
3592
|
+
}
|
|
3593
|
+
ci++;
|
|
3558
3594
|
}
|
|
3559
3595
|
}
|
|
3560
3596
|
|
|
3561
|
-
regexPattern = regexPattern.split('**').join('.*');
|
|
3562
|
-
regexPattern = regexPattern.split('\\\\*').join('[^/]*');
|
|
3563
|
-
|
|
3564
3597
|
regex = new RegExp('^' + regexPattern + '$');
|
|
3565
3598
|
}
|
|
3566
3599
|
|
|
@@ -258,42 +258,61 @@ function matchesPath(pathname, matcher) {
|
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
260
|
} else {
|
|
261
|
-
// \u8DEF\u5F84\u6A21\u5F0F\uFF0C\u9700\u8981\u8F6C\u6362
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
// \
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
261
|
+
// \u8DEF\u5F84\u6A21\u5F0F\uFF0C\u9700\u8981\u8F6C\u6362\u4E3A\u6B63\u5219\u8868\u8FBE\u5F0F
|
|
262
|
+
// Next.js middleware matcher \u4F7F\u7528\u7C7B\u4F3C path-to-regexp \u7684\u8BED\u6CD5:
|
|
263
|
+
// /dashboard/:path* -> \u5339\u914D /dashboard \u548C /dashboard/xxx\uFF08\u96F6\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
264
|
+
// /api/:path -> \u5339\u914D /api/xxx\uFF08\u4E00\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
265
|
+
// /api/:path+ -> \u5339\u914D /api/xxx/yyy\uFF08\u4E00\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF09
|
|
266
|
+
let regexPattern = '';
|
|
267
|
+
let ci = 0;
|
|
268
|
+
const p = pattern;
|
|
269
|
+
while (ci < p.length) {
|
|
270
|
+
if (p[ci] === ':') {
|
|
271
|
+
// \u89E3\u6790\u53C2\u6570\u540D
|
|
272
|
+
ci++;
|
|
273
|
+
while (ci < p.length && /[a-zA-Z0-9_]/.test(p[ci])) {
|
|
274
|
+
ci++;
|
|
275
|
+
}
|
|
276
|
+
// \u68C0\u67E5\u4FEE\u9970\u7B26
|
|
277
|
+
if (ci < p.length && p[ci] === '*') {
|
|
278
|
+
// :param* -> \u96F6\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5\uFF0C\u524D\u9762\u7684 / \u4E5F\u53D8\u4E3A\u53EF\u9009
|
|
279
|
+
if (regexPattern.endsWith('\\/')) {
|
|
280
|
+
regexPattern = regexPattern.slice(0, -2);
|
|
281
|
+
}
|
|
282
|
+
regexPattern += '(?:\\/.*)?';
|
|
283
|
+
ci++;
|
|
284
|
+
} else if (ci < p.length && p[ci] === '+') {
|
|
285
|
+
// :param+ -> \u4E00\u4E2A\u6216\u591A\u4E2A\u8DEF\u5F84\u6BB5
|
|
286
|
+
regexPattern += '.+';
|
|
287
|
+
ci++;
|
|
288
|
+
} else {
|
|
289
|
+
// :param -> \u5339\u914D\u4E00\u4E2A\u8DEF\u5F84\u6BB5
|
|
290
|
+
regexPattern += '[^/]+';
|
|
291
|
+
}
|
|
292
|
+
} else if (p[ci] === '/') {
|
|
293
|
+
regexPattern += '\\/';
|
|
294
|
+
ci++;
|
|
295
|
+
} else if (p[ci] === '*') {
|
|
296
|
+
if (ci + 1 < p.length && p[ci + 1] === '*') {
|
|
297
|
+
regexPattern += '.*';
|
|
298
|
+
ci += 2;
|
|
299
|
+
} else {
|
|
300
|
+
regexPattern += '[^/]*';
|
|
301
|
+
ci++;
|
|
302
|
+
}
|
|
285
303
|
} else {
|
|
286
|
-
//
|
|
287
|
-
|
|
304
|
+
// \u8F6C\u4E49\u6B63\u5219\u7279\u6B8A\u5B57\u7B26
|
|
305
|
+
const ch = p[ci];
|
|
306
|
+
const specialChars = '.+?^$|(){}[]\\\\';
|
|
307
|
+
if (specialChars.indexOf(ch) !== -1) {
|
|
308
|
+
regexPattern += '\\' + ch;
|
|
309
|
+
} else {
|
|
310
|
+
regexPattern += ch;
|
|
311
|
+
}
|
|
312
|
+
ci++;
|
|
288
313
|
}
|
|
289
314
|
}
|
|
290
315
|
|
|
291
|
-
// ** -> .*
|
|
292
|
-
regexPattern = regexPattern.split('**').join('.*');
|
|
293
|
-
// * -> [^/]* (\u4F46\u4E0D\u5F71\u54CD\u5DF2\u7ECF\u8F6C\u6362\u7684 .*)
|
|
294
|
-
// \u7B80\u5355\u5904\u7406\uFF1A\u53EA\u66FF\u6362\u72EC\u7ACB\u7684 *
|
|
295
|
-
regexPattern = regexPattern.split('\\*').join('[^/]*');
|
|
296
|
-
|
|
297
316
|
regex = new RegExp('^' + regexPattern + '$');
|
|
298
317
|
}
|
|
299
318
|
|
package/dist/build/routes.js
CHANGED
|
@@ -89,51 +89,6 @@ function getDataRoutes(dataRoutes, basePath = "") {
|
|
|
89
89
|
}
|
|
90
90
|
return routes;
|
|
91
91
|
}
|
|
92
|
-
function getServerRoutes(staticRoutes, prerenderManifest, basePath = "") {
|
|
93
|
-
const routes = [];
|
|
94
|
-
const prerenderRoutes = prerenderManifest?.routes || {};
|
|
95
|
-
for (const route of staticRoutes) {
|
|
96
|
-
if (route.page.startsWith("/_")) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
const prerenderInfo = prerenderRoutes[route.page];
|
|
100
|
-
if (prerenderInfo && prerenderInfo.initialRevalidateSeconds === false) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (route.namedRegex) {
|
|
104
|
-
let src = convertNamedRegexToSrc(route.namedRegex, basePath);
|
|
105
|
-
if (src) {
|
|
106
|
-
src = src.replace(/\(\?:\/\)\?\$$/, "$");
|
|
107
|
-
routes.push({ src });
|
|
108
|
-
}
|
|
109
|
-
} else if (route.regex) {
|
|
110
|
-
if (isRE2Compatible(route.regex)) {
|
|
111
|
-
let src = route.regex;
|
|
112
|
-
if (basePath && !src.startsWith(`^${basePath}`)) {
|
|
113
|
-
src = src.replace(/^\^/, `^${basePath}`);
|
|
114
|
-
}
|
|
115
|
-
src = src.replace(/\(\?:\/\)\?\$$/, "$");
|
|
116
|
-
routes.push({ src });
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return routes;
|
|
121
|
-
}
|
|
122
|
-
function getApiRoutes(appPathsManifest, basePath = "") {
|
|
123
|
-
if (!appPathsManifest) {
|
|
124
|
-
return [];
|
|
125
|
-
}
|
|
126
|
-
const routes = [];
|
|
127
|
-
for (const routePath of Object.keys(appPathsManifest)) {
|
|
128
|
-
if (routePath.includes("/api/") && routePath.endsWith("/route")) {
|
|
129
|
-
const apiPath = routePath.replace(/\/route$/, "");
|
|
130
|
-
const escapedPath = apiPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
131
|
-
const src = `^${basePath}${escapedPath}$`;
|
|
132
|
-
routes.push({ src });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return routes;
|
|
136
|
-
}
|
|
137
92
|
async function getMiddlewareConfig(ctx) {
|
|
138
93
|
try {
|
|
139
94
|
const manifest = await ctx.getMiddlewareManifest();
|
|
@@ -244,9 +199,6 @@ var createRouteMeta = async (ctx) => {
|
|
|
244
199
|
}
|
|
245
200
|
const dynamicRoutes = routesManifest?.dynamicRoutes || [];
|
|
246
201
|
const dataRoutes = routesManifest?.dataRoutes || [];
|
|
247
|
-
const staticRoutes = routesManifest?.staticRoutes || [];
|
|
248
|
-
const appPathsManifest = await ctx.getAppPathsManifest?.() || null;
|
|
249
|
-
const prerenderManifest = await ctx.getPrerenderManifest?.() || null;
|
|
250
202
|
const buildId = getBuildId(ctx);
|
|
251
203
|
const staticCacheRegex = buildId ? `^${basePath}/_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media|${buildId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})/.+` : `^${basePath}/_next/static/(?:[^/]+/pages|pages|chunks|runtime|css|image|media)/.+`;
|
|
252
204
|
routes.push({
|
|
@@ -333,19 +285,12 @@ var createRouteMeta = async (ctx) => {
|
|
|
333
285
|
console.warn("[opennext] Warning: Failed to convert fallback rewrites:", e);
|
|
334
286
|
}
|
|
335
287
|
}
|
|
336
|
-
if (staticRoutes.length > 0) {
|
|
337
|
-
routes.push(...getServerRoutes(staticRoutes, prerenderManifest, basePath));
|
|
338
|
-
}
|
|
339
288
|
if (dynamicRoutes.length > 0) {
|
|
340
289
|
routes.push(...getDynamicRoutes(dynamicRoutes, basePath));
|
|
341
290
|
}
|
|
342
291
|
if (dataRoutes.length > 0) {
|
|
343
292
|
routes.push(...getDataRoutes(dataRoutes, basePath));
|
|
344
293
|
}
|
|
345
|
-
const apiRoutes = getApiRoutes(appPathsManifest, basePath);
|
|
346
|
-
if (apiRoutes.length > 0) {
|
|
347
|
-
routes.push(...apiRoutes);
|
|
348
|
-
}
|
|
349
294
|
routes.push({
|
|
350
295
|
src: `^${basePath}/.*$`
|
|
351
296
|
});
|
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(tags_handler_exports);
|
|
|
28
28
|
|
|
29
29
|
// package.json
|
|
30
30
|
var name = "@edgeone/opennextjs-pages";
|
|
31
|
-
var version = "0.1.
|
|
31
|
+
var version = "0.1.6-beta.1";
|
|
32
32
|
|
|
33
33
|
// src/run/handlers/tags-handler.cts
|
|
34
34
|
var import_request_context = require("./request-context.cjs");
|