Repository navigation
fix(kit,nuxt): resolve auto-import type paths through shared resolver - #35451
Conversation
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/kit/src/types.ts`:
- Around line 57-72: `resolveRoot()` is caching package roots only by `basePkg`,
which can return the wrong result when the same package is resolved from
different `from` locations. Update the cache key in `packages/kit/src/types.ts`
so it also includes the `from` inputs used by `resolveModulePath` inside
`resolveRoot`, and make sure the cache lookup/store in `rootCache` is keyed by
both `basePkg` and the resolved `from` context.
- Around line 85-110: The `resolveTypePaths()` implementation is order-dependent
because each async task mutates `results` with `push`, so the final array can
differ from the input `packages` order. Update `resolveTypePaths` to have each
`Promise.allSettled` task return its `[pkg, path]` pair (or nothing for
unresolved packages), then build the final array by flattening the settled
outcomes in the original `packages` iteration order. Keep the existing
`resolveModulePath`, `resolveDeclarationPath`, and `resolveRoot` logic intact
while removing shared mutation of `results`.
In `@packages/nuxt/src/imports/module.ts`:
- Line 2: The absolute alias target handling in the imports module is still only
stripping extensions, so declaration-only `.d.mts`/`.d.cts` neighbors can be
missed for `.mjs`/`.cjs` runtime files. Update the alias resolution path in
`module.ts` to reuse the shared declaration resolution logic used by
`resolveTypePaths()` (rather than just stripping extensions), and apply it
wherever absolute alias targets are normalized so the declaration file is chosen
when present.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0aaa4e6c-6b7c-4244-817a-020c40dea971
📒 Files selected for processing (10)
packages/kit/src/index.tspackages/kit/src/template.tspackages/kit/src/types.tspackages/kit/test/types.spec.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/core/templates.tspackages/nuxt/src/core/utils/types.tspackages/nuxt/src/imports/module.tspackages/nuxt/src/pages/module.tspackages/nuxt/test/resolve-type-paths.test.ts
💤 Files with no reviewable changes (3)
- packages/nuxt/src/core/utils/types.ts
- packages/nuxt/src/core/templates.ts
- packages/nuxt/test/resolve-type-paths.test.ts
Merging this PR will not alter performance
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | loadNuxt in the basic test fixture (dev) |
329 ms | 374.4 ms | -12.11% |
| ⚡ | writeTypes in the basic-types fixture |
51.2 ms | 44.2 ms | +15.77% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/autoimport-types (8f32aac) with main (7b7595b)
Footnotes
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
🔗 Linked issue
regression from #35333
📚 Description
this creates
twothree shared utilities we can consume in nuxt (previously we were duplicating this same logic everywhere and it was diverging in unhelpful ways) for consistent type path resolution