Skip to content

Commit eb2ab91

Browse files
mikeniklesmrkishi
andauthored
[fix] Process symlinked routes (#4957)
* [fix] Process sym-linked routes * Revert to fs.statSync * Update packages/kit/src/core/sync/create_manifest_data/index.js Co-authored-by: Maurício Kishi <[email protected]> * reword sym-linked to symlinked * skip symlinks tests when unsupported Co-authored-by: Maurício Kishi <[email protected]> Co-authored-by: mrkishi <[email protected]>
1 parent e1cff24 commit eb2ab91

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

.changeset/few-cobras-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Allow symlinked directories in the routes folder

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

Lines changed: 7 additions & 5 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -426,8 +426,8 @@ function count_occurrences(needle, haystack) {
426
* @param {string[]} [files]
426
* @param {string[]} [files]
427
*/
427
*/
428
function list_files(dir, path = '', files = []) {
428
function list_files(dir, path = '', files = []) {
429-
fs.readdirSync(dir, { withFileTypes: true })
429+
fs.readdirSync(dir)
430-
.sort(({ name: a }, { name: b }) => {
430+
.sort((a, b) => {
431
// sort each directory in (__layout, __error, everything else) order
431
// sort each directory in (__layout, __error, everything else) order
432
// so that we can trace layouts/errors immediately
432
// so that we can trace layouts/errors immediately
433

433

@@ -444,10 +444,12 @@ function list_files(dir, path = '', files = []) {
444
return a < b ? -1 : 1;
444
return a < b ? -1 : 1;
445
})
445
})
446
.forEach((file) => {
446
.forEach((file) => {
447-
const joined = path ? `${path}/${file.name}` : file.name;
447+
const full = `${dir}/${file}`;
448+
const stats = fs.statSync(full);
449+
const joined = path ? `${path}/${file}` : file;
448

450

449-
if (file.isDirectory()) {
451+
if (stats.isDirectory()) {
450-
list_files(`${dir}/${file.name}`, joined, files);
452+
list_files(full, joined, files);
451
} else {
453
} else {
452
files.push(joined);
454
files.push(joined);
453
}
455
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs';
1
import path from 'path';
2
import path from 'path';
2
import { fileURLToPath } from 'url';
3
import { fileURLToPath } from 'url';
3
import { test } from 'uvu';
4
import { test } from 'uvu';
@@ -95,6 +96,43 @@ test('creates routes', () => {
95
]);
96
]);
96
});
97
});
97

98

99+
const symlink_survived_git = fs
100+
.statSync(path.join(cwd, 'samples/symlinks/routes/foo'))
101+
.isSymbolicLink();
102+
103+
const test_symlinks = symlink_survived_git ? test : test.skip;
104+
105+
test_symlinks('creates symlinked routes', () => {
106+
const { components, routes } = create('samples/symlinks/routes');
107+
108+
const index = 'samples/symlinks/routes/index.svelte';
109+
const symlinked_index = 'samples/symlinks/routes/foo/index.svelte';
110+
111+
assert.equal(components, [default_layout, default_error, symlinked_index, index]);
112+
113+
assert.equal(routes, [
114+
{
115+
type: 'page',
116+
id: '',
117+
pattern: /^\/$/,
118+
path: '/',
119+
shadow: null,
120+
a: [default_layout, index],
121+
b: [default_error]
122+
},
123+
124+
{
125+
type: 'page',
126+
id: 'foo',
127+
pattern: /^\/foo\/?$/,
128+
path: '/foo',
129+
shadow: null,
130+
a: [default_layout, symlinked_index],
131+
b: [default_error]
132+
}
133+
]);
134+
});
135+
98
test('creates routes with layout', () => {
136
test('creates routes with layout', () => {
99
const { components, routes } = create('samples/basic-layout');
137
const { components, routes } = create('samples/basic-layout');
100

138

packages/kit/src/core/sync/create_manifest_data/test/samples/symlinks/bar/index.svelte

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberOriginal file lineDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../bar

packages/kit/src/core/sync/create_manifest_data/test/samples/symlinks/routes/index.svelte

Whitespace-only changes.

0 commit comments

Comments
 (0)