Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Process symlinked routes #4957

Merged
merged 5 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 sym-linked routes
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(`${dir}/${file}`, joined, files);
mikenikles marked this conversation as resolved.
Show resolved Hide resolved
} else {
files.push(joined);
}
Expand Down
31 changes: 31 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,37 @@ test('creates routes', () => {
]);
});

test('creates sym-linked routes', () => {
const { components, routes } = create('samples/sym-link/routes');

const index = 'samples/sym-link/routes/index.svelte';
const symlinked_index = 'samples/sym-link/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