Skip to content

feat(nuxt,nitro): auto-import types from app/types and server/types directories - #35783

Merged
danielroe merged 4 commits into
nuxt:mainfrom
Flo0806:feat/app-server-types
Jul 27, 2026
Merged

danielroe merged 4 commits into
nuxt:mainfrom
Flo0806:feat/app-server-types

Conversation

@Flo0806

@Flo0806 Flo0806 commented Jul 21, 2026

Copy link
Copy Markdown
Member

🔗 Linked issue

Resolves: #35763

📚 Description

Now types (flat) in app/types are auto-imported by Nuxt. Also server/types. This let you make a more clear structure if needed.
The flag experimental.nitroAutoImports === false disables the nitro server/types auto-import, too.

Tests

Added tests

Docs

Docs are updated on three places

@Flo0806
Flo0806 requested a review from danielroe as a code owner July 21, 2026 19:52
@github-actions github-actions Bot added 5.x ✨ enhancement New feature or improvement to existing functionality labels Jul 21, 2026
@Flo0806 Flo0806 changed the title feat(nuxt,nitro): auto-import types from app/typesandserver/types directories feat(nuxt,nitro): auto-import types from app/types and server/types directories Jul 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35783

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35783

nuxt

npm i https://pkg.pr.new/nuxt@35783

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35783

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35783

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35783

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35783

commit: 29047bb

@coderabbitai

This comment has been minimized.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
docs/2.directory-structure/1.server.md (1)

169-187: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Verify the documented flat-directory guarantee with a regression test.

The documentation now promises that nested server/types files are excluded, but the implementation only registers the directory with Nitro and the current snapshot checks directory registration, not scan depth. Add a nested fixture and assert that its type is not auto-imported, or explicitly constrain the scanner to direct files.

Based on the documented contract and the supplied directory-only test, this behaviour still needs verification.

🤖 Prompt for 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.

In `@docs/2.directory-structure/1.server.md` around lines 169 - 187, Add a
regression test for the server types auto-import behavior using the existing
directory-registration test setup: create a nested server/types fixture and
verify its type is not available for auto-import, while preserving direct-file
support. If the scanner currently includes nested files, constrain it to scan
only files directly under server/types so the implementation matches the
documented flat-directory contract.
packages/nuxt/test/shared-dir-config.test.ts (1)

11-41: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the nitroAutoImports: false opt-out.

These tests cover default directory discovery and app/server separation, but not the PR objective that experimental.nitroAutoImports: false disables Nitro auto-imports. Add a case that captures config.imports and asserts it is false (or at least that no server/types directory is passed).

Based on the PR objective, this opt-out is an explicit acceptance criterion.

🤖 Prompt for 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.

In `@packages/nuxt/test/shared-dir-config.test.ts` around lines 11 - 41, Extend
the shared-directory configuration tests with a case that configures
experimental.nitroAutoImports as false, captures the resulting config.imports
value, and asserts the opt-out is preserved as false (or prevents server/types
from being passed). Reuse the existing test setup and configuration symbols
rather than changing the default directory-discovery assertions.
🤖 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.

Nitpick comments:
In `@docs/2.directory-structure/1.server.md`:
- Around line 169-187: Add a regression test for the server types auto-import
behavior using the existing directory-registration test setup: create a nested
server/types fixture and verify its type is not available for auto-import, while
preserving direct-file support. If the scanner currently includes nested files,
constrain it to scan only files directly under server/types so the
implementation matches the documented flat-directory contract.

In `@packages/nuxt/test/shared-dir-config.test.ts`:
- Around line 11-41: Extend the shared-directory configuration tests with a case
that configures experimental.nitroAutoImports as false, captures the resulting
config.imports value, and asserts the opt-out is preserved as false (or prevents
server/types from being passed). Reuse the existing test setup and configuration
symbols rather than changing the default directory-discovery assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 68832a56-303e-4187-a2c5-973781e994a2

📥 Commits

Reviewing files that changed from the base of the PR and between ba42831 and 7fdb8a2.

📒 Files selected for processing (6)
  • docs/2.directory-structure/1.app/1.utils.md
  • docs/2.directory-structure/1.server.md
  • docs/2.directory-structure/1.shared.md
  • packages/nitro-server/src/index.ts
  • packages/nuxt/src/imports/module.ts
  • packages/nuxt/test/shared-dir-config.test.ts

@codspeed

codspeed Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 11.27%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 19 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ writeTypes in the basic-types fixture 46.2 ms 52.3 ms -11.61%
❌ loadNuxt in the basic test fixture 382.6 ms 429.6 ms -10.92%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Flo0806:feat/app-server-types (29047bb) with main (ba42831)

Open in CodSpeed

Footnotes

  1. 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. ↩

@danielroe danielroe added this to the 4.6 milestone Jul 21, 2026
@danielroe
danielroe added this pull request to the merge queue Jul 27, 2026
Merged via the queue into nuxt:main with commit 48886c5 Jul 27, 2026
33 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 27, 2026
2 of 5 tasks
danielroe pushed a commit that referenced this pull request Aug 12, 2026
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
danielroe pushed a commit that referenced this pull request Aug 12, 2026
@github-actions github-actions Bot mentioned this pull request Aug 12, 2026
@github-actions github-actions Bot mentioned this pull request Aug 28, 2026
@Flo0806
Flo0806 deleted the feat/app-server-types branch September 4, 2026 08:27
@github-actions github-actions Bot mentioned this pull request Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x ✨ enhancement New feature or improvement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-import types from app/types

2 participants