Skip to content

Commit ef59ca9

Browse files
authored
Merge branch 'main' into rename-FreshContext-req-to-request
2 parents 5ffccb7 + b1f2a98 commit ef59ca9

File tree

25 files changed

+532
-383
lines changed

25 files changed

+532
-383
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 103 additions & 300 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/README.md

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ export async function fsRoutes<State>(
296296
isHandlerByMethod(handlers) &&
297297
!Object.keys(handlers).includes("GET");
298298
if (missingGetHandler) {
299-
app.get(routePath, renderMiddleware(components, undefined));
299+
const combined = middlewares.concat(
300+
renderMiddleware(components, undefined),
301+
);
302+
app.get(routePath, ...combined);
300303
}
301304
}
302305

@@ -397,37 +400,18 @@ export function sortRoutePaths(a: string, b: string) {
397400
let aIdx = 0;
398401
let bIdx = 0;
399402
for (; aIdx < aLen && bIdx < bLen; aIdx++, bIdx++) {
400-
let charA = a.charAt(aIdx);
401-
let charB = b.charAt(bIdx);
403+
const charA = a.charAt(aIdx);
404+
const charB = b.charAt(bIdx);
402405

403406
// When comparing a grouped route with a non-grouped one, we
404407
// need to skip over the group name to effectively compare the
405408
// actual route.
406409
if (charA === "(" && charB !== "(") {
407-
aIdx++;
408-
409-
while (aIdx < aLen) {
410-
charA = a.charAt(aIdx);
411-
if (charA === ")") {
412-
aIdx += 2;
413-
charA = a.charAt(aIdx);
414-
break;
415-
}
416-
417-
aIdx++;
418-
}
410+
if (charB == "[") return -1;
411+
return 1;
419412
} else if (charB === "(" && charA !== "(") {
420-
bIdx++;
421-
while (bIdx < bLen) {
422-
charB = b.charAt(bIdx);
423-
if (charB === ")") {
424-
bIdx += 2;
425-
charB = b.charAt(bIdx);
426-
break;
427-
}
428-
429-
bIdx++;
430-
}
413+
if (charA == "[") return 1;
414+
return -1;
431415
}
432416

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

src/plugins/fs_routes/mod_test.tsx

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,54 @@ Deno.test("fsRoutes - sortRoutePaths", () => {
11641164
expect(routes).toEqual(sorted);
11651165
});
11661166

1167+
Deno.test("fsRoutes - sortRoutePaths with groups", () => {
1168+
let routes = [
1169+
"/(authed)/_middleware.ts",
1170+
"/(authed)/index.ts",
1171+
"/about.tsx",
1172+
];
1173+
routes.sort(sortRoutePaths);
1174+
let sorted = [
1175+
"/about.tsx",
1176+
"/(authed)/_middleware.ts",
1177+
"/(authed)/index.ts",
1178+
];
1179+
expect(routes).toEqual(sorted);
1180+
1181+
routes = [
1182+
"/_app",
1183+
"/(authed)/_middleware",
1184+
"/(authed)/_layout",
1185+
"/_error",
1186+
"/(authed)/index",
1187+
"/login",
1188+
"/auth/login",
1189+
"/auth/logout",
1190+
"/(authed)/(account)/account",
1191+
"/(authed)/api/slug",
1192+
"/hooks/github",
1193+
"/(authed)/[org]/_middleware",
1194+
"/(authed)/[org]/index",
1195+
];
1196+
routes.sort(sortRoutePaths);
1197+
sorted = [
1198+
"/_app",
1199+
"/_error",
1200+
"/login",
1201+
"/auth/login",
1202+
"/auth/logout",
1203+
"/hooks/github",
1204+
"/(authed)/_middleware",
1205+
"/(authed)/_layout",
1206+
"/(authed)/index",
1207+
"/(authed)/api/slug",
1208+
"/(authed)/(account)/account",
1209+
"/(authed)/[org]/_middleware",
1210+
"/(authed)/[org]/index",
1211+
];
1212+
expect(routes).toEqual(sorted);
1213+
});
1214+
11671215
Deno.test("fsRoutes - registers default GET route for component without GET handler", async () => {
11681216
const server = await createServer<{ value: boolean }>({
11691217
"routes/noGetHandler.tsx": {
@@ -1193,6 +1241,47 @@ Deno.test("fsRoutes - registers default GET route for component without GET hand
11931241
);
11941242
});
11951243

1244+
Deno.test("fsRoutes - default GET route works with nested middleware", async () => {
1245+
const server = await createServer<{ text: string }>({
1246+
"routes/_middleware.ts": {
1247+
handler: (ctx) => {
1248+
ctx.state.text = "A";
1249+
return ctx.next();
1250+
},
1251+
},
1252+
"routes/foo/_middleware.ts": {
1253+
handler: (ctx) => {
1254+
ctx.state.text += "B";
1255+
return ctx.next();
1256+
},
1257+
},
1258+
"routes/foo/noGetHandler.tsx": {
1259+
default: (ctx) => {
1260+
return <h1>{ctx.state.text}</h1>;
1261+
},
1262+
handlers: {
1263+
POST: () => new Response("POST"),
1264+
},
1265+
},
1266+
});
1267+
1268+
const postRes = await server.post("/foo/noGetHandler");
1269+
expect(postRes.status).toEqual(200);
1270+
expect(postRes.headers.get("Content-Type")).toEqual(
1271+
"text/plain;charset=UTF-8",
1272+
);
1273+
expect(await postRes.text()).toEqual("POST");
1274+
1275+
const getRes = await server.get("/foo/noGetHandler");
1276+
expect(getRes.status).toEqual(200);
1277+
expect(getRes.headers.get("Content-Type")).toEqual(
1278+
"text/html; charset=utf-8",
1279+
);
1280+
expect(await getRes.text()).toContain(
1281+
"<h1>AB</h1>",
1282+
);
1283+
});
1284+
11961285
Deno.test("fsRoutes - default GET route doesn't override existing handler", async () => {
11971286
const server = await createServer<{ value: boolean }>({
11981287
"routes/withGetHandler.tsx": {

update/deno.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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;

www/components/DocsSidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function SidebarCategory(props: {
1212
<li class="my-2 block">
1313
<a
1414
href={href}
15-
class="text-gray-900 hover:text-gray-600 aria-[current]:text-green-700 aria-[current]:hover:underline font-bold"
15+
class="text-foreground-secondary hover:text-gray-600 aria-[current]:text-fresh-green aria-[current]:hover:underline font-bold"
1616
>
1717
{title}
1818
</a>
@@ -36,7 +36,7 @@ export function SidebarEntry(props: {
3636
<li class="py-[1px]">
3737
<a
3838
href={href}
39-
class="aria-[current]:text-green-700 aria-[current]:border-green-600 aria-[current]:bg-green-50 border-l-4 border-transparent px-4 py-0.5 transition-colors hover:text-green-500 font-normal block"
39+
class="aria-[current]:text-fresh-green aria-[current]:border-green-600 aria-[current]:bg-fresh-green/5 border-l-4 border-transparent px-4 py-0.5 transition-colors hover:text-fresh-green/80 font-normal block"
4040
>
4141
{title}
4242
</a>

0 commit comments

Comments
 (0)