fix: in sortRoutePaths: sort files alphabetically (#3769)
Closes #3773 --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Bartek Iwańczuk
Claude Opus 4.6
parent
36dd6375eb
commit
ecc42850b9
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1315,6 +1315,8 @@ Deno.test("fsRoutes - sortRoutePaths with groups", () => {
|
||||
|
||||
routes = [
|
||||
"/_app",
|
||||
"/app",
|
||||
"/app/_middleware",
|
||||
"/(authed)/_middleware",
|
||||
"/(authed)/_layout",
|
||||
"/_error",
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user