From 651877629c36a8b08ccfbe8c1df8c8bb9cc0617f Mon Sep 17 00:00:00 2001 From: Inesh Bose <56732164+ineshbose@users.noreply.github.com> Date: Fri, 13 Jan 2023 13:02:31 +0000 Subject: [PATCH 1/2] refactor: composables import path --- .../1.docs/2.guide/2.directory-structure/1.composables.md | 3 ++- packages/nuxt/src/imports/module.ts | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md b/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md index bd7e9f5153a..465c192964c 100644 --- a/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md +++ b/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md @@ -82,10 +82,11 @@ composables | - index.ts // scanned | - useFoo.ts // scanned | - nested + | --- index.ts // scanned | --- utils.ts // not scanned ``` -Only `composables/index.ts` and `composables/useFoo.ts` would be searched for imports. +Only `composables/index.ts`, `composables/useFoo.ts` and `composables/nested/index.ts` would be searched for imports. To get auto imports working for nested modules, you could either re-export them (recommended) or configure the scanner to include nested directories: diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index a26d941de1d..2d676836209 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -49,6 +49,7 @@ export default defineNuxtModule>({ let composablesDirs: string[] = [] for (const layer of nuxt.options._layers) { composablesDirs.push(resolve(layer.config.srcDir, 'composables')) + composablesDirs.push(resolve(layer.config.srcDir, 'composables/*/index.{ts,js,mjs,mts}')) composablesDirs.push(resolve(layer.config.srcDir, 'utils')) for (const dir of (layer.config.imports?.dirs ?? [])) { if (!dir) { From 0337382a4d15a5b3e6f86912029cdb480b91f17d Mon Sep 17 00:00:00 2001 From: Inesh Bose <56732164+ineshbose@users.noreply.github.com> Date: Fri, 13 Jan 2023 16:06:45 +0000 Subject: [PATCH 2/2] fix: add scanning for index.ts in utils --- packages/nuxt/src/imports/module.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 2d676836209..01f1c6731bb 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -51,6 +51,7 @@ export default defineNuxtModule>({ composablesDirs.push(resolve(layer.config.srcDir, 'composables')) composablesDirs.push(resolve(layer.config.srcDir, 'composables/*/index.{ts,js,mjs,mts}')) composablesDirs.push(resolve(layer.config.srcDir, 'utils')) + composablesDirs.push(resolve(layer.config.srcDir, 'utils/*/index.{ts,js,mjs,mts}')) for (const dir of (layer.config.imports?.dirs ?? [])) { if (!dir) { continue