From 05403910ac6606ff610f0eb9852aca927ed46770 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 19 Nov 2024 15:25:08 +0100 Subject: [PATCH 1/4] feat: add warning if some preset import is overridden --- packages/nuxt/src/imports/module.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index af728fb6db..ea1dfa740c 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -117,7 +117,24 @@ export default defineNuxtModule>({ const scannedImports = await scanDirExports(composablesDirs, { fileFilter: file => !isIgnored(file), }) + + const presetMap = new Map() + + for (const preset of presets) { + preset.imports = preset.imports || [] + for (const i of preset.imports) { + presetMap.set(i, preset.from) + } + presetMap.set(preset.as, preset.from) + } + for (const i of scannedImports) { + const preset = presetMap.get(i.as) + + if (preset) { + console.warn(`[imports] "${i.as}" is already defined and auto imported from "${preset}" within nuxt itself. Please don't name your composable the same as a preset, as it will lead to unexpected behavior.`) + } + i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1] } imports.push(...scannedImports) From 6aa5d126525f91d127d88b170f4bef72ff4b2834 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 19 Nov 2024 15:42:10 +0100 Subject: [PATCH 2/4] chore: clarify duplicate import message --- packages/nuxt/src/imports/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index ea1dfa740c..7b2a0f08bc 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -132,7 +132,7 @@ export default defineNuxtModule>({ const preset = presetMap.get(i.as) if (preset) { - console.warn(`[imports] "${i.as}" is already defined and auto imported from "${preset}" within nuxt itself. Please don't name your composable the same as a preset, as it will lead to unexpected behavior.`) + console.warn(`[imports] "${i.as}" is already defined and auto imported from "${preset}" within nuxt itself. Please consider renaming "${i.as}" at ${i.from}.`) } i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1] From 06add6e7fbb337cf2e61f8e0cd906c1606aa0473 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 19 Nov 2024 15:48:06 +0100 Subject: [PATCH 3/4] chore: clarify duplicate import message --- packages/nuxt/src/imports/module.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 7b2a0f08bc..33953704e7 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -121,7 +121,7 @@ export default defineNuxtModule>({ const presetMap = new Map() for (const preset of presets) { - preset.imports = preset.imports || [] + preset.imports = preset.imports ?? [] for (const i of preset.imports) { presetMap.set(i, preset.from) } @@ -129,10 +129,11 @@ export default defineNuxtModule>({ } for (const i of scannedImports) { - const preset = presetMap.get(i.as) + const name = i.as ?? i.name + const preset = presetMap.get(name) if (preset) { - console.warn(`[imports] "${i.as}" is already defined and auto imported from "${preset}" within nuxt itself. Please consider renaming "${i.as}" at ${i.from}.`) + console.warn(`[imports] "${name}" is already defined and auto imported from "${preset ?? 'unknown preset'}" within nuxt itself. Please consider renaming "${name}" at ${i.from}.`) } i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1] From 38bfe2a6bc00213b2b34f99322dfbe7ed01ada54 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 19 Nov 2024 16:44:37 +0100 Subject: [PATCH 4/4] chore: update map type --- packages/nuxt/src/imports/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index 33953704e7..c109219b89 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -118,7 +118,7 @@ export default defineNuxtModule>({ fileFilter: file => !isIgnored(file), }) - const presetMap = new Map() + const presetMap = new Map() for (const preset of presets) { preset.imports = preset.imports ?? []