Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions packages/fresh/src/fs_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ export function sortRoutePaths(a: string, b: string) {
const scoreB = getRoutePathScore(charB, b, bIdx);
if (scoreA === scoreB) {
if (charA !== charB) {
// TODO: Do we need localeSort here or is this good enough?
return charA < charB ? 0 : 1;
return charA < charB ? -1 : 1;
}
continue;
}
Expand All @@ -256,8 +255,7 @@ export function sortRoutePaths(a: string, b: string) {
}

if (charA !== charB) {
// TODO: Do we need localeSort here or is this good enough?
return charA < charB ? 0 : 1;
return charA < charB ? -1 : 1;
}

// If we're at the end of A or B, then we assume that the longer
Expand Down Expand Up @@ -292,8 +290,9 @@ function getRoutePathScore(char: string, s: string, i: number): number {
}

if (
i + 4 === s.length - 1 && char === "i" && s[i + 1] === "n" &&
s[i + 2] === "d" && s[i + 3] === "e" && s[i + 4] === "x"
char === "i" && s[i + 1] === "n" &&
s[i + 2] === "d" && s[i + 3] === "e" && s[i + 4] === "x" &&
(i + 4 === s.length - 1 || s[i + 5] === ".")
) {
return 3;
}
Expand Down
49 changes: 48 additions & 1 deletion packages/fresh/src/fs_routes_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,8 @@ Deno.test("fsRoutes - sortRoutePaths with groups", () => {

routes = [
"/_app",
"/app",
"/app/_middleware",
"/(authed)/_middleware",
"/(authed)/_layout",
"/_error",
Expand All @@ -1325,26 +1327,71 @@ Deno.test("fsRoutes - sortRoutePaths with groups", () => {
"/(authed)/(account)/account",
"/(authed)/api/slug",
"/hooks/github",
"/(authed)/[org]/__foo",
"/(authed)/[org]/_middleware",
"/(authed)/[org]/index",
];
routes.sort(() => Math.random() > 0.5 ? -1 : 1);
routes.sort(sortRoutePaths);
sorted = [
"/_app",
"/_error",
"/login",
"/app/_middleware",
"/app",
"/auth/login",
"/auth/logout",
"/hooks/github",
"/login",
"/(authed)/_middleware",
"/(authed)/_layout",
"/(authed)/index",
"/(authed)/api/slug",
"/(authed)/(account)/account",
"/(authed)/[org]/_middleware",
"/(authed)/[org]/__foo",
"/(authed)/[org]/index",
];
expect(routes).toEqual(sorted);

routes = [
"/_app.js",
"/app.tsx",
"/app/_middleware.tsx",
"/(authed)/_middleware.tsx",
"/(authed)/_layout.jsx",
"/_error.tsx",
"/(authed)/index.js",
"/login.js",
"/auth/logout.tsx",
"/auth/login.ts",
"/(authed)/(account)/account.tsx",
"/(authed)/api/slug.js",
"/hooks/github.js",
"/(authed)/[org]/__foo.js",
"/(authed)/[org]/_middleware.tsx",
"/(authed)/[org]/index.ts",
];
routes.sort(() => Math.random() > 0.5 ? -1 : 1);
routes.sort(sortRoutePaths);
sorted = [
"/_app.js",
"/_error.tsx",
"/app/_middleware.tsx",
"/app.tsx",
"/auth/login.ts",
"/auth/logout.tsx",
"/hooks/github.js",
"/login.js",
"/(authed)/_middleware.tsx",
"/(authed)/_layout.jsx",
"/(authed)/index.js",
"/(authed)/api/slug.js",
"/(authed)/(account)/account.tsx",
"/(authed)/[org]/_middleware.tsx",
"/(authed)/[org]/__foo.js",
"/(authed)/[org]/index.ts",
];
expect(routes).toEqual(sorted);
});

Deno.test("fsRoutes - registers default GET route for component without GET handler", async () => {
Expand Down