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: auto import the multiple levels of nested directories in utils/ #2953

Merged
merged 2 commits into from
Jan 4, 2025
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
2 changes: 1 addition & 1 deletion src/core/config/resolvers/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function resolveImportsOptions(options: NitroOptions) {
// Auto imports from utils dirs
options.imports.dirs ??= [];
options.imports.dirs.push(
...options.scanDirs.map((dir) => join(dir, "utils/*"))
...options.scanDirs.map((dir) => join(dir, "utils/**/*"))
);

// Normalize exclude
Expand Down
1 change: 1 addition & 0 deletions test/fixture/routes/imports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default defineEventHandler(() => {
return {
testUtil: testUtil(),
testNestedUtil: testFooUtil() + testBarUtil(),
};
});
1 change: 1 addition & 0 deletions test/fixture/utils/foo/bar/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const testBarUtil = () => 12_345;
1 change: 1 addition & 0 deletions test/fixture/utils/foo/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const testFooUtil = () => 1234;
1 change: 1 addition & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ export function testNitro(
const res = await callHandler({ url: "/imports" });
expect(res.data).toMatchObject({
testUtil: 123,
testNestedUtil: 1234 + 12_345,
});
});

Expand Down
Loading