Skip to content

Commit

Permalink
feat: add warning if some preset import is overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
OrbisK committed Nov 19, 2024
1 parent d9b7ac1 commit 0540391
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/nuxt/src/imports/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,24 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
const scannedImports = await scanDirExports(composablesDirs, {
fileFilter: file => !isIgnored(file),
})

const presetMap = new Map<string, typeof presets[]>()

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) {

Check failure on line 131 in packages/nuxt/src/imports/module.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'InlinePreset | PresetImport' is not assignable to parameter of type 'string'.
const preset = presetMap.get(i.as)

Check failure on line 133 in packages/nuxt/src/imports/module.ts

View workflow job for this annotation

GitHub Actions / build

Property 'as' does not exist on type 'ImportPresetWithDeprecation'.

Check failure on line 133 in packages/nuxt/src/imports/module.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string' is not assignable to parameter of type 'ImportPresetWithDeprecation[][]'.
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.`)
}

Check failure on line 137 in packages/nuxt/src/imports/module.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1]
}
imports.push(...scannedImports)
Expand Down

0 comments on commit 0540391

Please sign in to comment.