From 9f9e3e6917bdb306ac30634d9fa6a84539b81017 Mon Sep 17 00:00:00 2001 From: rgehbt <74761884+Gehbt@users.noreply.github.com> Date: Tue, 23 Apr 2024 20:19:12 +0800 Subject: [PATCH] fix(nuxt): don't scan component dirs when `enabled` is `false` (#26906) --- packages/nuxt/src/components/scan.ts | 3 +++ packages/nuxt/test/scan-components.test.ts | 7 ++++++- packages/schema/src/types/components.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/components/scan.ts b/packages/nuxt/src/components/scan.ts index 4f21454e6a..dc3eb4f2a6 100644 --- a/packages/nuxt/src/components/scan.ts +++ b/packages/nuxt/src/components/scan.ts @@ -26,6 +26,9 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr const scannedPaths: string[] = [] for (const dir of dirs) { + if (dir.enabled === false) { + continue + } // A map from resolved path to component name (used for making duplicate warning message) const resolvedNames = new Map() diff --git a/packages/nuxt/test/scan-components.test.ts b/packages/nuxt/test/scan-components.test.ts index 2fffdebcb5..a4e8f172da 100644 --- a/packages/nuxt/test/scan-components.test.ts +++ b/packages/nuxt/test/scan-components.test.ts @@ -86,7 +86,7 @@ const dirs: ComponentsDir[] = [ transpile: false, }, ] - +const dirUnable = dirs.map((d) => { return { ...d, enabled: false } }) const expectedComponents = [ { chunkName: 'components/isle-server', @@ -243,3 +243,8 @@ it('components:scanComponents', async () => { } expect(scannedComponents).deep.eq(expectedComponents) }) + +it('components:scanComponents:unable', async () => { + const scannedComponents = await scanComponents(dirUnable, srcDir) + expect(scannedComponents).deep.eq([]) +}) diff --git a/packages/schema/src/types/components.ts b/packages/schema/src/types/components.ts index d0a9507d04..9bea3a8cdc 100644 --- a/packages/schema/src/types/components.ts +++ b/packages/schema/src/types/components.ts @@ -53,7 +53,7 @@ export interface ScanDir { */ pathPrefix?: boolean /** - * Ignore scanning this directory if set to `true` + * Ignore scanning this directory if set to `false` */ enabled?: boolean /**