Skip to content

Commit 5b47013

Browse files
fix rest sorting for endpoints and pages (#3168)
* fix rest sorting for endpoints and pages * changeset Co-authored-by: Rich Harris <[email protected]>
1 parent 5cf9486 commit 5b47013

File tree

7 files changed

+22
-0
lines changed

7 files changed

+22
-0
lines changed

.changeset/strange-kiwis-tell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Sort rest endpoints before pages

packages/kit/src/core/create_manifest_data/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ function comparator(a, b) {
303303
if (!b_sub_part) return -1;
304304

305305
if (a_sub_part.rest && b_sub_part.rest) {
306+
if (a.is_page !== b.is_page) {
307+
return a.is_page ? 1 : -1;
308+
}
306309
// sort alphabetically
307310
return a_sub_part.content < b_sub_part.content ? -1 : 1;
308311
}

packages/kit/src/core/create_manifest_data/index.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,20 @@ test('sorts routes correctly', () => {
200200
);
201201
});
202202

203+
test('sorts routes with rest correctly', () => {
204+
const { routes } = create('samples/rest');
205+
206+
assert.equal(
207+
routes.map((p) => (p.type === 'page' ? p.a : p.file)),
208+
[
209+
'samples/rest/a/[...rest].js',
210+
[layout, 'samples/rest/a/[...rest].svelte'],
211+
'samples/rest/b/[...rest].ts',
212+
[layout, 'samples/rest/b/[...rest].svelte']
213+
]
214+
);
215+
});
216+
203217
test('disallows rest parameters inside segments', () => {
204218
assert.throws(
205219
() => {

packages/kit/src/core/create_manifest_data/test/samples/rest/a/[...rest].js

Whitespace-only changes.

packages/kit/src/core/create_manifest_data/test/samples/rest/a/[...rest].svelte

Whitespace-only changes.

packages/kit/src/core/create_manifest_data/test/samples/rest/b/[...rest].svelte

Whitespace-only changes.

packages/kit/src/core/create_manifest_data/test/samples/rest/b/[...rest].ts

Whitespace-only changes.

0 commit comments

Comments
 (0)