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 <mrkishi@users.noreply.github.com> * reword sym-linked to symlinked * skip symlinks tests when unsupported Co-authored-by: Maurício Kishi <mrkishi@users.noreply.github.com> Co-authored-by: mrkishi <mauriciokishi@gmail.com>
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 numberDiff 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 numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ function count_occurrences(needle, haystack) {
426426
* @param {string[]} [files]
427427
*/
428428
function list_files(dir, path = '', files = []) {
429-
fs.readdirSync(dir, { withFileTypes: true })
430-
.sort(({ name: a }, { name: b }) => {
429+
fs.readdirSync(dir)
430+
.sort((a, b) => {
431431
// sort each directory in (__layout, __error, everything else) order
432432
// so that we can trace layouts/errors immediately
433433

@@ -444,10 +444,12 @@ function list_files(dir, path = '', files = []) {
444444
return a < b ? -1 : 1;
445445
})
446446
.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;
448450

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

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

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

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+
98136
test('creates routes with layout', () => {
99137
const { components, routes } = create('samples/basic-layout');
100138

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 numberDiff 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)