Skip to content

fix(vite): generate nitro types in vite builder#4387

Open
p-dubovitsky wants to merge 1 commit into
nitrojs:mainfrom
p-dubovitsky:fix-vite-types-generation
Open

fix(vite): generate nitro types in vite builder#4387
p-dubovitsky wants to merge 1 commit into
nitrojs:mainfrom
p-dubovitsky:fix-vite-types-generation

Conversation

@p-dubovitsky

Copy link
Copy Markdown
Contributor

🔗 Linked issue

#4379

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Vite builder did not generate Nitro types, so .nitro/types/ declarations were missing during dev and build.

This PR makes the Vite builder run Nitro type generation during setup, and also regenerates types after Nitro config changes in dev mode. This makes route, config, and import declarations available for Vite-based projects.

Added tests for both Vite dev and prod builder flows to make sure the expected declaration files are written.

Resolves #4379

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@p-dubovitsky p-dubovitsky requested a review from pi0 as a code owner June 26, 2026 20:41
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@p-dubovitsky is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bb106cf8-98b8-439a-b017-13604d251eff

📥 Commits

Reviewing files that changed from the base of the PR and between 83acc44 and 030618f.

📒 Files selected for processing (3)
  • src/build/vite/dev.ts
  • src/build/vite/plugin.ts
  • test/vite/types.test.ts

📝 Walkthrough

Walkthrough

The Vite builder now writes Nitro type declarations during setup and debounced dev reloads. A new Vitest suite checks the generated declaration files in both dev-server and production build flows.

Changes

Vite type generation

Layer / File(s) Summary
Setup and reload write types
src/build/vite/plugin.ts, src/build/vite/dev.ts
writeTypes is imported and awaited during Nitro setup after rollup:before, and during debounced scan-dir reload handling before invalidation and full reload.
Declaration output tests
test/vite/types.test.ts
The new Vitest suite removes the types directory, runs the Vite dev server or Nitro build, and asserts the expected declaration files exist.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • nitrojs/nitro#4333: Changes writeTypes emission logic in src/build/types.ts, which is the same type-generation path invoked by this PR.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses a valid conventional-commits format and clearly matches the Vite type-generation fix.
Description check ✅ Passed The description directly explains the Vite builder type-generation bug and the fix, so it is on-topic.
Linked Issues check ✅ Passed The changes generate Nitro types during Vite setup and dev reloads, matching the linked issue's expected behavior.
Out of Scope Changes check ✅ Passed The added code and tests stay focused on Vite Nitro type generation without unrelated scope creep.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jun 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4387

commit: 030618f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite builder does not write generated Nitro types

1 participant