From 273216956421151cc87a6dd0e17476db30e97aa5 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Wed, 11 Dec 2024 16:52:05 +0800 Subject: [PATCH 1/4] add fix --- packages/kit/src/utils/filesystem.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/utils/filesystem.js b/packages/kit/src/utils/filesystem.js index ff83568e0358..58bcce22c7e3 100644 --- a/packages/kit/src/utils/filesystem.js +++ b/packages/kit/src/utils/filesystem.js @@ -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; From 686e6ae84676624b3e3f7d9500cf737816a78d18 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Wed, 11 Dec 2024 16:59:13 +0800 Subject: [PATCH 2/4] add test --- packages/kit/src/utils/filesystem.spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/kit/src/utils/filesystem.spec.js b/packages/kit/src/utils/filesystem.spec.js index 443268314d50..e9ccf8d832a9 100644 --- a/packages/kit/src/utils/filesystem.spec.js +++ b/packages/kit/src/utils/filesystem.spec.js @@ -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'); +}); From 6536b65e16b441adfbdd6dcae814dea68f9a2f9b Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Wed, 11 Dec 2024 17:06:10 +0800 Subject: [PATCH 3/4] changeset --- .changeset/brown-bats-mate.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brown-bats-mate.md diff --git a/.changeset/brown-bats-mate.md b/.changeset/brown-bats-mate.md new file mode 100644 index 000000000000..cda1f77ce152 --- /dev/null +++ b/.changeset/brown-bats-mate.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: correctly resolves hooks when similarly named directory exists From fe771b271e67b43d5403309fb7bffe19890e5914 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 11 Dec 2024 17:12:47 +0800 Subject: [PATCH 4/4] Update .changeset/brown-bats-mate.md --- .changeset/brown-bats-mate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/brown-bats-mate.md b/.changeset/brown-bats-mate.md index cda1f77ce152..3b0c4b70dabe 100644 --- a/.changeset/brown-bats-mate.md +++ b/.changeset/brown-bats-mate.md @@ -2,4 +2,4 @@ '@sveltejs/kit': patch --- -fix: correctly resolves hooks when similarly named directory exists +fix: correctly resolve hooks file when a similarly named directory exists