Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-cobras-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Allow symlinked directories in the routes folder
12 changes: 7 additions & 5 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ function count_occurrences(needle, haystack) {
* @param {string[]} [files]
*/
function list_files(dir, path = '', files = []) {
fs.readdirSync(dir, { withFileTypes: true })
.sort(({ name: a }, { name: b }) => {
fs.readdirSync(dir)
.sort((a, b) => {
// sort each directory in (__layout, __error, everything else) order
// so that we can trace layouts/errors immediately

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

if (file.isDirectory()) {
list_files(`${dir}/${file.name}`, joined, files);
if (stats.isDirectory()) {
list_files(full, joined, files);
} else {
files.push(joined);
}
Expand Down
38 changes: 38 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { test } from 'uvu';
Expand Down Expand Up @@ -95,6 +96,43 @@ test('creates routes', () => {
]);
});

const symlink_survived_git = fs
.statSync(path.join(cwd, 'samples/symlinks/routes/foo'))
.isSymbolicLink();

const test_symlinks = symlink_survived_git ? test : test.skip;

test_symlinks('creates symlinked routes', () => {
const { components, routes } = create('samples/symlinks/routes');

const index = 'samples/symlinks/routes/index.svelte';
const symlinked_index = 'samples/symlinks/routes/foo/index.svelte';

assert.equal(components, [default_layout, default_error, symlinked_index, index]);

assert.equal(routes, [
{
type: 'page',
id: '',
pattern: /^\/$/,
path: '/',
shadow: null,
a: [default_layout, index],
b: [default_error]
},

{
type: 'page',
id: 'foo',
pattern: /^\/foo\/?$/,
path: '/foo',
shadow: null,
a: [default_layout, symlinked_index],
b: [default_error]
}
]);
});

test('creates routes with layout', () => {
const { components, routes } = create('samples/basic-layout');

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/test/prerendering/paths-base/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config = {
adapter: adapter(),

paths: {
base: '/path-base',
base: '/path-base'
},

prerender: {
Expand Down