-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add warning if some preset import is overridden #29971
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,25 @@ | |
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) | ||
} | ||
OrbisK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for (const i of scannedImports) { | ||
const name = i.as ?? i.name | ||
const preset = presetMap.get(name) | ||
Check failure on line 133 in packages/nuxt/src/imports/module.ts GitHub Actions / build
|
||
|
||
if (preset) { | ||
console.warn(`[imports] "${name}" is already defined and auto imported from "${preset ?? 'unknown preset'}" within nuxt itself. Please consider renaming "${name}" at ${i.from}.`) | ||
} | ||
Comment on lines
+132
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion Enhance the warning implementation. While the warning implementation works, it could be improved for better developer experience and code consistency:
Apply this diff to implement these improvements: -const name = i.as ?? i.name
-const preset = presetMap.get(name)
-
-if (preset) {
- console.warn(`[imports] "${name}" is already defined and auto imported from "${preset ?? 'unknown preset'}" within nuxt itself. Please consider renaming "${name}" at ${i.from}.`)
-}
+const importName = i.as ?? i.name
+const presetSource = presetMap.get(importName)
+if (!presetSource) {
+ continue
+}
+
+logger.warn(
+ `Import conflict: "${importName}" is already auto-imported from preset "${presetSource}"\n` +
+ ` Source: ${i.from}\n` +
+ ` Solution: Consider renaming the import or using a different name via 'as' syntax`
+)
π§° Toolsπͺ GitHub Check: build[failure] 133-133: |
||
|
||
i.priority = i.priority || priorities.find(([dir]) => i.from.startsWith(dir))?.[1] | ||
} | ||
imports.push(...scannedImports) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous implementation has type issues. types are weired on the presets. I tried to solve it like this, but seems kinda hacky