Skip to content

Commit 6302e9f

Browse files
authored
Merge branch 'main' into main
2 parents e3888a3 + adf8b87 commit 6302e9f

File tree

9 files changed

+212
-337
lines changed

9 files changed

+212
-337
lines changed

deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"./www"
88
],
99
"name": "@fresh/core",
10-
"version": "2.0.0-alpha.27",
10+
"version": "2.0.0-alpha.29",
1111
"license": "MIT",
1212
"exports": {
1313
".": "./src/mod.ts",

deno.lock

+103-300
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Examples for Fresh
22

3-
This is an package contains examples for using Fresh with
4-
[JSR](https://jsr.io/).
3+
This package contains examples for using Fresh with [JSR](https://jsr.io/).
54

65
Learn more about the Fresh framework here:
76
[https://fresh.deno.dev/](https://fresh.deno.dev/)

init/deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fresh/init",
3-
"version": "2.0.0-alpha.27",
3+
"version": "2.0.0-alpha.29",
44
"license": "MIT",
55
"exports": {
66
".": "./src/mod.ts"

init/src/init.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import * as colors from "@std/fmt/colors";
22
import * as path from "@std/path";
33

44
// Keep these as is, as we replace these version in our release script
5-
const FRESH_VERSION = "2.0.0-alpha.27";
5+
const FRESH_VERSION = "2.0.0-alpha.29";
66
const FRESH_TAILWIND_VERSION = "0.0.1-alpha.7";
7-
const PREACT_VERSION = "10.25.2";
8-
const PREACT_SIGNALS_VERSION = "1.3.1";
7+
const PREACT_VERSION = "10.25.4";
8+
const PREACT_SIGNALS_VERSION = "2.0.1";
99

1010
export const enum InitStep {
1111
ProjectName = "ProjectName",

src/plugins/fs_routes/mod.ts

+10-26
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ export async function fsRoutes<State>(
299299
isHandlerByMethod(handlers) &&
300300
!Object.keys(handlers).includes("GET");
301301
if (missingGetHandler) {
302-
app.get(routePath, renderMiddleware(components, undefined));
302+
const combined = middlewares.concat(
303+
renderMiddleware(components, undefined),
304+
);
305+
app.get(routePath, ...combined);
303306
}
304307
}
305308

@@ -400,37 +403,18 @@ export function sortRoutePaths(a: string, b: string) {
400403
let aIdx = 0;
401404
let bIdx = 0;
402405
for (; aIdx < aLen && bIdx < bLen; aIdx++, bIdx++) {
403-
let charA = a.charAt(aIdx);
404-
let charB = b.charAt(bIdx);
406+
const charA = a.charAt(aIdx);
407+
const charB = b.charAt(bIdx);
405408

406409
// When comparing a grouped route with a non-grouped one, we
407410
// need to skip over the group name to effectively compare the
408411
// actual route.
409412
if (charA === "(" && charB !== "(") {
410-
aIdx++;
411-
412-
while (aIdx < aLen) {
413-
charA = a.charAt(aIdx);
414-
if (charA === ")") {
415-
aIdx += 2;
416-
charA = a.charAt(aIdx);
417-
break;
418-
}
419-
420-
aIdx++;
421-
}
413+
if (charB == "[") return -1;
414+
return 1;
422415
} else if (charB === "(" && charA !== "(") {
423-
bIdx++;
424-
while (bIdx < bLen) {
425-
charB = b.charAt(bIdx);
426-
if (charB === ")") {
427-
bIdx += 2;
428-
charB = b.charAt(bIdx);
429-
break;
430-
}
431-
432-
bIdx++;
433-
}
416+
if (charA == "[") return 1;
417+
return -1;
434418
}
435419

436420
if (charA === "/" || charB === "/") {

src/plugins/fs_routes/mod_test.tsx

+89
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,54 @@ Deno.test("fsRoutes - sortRoutePaths", () => {
12121212
expect(routes).toEqual(sorted);
12131213
});
12141214

1215+
Deno.test("fsRoutes - sortRoutePaths with groups", () => {
1216+
let routes = [
1217+
"/(authed)/_middleware.ts",
1218+
"/(authed)/index.ts",
1219+
"/about.tsx",
1220+
];
1221+
routes.sort(sortRoutePaths);
1222+
let sorted = [
1223+
"/about.tsx",
1224+
"/(authed)/_middleware.ts",
1225+
"/(authed)/index.ts",
1226+
];
1227+
expect(routes).toEqual(sorted);
1228+
1229+
routes = [
1230+
"/_app",
1231+
"/(authed)/_middleware",
1232+
"/(authed)/_layout",
1233+
"/_error",
1234+
"/(authed)/index",
1235+
"/login",
1236+
"/auth/login",
1237+
"/auth/logout",
1238+
"/(authed)/(account)/account",
1239+
"/(authed)/api/slug",
1240+
"/hooks/github",
1241+
"/(authed)/[org]/_middleware",
1242+
"/(authed)/[org]/index",
1243+
];
1244+
routes.sort(sortRoutePaths);
1245+
sorted = [
1246+
"/_app",
1247+
"/_error",
1248+
"/login",
1249+
"/auth/login",
1250+
"/auth/logout",
1251+
"/hooks/github",
1252+
"/(authed)/_middleware",
1253+
"/(authed)/_layout",
1254+
"/(authed)/index",
1255+
"/(authed)/api/slug",
1256+
"/(authed)/(account)/account",
1257+
"/(authed)/[org]/_middleware",
1258+
"/(authed)/[org]/index",
1259+
];
1260+
expect(routes).toEqual(sorted);
1261+
});
1262+
12151263
Deno.test("fsRoutes - registers default GET route for component without GET handler", async () => {
12161264
const server = await createServer<{ value: boolean }>({
12171265
"routes/noGetHandler.tsx": {
@@ -1241,6 +1289,47 @@ Deno.test("fsRoutes - registers default GET route for component without GET hand
12411289
);
12421290
});
12431291

1292+
Deno.test("fsRoutes - default GET route works with nested middleware", async () => {
1293+
const server = await createServer<{ text: string }>({
1294+
"routes/_middleware.ts": {
1295+
handler: (ctx) => {
1296+
ctx.state.text = "A";
1297+
return ctx.next();
1298+
},
1299+
},
1300+
"routes/foo/_middleware.ts": {
1301+
handler: (ctx) => {
1302+
ctx.state.text += "B";
1303+
return ctx.next();
1304+
},
1305+
},
1306+
"routes/foo/noGetHandler.tsx": {
1307+
default: (ctx) => {
1308+
return <h1>{ctx.state.text}</h1>;
1309+
},
1310+
handlers: {
1311+
POST: () => new Response("POST"),
1312+
},
1313+
},
1314+
});
1315+
1316+
const postRes = await server.post("/foo/noGetHandler");
1317+
expect(postRes.status).toEqual(200);
1318+
expect(postRes.headers.get("Content-Type")).toEqual(
1319+
"text/plain;charset=UTF-8",
1320+
);
1321+
expect(await postRes.text()).toEqual("POST");
1322+
1323+
const getRes = await server.get("/foo/noGetHandler");
1324+
expect(getRes.status).toEqual(200);
1325+
expect(getRes.headers.get("Content-Type")).toEqual(
1326+
"text/html; charset=utf-8",
1327+
);
1328+
expect(await getRes.text()).toContain(
1329+
"<h1>AB</h1>",
1330+
);
1331+
});
1332+
12441333
Deno.test("fsRoutes - default GET route doesn't override existing handler", async () => {
12451334
const server = await createServer<{ value: boolean }>({
12461335
"routes/withGetHandler.tsx": {

update/deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fresh/update",
3-
"version": "2.0.0-alpha.27",
3+
"version": "2.0.0-alpha.29",
44
"license": "MIT",
55
"exports": {
66
".": "./src/mod.ts"

update/src/update.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as tsmorph from "ts-morph";
44

55
export const SyntaxKind = tsmorph.ts.SyntaxKind;
66

7-
export const FRESH_VERSION = "2.0.0-alpha.27";
8-
export const PREACT_VERSION = "10.25.2";
9-
export const PREACT_SIGNALS_VERSION = "1.3.1";
7+
export const FRESH_VERSION = "2.0.0-alpha.29";
8+
export const PREACT_VERSION = "10.25.4";
9+
export const PREACT_SIGNALS_VERSION = "2.0.1";
1010

1111
export interface DenoJson {
1212
name?: string;

0 commit comments

Comments
 (0)