-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix(nuxt): include core auto-imports from imports:sources in override warning
#33050
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
Conversation
|
|
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/nuxt/src/imports/module.ts (1)
146-154: Bug: this will warn for Nuxt’s own internal imports (false positives).The current condition uses
i.__nuxt_internalon the item being iterated, so it logs for the internal import itself (e.g.definePageMeta) rather than when a user import overrides it. You need to compare user-defined imports against the set of internal-import names, and skip logging for the internal entries themselves.Proposed fix:
- for (const i of (imports as ImportInternal[])) { - if (!defaultImportSources.has(i.from)) { - const value = i.as || i.name - if ((defaultImports.has(value) || i.__nuxt_internal) && (!i.priority || i.priority >= 0 /* default priority */)) { - const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from - logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`) - } - } - } + // Build a lookup of names reserved by Nuxt (defaults + dynamically-added internal ones) + const internalImportNames = new Set<string>( + (imports as ImportInternal[]) + .filter(j => j.__nuxt_internal) + .map(j => j.as || j.name), + ) + + for (const i of (imports as ImportInternal[])) { + if (defaultImportSources.has(i.from)) { continue } + const value = i.as || i.name + const conflictsWithDefault = defaultImports.has(value) + const conflictsWithInternal = internalImportNames.has(value) && !i.__nuxt_internal + if ((conflictsWithDefault || conflictsWithInternal) && (!i.priority || i.priority >= 0 /* default priority */)) { + const relativePath = isAbsolute(i.from) ? `${resolveToAlias(i.from, nuxt)}` : i.from + logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`) + } + }
🧹 Nitpick comments (7)
packages/nuxt/src/imports/utils.ts (3)
5-10: Docstring vs behaviour: this mutates the input, not “creates a new Import object”.Either adjust the wording or clone before tagging to avoid surprising callers.
Option A — clarify doc:
- * Creates a new `Import` object marked as an internal Nuxt entity to be able to warn users when they override it. + * Marks the given `Import` object as an internal Nuxt entity (non-enumerable) so we can warn when users override it.Option B — actually create a new object (keeps callers’ inputs immutable):
-export function createInternalImport (i: Import): Import { - return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false }) -} +export function createInternalImport (i: Import): Import { + const clone = { ...i } + return Object.defineProperty(clone, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false }) +}
8-10: Return a narrowed type to avoid downstream casts.You already export
ImportInternal; returning it here removes the need to cast in consumers.-export function createInternalImport (i: Import): Import { +export function createInternalImport (i: Import): ImportInternal { - return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false }) + return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false }) as ImportInternal }
9-9: Explicitly setconfigurableandwritableto false for clarity.Defaults are false, but being explicit communicates intent and prevents accidental mutation in future refactors.
-return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false }) +return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false })packages/nuxt/src/imports/module.ts (2)
151-151: Severity wording: considerlogger.warnto align with “warning” in the PR title and intent.Functionally the same, but matches the messaging and reduces noise for users.
- logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`) + logger.warn(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`)
13-13: Import extension consistency for type-only imports.
import type ... from './utils.ts'is erased at emit; both with and without.tstypically work under NodeNext. Please ensure this is consistent with the rest of the repo’s TS imports (style often omits.tsfor type-only).If the repo prefers extension-less type imports, apply:
-import type { ImportInternal } from './utils.ts' +import type { ImportInternal } from './utils'packages/nuxt/src/pages/module.ts (2)
400-405: Also markdefineRouteRulesas internal when the experimental flag is enabled.If users override
defineRouteRulesthey’ll hit the same class of issues asdefinePageMeta. Tagging it keeps the warning consistent.- if (nuxt.options.experimental.inlineRouteRules) { - imports.push({ name: 'defineRouteRules', as: 'defineRouteRules', from: resolve(runtimeDir, 'composables') }) - } + if (nuxt.options.experimental.inlineRouteRules) { + imports.push(createInternalImport({ name: 'defineRouteRules', as: 'defineRouteRules', from: resolve(runtimeDir, 'composables') })) + }
22-22: Import extension consistency.Same note as in
imports/module.ts: consider omitting.tsfor type-only/runtime-internal imports if that’s the project style.-import { createInternalImport } from '../imports/utils.ts' +import { createInternalImport } from '../imports/utils'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
packages/nuxt/src/imports/module.ts(2 hunks)packages/nuxt/src/imports/utils.ts(1 hunks)packages/nuxt/src/pages/module.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/imports/module.tspackages/nuxt/src/imports/utils.tspackages/nuxt/src/pages/module.ts
🧠 Learnings (2)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/nuxt/src/imports/module.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
packages/nuxt/src/pages/module.ts
🧬 Code graph analysis (2)
packages/nuxt/src/imports/module.ts (1)
packages/nuxt/src/imports/utils.ts (1)
ImportInternal(3-3)
packages/nuxt/src/pages/module.ts (1)
packages/nuxt/src/imports/utils.ts (1)
createInternalImport(8-10)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
- GitHub Check: release-pkg-pr-new
- GitHub Check: test-benchmark
- GitHub Check: typecheck (windows-latest, bundler)
- GitHub Check: typecheck (ubuntu-latest, bundler)
- GitHub Check: test-size
- GitHub Check: code
CodSpeed Performance ReportMerging #33050 will not alter performanceComparing Summary
|
imports:extends in override warningimports:sources in override warning
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/nuxt/src/imports/utils.ts (3)
5-10: Clone instead of mutating; align implementation with the docstring and make the return type internal.The JSDoc says “Creates a new … object”, but the function mutates the argument in place. Cloning avoids side effects and makes behaviour match the description. Also, returning
InternalImportPresetWithDeprecationremoves the need for downstream casts.Apply this diff:
/** - * Creates a new `ImportPresetWithDeprecation` object marked as internal to be able to warn users when they override it. + * Create a copy of the preset marked as internal (non-enumerable flag). + * Avoids mutating the original and lets us warn when it is overridden. */ -export function createInternalImportPresetWithDeprecation (i: ImportPresetWithDeprecation): ImportPresetWithDeprecation { - return Object.defineProperty(i, '__nuxt_internal', { value: true, enumerable: false }) -} +export function createInternalImportPresetWithDeprecation (i: ImportPresetWithDeprecation): InternalImportPresetWithDeprecation { + const preset = { ...i } as InternalImportPresetWithDeprecation + Object.defineProperty(preset, '__nuxt_internal', { value: true, enumerable: false, configurable: false, writable: false }) + return preset +}
3-3: Make the internal flag readonly in the type.The property is non-writable at runtime; reflect that intent in the type for better signalling and safety.
-export type InternalImportPresetWithDeprecation = ImportPresetWithDeprecation & { __nuxt_internal?: true } +export type InternalImportPresetWithDeprecation = ImportPresetWithDeprecation & { readonly __nuxt_internal?: true }
5-10: Optional: provide a type guard to centralise detection of internal presets.This avoids ad-hoc casts at call sites and keeps the flag name in one place.
Add the following helper near this util:
export function isInternalImportPresetWithDeprecation( p: ImportPresetWithDeprecation ): p is InternalImportPresetWithDeprecation { return Object.prototype.hasOwnProperty.call(p, '__nuxt_internal') }If you want, I can push a follow-up patch updating the call sites to use this guard instead of array casts.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
packages/nuxt/src/imports/module.ts(2 hunks)packages/nuxt/src/imports/utils.ts(1 hunks)packages/nuxt/src/pages/module.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/nuxt/src/pages/module.ts
- packages/nuxt/src/imports/module.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/imports/utils.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: code
# Conflicts: # packages/nuxt/src/pages/module.ts
|
I've updated the implementation. I haven't benchmarked it, I feel like this isn't going to be more performant 😕 I'll need to add more core auto-imports in #32300 from a module too. |
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.
Actionable comments posted: 2
🧹 Nitpick comments (2)
packages/nuxt/src/imports/module.ts (2)
13-13: Avoid .ts extension in source imports to keep build outputs portablePrefer extensionless import to prevent ESM resolution issues post-transpile and to align with repo style.
-import { distDir } from '../dirs.ts' +import { distDir } from '../dirs'
15-15: Tighten #app detection regexUse an explicit end-or-slash to avoid edge-case matches like
#appConfig.-const NUXT_APP_RE = /^#app\b/ +const NUXT_APP_RE = /^#app(?:$|\/)/
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/nuxt/src/imports/module.ts(4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/imports/module.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/nuxt/src/imports/module.ts
🧬 Code graph analysis (1)
packages/nuxt/src/imports/module.ts (2)
packages/kit/src/resolve.ts (1)
resolvePath(52-63)packages/nuxt/src/utils.ts (2)
resolveToAlias(16-18)logger(14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: code
🔇 Additional comments (2)
packages/nuxt/src/imports/module.ts (2)
2-2: LGTM on adding resolvePath importThis is appropriate for later resolution checks.
173-184: Review comment updateChange the conflict log to a warning and use the
isFromNuxtDistPathcheck:const value = i.as || i.name if ( (nuxtImportNames.has(value) || nuxtImportNamesFromPresets.has(value)) - && !((await resolvePath(i.from)).startsWith(distDir)) + && !(await isFromNuxtDistPath(i.from)) && (!i.priority || i.priority >= 0) ) { const relativePath = isAbsolute(i.from) ? resolveToAlias(i.from, nuxt) : i.from - logger.error(`\`${value}\` is an auto-imported function that is in use by Nuxt. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`) + logger.warn(`\`${value}\` is an internal Nuxt auto-import. Overriding it will likely cause issues. Please consider renaming \`${value}\` in \`${relativePath}\`.`) }Ensure
isFromNuxtDistPathis imported andlogger.warnis available in this module.
|
I was thinking more something like this - do you see any downsides? |
|
Ah, I see. This is great. Thank you! |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/nuxt/src/imports/module.ts (1)
154-160: Use canonicalised names for conflict detectionAfter adopting
nuxtImportNames, update the check to avoid missing conflicts.- if (nuxtImports.has(value) && (!i.priority || i.priority >= 0 /* default priority */)) { + if (nuxtImportNames.has(value) && (!i.priority || i.priority >= 0 /* default priority */)) {
🧹 Nitpick comments (2)
packages/nuxt/src/pages/module.ts (1)
431-436: Co-locateimports:sourceshooks for readabilityYou already adjust router guard imports via
imports:sourcesat Lines 309–314. Consider grouping these hooks together to make all import-source mutations discoverable in one place.packages/nuxt/src/imports/module.ts (1)
14-21: Avoid cross-module initialisation side-effects; extract shared presets to a sidecarImporting from
../pages/moduleexecutes that module’s top-level initialisation. To minimise coupling and evaluation cost, movepagesImportPresets/routeRulesPresetsinto a small shared file (e.g.../imports/core-presets.ts) that exports only data, and import from there in both modules.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/nuxt/src/imports/module.ts(3 hunks)packages/nuxt/src/pages/module.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/pages/module.tspackages/nuxt/src/imports/module.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
packages/nuxt/src/pages/module.tspackages/nuxt/src/imports/module.ts
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
packages/nuxt/src/imports/module.ts
🧬 Code graph analysis (1)
packages/nuxt/src/imports/module.ts (2)
packages/nuxt/src/pages/module.ts (2)
pagesImportPresets(29-32)routeRulesPresets(34-36)packages/nuxt/src/imports/presets.ts (1)
defaultPresets(277-283)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: code
🔇 Additional comments (4)
packages/nuxt/src/pages/module.ts (3)
23-23: LGTM: type-only importImporting
InlinePresetas a type keeps runtime lean. No issues.
29-32: VerifyuseLinkisn’t already provided by default presetsIf
routerPreset(inimports/presets.ts) already exposesuseLink, this introduces a duplicate preset entry. Unimport de-duplicates, but keeping a single source reduces noise.
34-36: LGTM: scoped preset fordefineRouteRulesExporting this as a preset is clean and keeps it composable with
imports:sources.packages/nuxt/src/imports/module.ts (1)
16-21: Double-check gating forrouteRulesPresets
allNuxtPresetsunconditionally includesrouteRulesPresets, while actual registration of those presets is gated byinlineRouteRules. Your name-set below usespresets(postimports:sources) so behaviour should be gated correctly, but please verify no warning is emitted fordefineRouteRuleswheninlineRouteRulesis false.
| const isIgnored = createIsIgnored(nuxt) | ||
| const defaultImportSources = new Set(defaultPresets.flatMap(i => i.from)) | ||
| const defaultImports = new Set(presets.flatMap(p => defaultImportSources.has(p.from) ? p.imports : [])) | ||
| const nuxtImportSources = new Set(allNuxtPresets.flatMap(i => i.from)) | ||
| const nuxtImports = new Set(presets.flatMap(p => nuxtImportSources.has(p.from) ? p.imports : [])) | ||
| const regenerateImports = async () => { |
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.
Normalise names and include per-import from to avoid false negatives
nuxtImports currently stores raw p.imports (strings, tuples, or objects). Later you .has(value: string), which won’t match tuples/objects. Also, some presets specify from per import; those sources should be included in the “Nuxt sources” set.
Apply the following diff and helper:
- const nuxtImportSources = new Set(allNuxtPresets.flatMap(i => i.from))
- const nuxtImports = new Set(presets.flatMap(p => nuxtImportSources.has(p.from) ? p.imports : []))
+ const nuxtImportSources = new Set(
+ allNuxtPresets
+ .flatMap(p => [
+ p.from,
+ ...p.imports.map(i => (typeof i === 'object' && !Array.isArray(i) && i?.from) ? i.from : undefined),
+ ])
+ .filter(Boolean) as string[],
+ )
+ const nuxtImportNames = new Set<string>(
+ presets.flatMap(p =>
+ p.imports
+ .map(i => {
+ const itemFrom = (typeof i === 'object' && !Array.isArray(i) && i?.from) ? i.from : p.from
+ return itemFrom && nuxtImportSources.has(itemFrom) ? normaliseImportName(i) : undefined
+ })
+ .filter(Boolean) as string[],
+ ),
+ )Place this helper near the top of the file:
function normaliseImportName(i: unknown): string | undefined {
if (typeof i === 'string') { return i }
if (Array.isArray(i)) { return (i[1] as string | undefined) || (i[0] as string | undefined) }
if (i && typeof i === 'object' && 'name' in (i as any)) {
const o = i as { name?: string; as?: string }
return o.as || o.name
}
return undefined
}🤖 Prompt for AI Agents
In packages/nuxt/src/imports/module.ts around lines 132-135, nuxtImports is
built from raw p.imports which may be strings, tuples, or objects causing .has
checks to miss matches and also ignores per-import from overrides; add the
provided normaliseImportName helper near the top of the file, expand
nuxtImportSources to include any per-import `from` values found on individual
imports, and rebuild nuxtImports by normalising each import entry (using
normaliseImportName) to a string before adding to the Set so tuple/object
imports match string checks later.
📚 Description
Following up on #29971, this adds a warning for overriding internal functions in auto-imports, which were added dynamically via
imports:sources. Currently, it isdefinePageMetaanddefineRouteRules, but there will be more in #32300.