Skip to content

Commit

Permalink
fix: auto import the multiple levels of nested directories in 'utils'
Browse files Browse the repository at this point in the history
  • Loading branch information
noootwo committed Dec 4, 2024
1 parent f982f99 commit b429419
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 1 deletion.
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

0 comments on commit b429419

Please sign in to comment.