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: correctly resolve hooks entry file when directory exists #13144

Merged
merged 4 commits into from
Dec 11, 2024
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/brown-bats-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: correctly resolve hooks file when a similarly named directory exists
5 changes: 3 additions & 2 deletions packages/kit/src/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ export function from_fs(str) {
export function resolve_entry(entry) {
if (fs.existsSync(entry)) {
const stats = fs.statSync(entry);
if (stats.isDirectory()) {
return resolve_entry(path.join(entry, 'index'));
const index = path.join(entry, 'index');
if (stats.isDirectory() && fs.existsSync(index)) {
return resolve_entry(index);
}

return entry;
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/src/utils/filesystem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ test('ignores hooks.server folder when resolving hooks', () => {

expect(resolve_entry(source_dir + '/hooks')).null;
});

test('ignores hooks folder that has no index file when resolving hooks', () => {
write('hooks/not-index.js', '');
write('hooks.js', '');

expect(resolve_entry(source_dir + '/hooks')).toBe(source_dir + '/hooks');
});
Loading