Skip to content

Commit 8809231

Browse files
committed
fix in sortRoutePaths: sort files alphabetically
1 parent 25e6357 commit 8809231

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

packages/fresh/src/fs_routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ export function sortRoutePaths(a: string, b: string) {
247247
if (scoreA === scoreB) {
248248
if (charA !== charB) {
249249
// TODO: Do we need localeSort here or is this good enough?
250-
return charA < charB ? 0 : 1;
250+
return charA < charB ? -1 : 1;
251251
}
252252
continue;
253253
}
@@ -257,7 +257,7 @@ export function sortRoutePaths(a: string, b: string) {
257257

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

263263
// If we're at the end of A or B, then we assume that the longer

packages/fresh/src/fs_routes_test.tsx

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,35 +1314,40 @@ Deno.test("fsRoutes - sortRoutePaths with groups", () => {
13141314
expect(routes).toEqual(sorted);
13151315

13161316
routes = [
1317-
"/_app",
1318-
"/(authed)/_middleware",
1319-
"/(authed)/_layout",
1320-
"/_error",
1321-
"/(authed)/index",
1322-
"/login",
1323-
"/auth/login",
1324-
"/auth/logout",
1325-
"/(authed)/(account)/account",
1326-
"/(authed)/api/slug",
1327-
"/hooks/github",
1328-
"/(authed)/[org]/_middleware",
1329-
"/(authed)/[org]/index",
1317+
"/_app.tsx",
1318+
"/app.tsx",
1319+
"/app/_middleware.tsx",
1320+
"/(authed)/_middleware.tsx",
1321+
"/(authed)/_layout.tsx",
1322+
"/_error.tsx",
1323+
"/(authed)/index.tsx",
1324+
"/login.tsx",
1325+
"/auth/login.tsx",
1326+
"/auth/logout.tsx",
1327+
"/(authed)/(account)/account.tsx",
1328+
"/(authed)/api/slug.tsx",
1329+
"/hooks/github.tsx",
1330+
"/(authed)/[org]/_middleware.tsx",
1331+
"/(authed)/[org]/index.tsx",
13301332
];
1333+
// routes.sort(() => Math.random() > 0.5 ? -1 : 1);
13311334
routes.sort(sortRoutePaths);
13321335
sorted = [
1333-
"/_app",
1334-
"/_error",
1335-
"/login",
1336-
"/auth/login",
1337-
"/auth/logout",
1338-
"/hooks/github",
1339-
"/(authed)/_middleware",
1340-
"/(authed)/_layout",
1341-
"/(authed)/index",
1342-
"/(authed)/api/slug",
1343-
"/(authed)/(account)/account",
1344-
"/(authed)/[org]/_middleware",
1345-
"/(authed)/[org]/index",
1336+
"/_app.tsx",
1337+
"/_error.tsx",
1338+
"/app/_middleware.tsx",
1339+
"/app.tsx",
1340+
"/auth/login.tsx",
1341+
"/auth/logout.tsx",
1342+
"/hooks/github.tsx",
1343+
"/login.tsx",
1344+
"/(authed)/_middleware.tsx",
1345+
"/(authed)/_layout.tsx",
1346+
"/(authed)/index.tsx",
1347+
"/(authed)/api/slug.tsx",
1348+
"/(authed)/(account)/account.tsx",
1349+
"/(authed)/[org]/_middleware.tsx",
1350+
"/(authed)/[org]/index.tsx",
13461351
];
13471352
expect(routes).toEqual(sorted);
13481353
});

0 commit comments

Comments
 (0)