Repository navigation
refactor(nuxt,nitro): use dev exports for no-build type-checking - #35605
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
packages/nitro-server/src/internal.d.ts (1)
1-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd export shapes for the internal virtual modules. These bare
declare modulestubs make the imports resolve, but they still drop export-shape checking for#internal/*;r.default.fetch(...)and similar calls will stay unchecked unless these modules declare their minimal exports.🤖 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/nitro-server/src/internal.d.ts` around lines 1 - 12, Replace the bare module declarations in the internal declaration file with minimal export-shape declarations for each virtual module, covering the actual default and named exports consumed by the code. Ensure default exports expose members such as fetch where applicable, while preserving module resolution for all listed `#internal` and `#spa-template` modules.packages/nuxt/src/core/templates.ts (1)
641-647: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider using
TYPE_FILENAME_REto strip the extension.If any templates output
.ts,.mts, or.cjsfiles, the hardcoded/\.m?js$/regex will not remove their extensions for the bare specifier. You can reuse the existingTYPE_FILENAME_REdefined earlier in the file to handle all script extensions robustly.♻️ Proposed refactor
// declare both extensioned (`#build/foo.mjs`) and bare (`#build/foo`) module specifiers const fullSpecifier = join('`#build`', file.filename) declarations += 'declare module ' + JSON.stringify(fullSpecifier) + ';\n' - const bareSpecifier = fullSpecifier.replace(/\.m?js$/, '') + const bareSpecifier = fullSpecifier.replace(TYPE_FILENAME_RE, '') if (bareSpecifier !== fullSpecifier) { declarations += 'declare module ' + JSON.stringify(bareSpecifier) + ';\n' }🤖 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/src/core/templates.ts` around lines 641 - 647, Update the bare specifier derivation in the module declaration generation block near fullSpecifier to use the existing TYPE_FILENAME_RE instead of the hardcoded /\.m?js$/ pattern, ensuring .ts, .mts, .cts, .js, .mjs, and .cjs extensions are stripped while preserving the fullSpecifier declaration.
🤖 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/nuxt/src/app/components/nuxt-layout.ts`:
- Around line 60-67: Update the layout selection assignment in the Nuxt layout
component so the complete nullish-coalescing expression is cast to LayoutName
after evaluating props.name, route metadata, route rules, and the default.
Preserve the existing precedence and fallback behavior while ensuring
intermediate string values do not violate the LayoutName type.
---
Nitpick comments:
In `@packages/nitro-server/src/internal.d.ts`:
- Around line 1-12: Replace the bare module declarations in the internal
declaration file with minimal export-shape declarations for each virtual module,
covering the actual default and named exports consumed by the code. Ensure
default exports expose members such as fetch where applicable, while preserving
module resolution for all listed `#internal` and `#spa-template` modules.
In `@packages/nuxt/src/core/templates.ts`:
- Around line 641-647: Update the bare specifier derivation in the module
declaration generation block near fullSpecifier to use the existing
TYPE_FILENAME_RE instead of the hardcoded /\.m?js$/ pattern, ensuring .ts, .mts,
.cts, .js, .mjs, and .cjs extensions are stripped while preserving the
fullSpecifier declaration.
🪄 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: 85549e44-834e-43cf-ab59-9da6edaccbf1
⛔ Files ignored due to path filters (8)
package.jsonis excluded by!package.json,!**/package.jsonpackages/kit/package.jsonis excluded by!**/package.jsonpackages/nitro-server/package.jsonis excluded by!**/package.jsonpackages/nuxt/package.jsonis excluded by!**/package.jsonpackages/rspack/package.jsonis excluded by!**/package.jsonpackages/schema/package.jsonis excluded by!**/package.jsonpackages/vite/package.jsonis excluded by!**/package.jsonpackages/webpack/package.jsonis excluded by!**/package.json
📒 Files selected for processing (87)
.github/workflows/autofix-docs.yml.github/workflows/autofix.yml.github/workflows/ci.yml.github/workflows/docs.yml.github/workflows/release.ymlpackages/nitro-server/src/augments.tspackages/nitro-server/src/index.tspackages/nitro-server/src/internal.d.tspackages/nitro-server/src/runtime/handlers/error.tspackages/nitro-server/src/runtime/handlers/island.tspackages/nitro-server/src/runtime/handlers/renderer.tspackages/nitro-server/src/runtime/plugins/dev-server-logs.tspackages/nitro-server/src/runtime/utils/app-config.tspackages/nitro-server/src/runtime/utils/cache.tspackages/nitro-server/src/runtime/utils/renderer/app.tspackages/nitro-server/src/runtime/utils/renderer/build-files.tspackages/nitro-server/src/runtime/utils/renderer/islands.tspackages/nitro-server/src/runtime/utils/renderer/payload.tspackages/nitro-server/src/templates.tspackages/nitro-server/tsdown.config.tspackages/nuxt/app.d.tspackages/nuxt/src/app/components/client-only.tspackages/nuxt/src/app/components/island-renderer.tspackages/nuxt/src/app/components/nuxt-island.tspackages/nuxt/src/app/components/nuxt-layout.tspackages/nuxt/src/app/components/nuxt-link.tspackages/nuxt/src/app/components/nuxt-route-announcer.tspackages/nuxt/src/app/components/nuxt-teleport-island-component.tspackages/nuxt/src/app/components/server-placeholder.tspackages/nuxt/src/app/components/test-component-wrapper.tspackages/nuxt/src/app/components/utils.tspackages/nuxt/src/app/composables/asyncData.tspackages/nuxt/src/app/composables/cookie.tspackages/nuxt/src/app/composables/error.tspackages/nuxt/src/app/composables/fetch.tspackages/nuxt/src/app/composables/manifest.tspackages/nuxt/src/app/composables/payload.tspackages/nuxt/src/app/composables/router.tspackages/nuxt/src/app/composables/ssr.tspackages/nuxt/src/app/composables/state.tspackages/nuxt/src/app/config.tspackages/nuxt/src/app/entry.tspackages/nuxt/src/app/index.tspackages/nuxt/src/app/nuxt.tspackages/nuxt/src/app/plugins/check-if-layout-used.tspackages/nuxt/src/app/plugins/check-outdated-build.client.tspackages/nuxt/src/app/plugins/dev-server-logs.tspackages/nuxt/src/app/plugins/payload.client.tspackages/nuxt/src/app/plugins/revive-payload.client.tspackages/nuxt/src/app/plugins/revive-payload.server.tspackages/nuxt/src/app/plugins/router.tspackages/nuxt/src/app/plugins/view-transitions.client.tspackages/nuxt/src/app/types.tspackages/nuxt/src/app/types/augments.tspackages/nuxt/src/build-stub-module.d.tspackages/nuxt/src/build-stubs.d.tspackages/nuxt/src/components/runtime/client-component.tspackages/nuxt/src/core/nuxt.tspackages/nuxt/src/core/plugins/plugin-metadata.tspackages/nuxt/src/core/templates.tspackages/nuxt/src/head/runtime/install-client-head.tspackages/nuxt/src/head/runtime/plugins/unhead-stream.client.tspackages/nuxt/src/head/runtime/plugins/unhead.client.tspackages/nuxt/src/pages/runtime/composables.tspackages/nuxt/src/pages/runtime/page-placeholder.tspackages/nuxt/src/pages/runtime/page.tspackages/nuxt/src/pages/runtime/plugins/prefetch.client.tspackages/nuxt/src/pages/runtime/plugins/prerender.server.tspackages/nuxt/src/pages/runtime/plugins/router.tspackages/nuxt/src/pages/runtime/utils.tspackages/nuxt/src/runtime/server/entry.tspackages/nuxt/tsconfig.build.jsonpackages/nuxt/types.dev.d.tspackages/schema/src/config/nitro.tspackages/schema/src/types/schema.tspackages/vite/src/fix-stacktrace.tsscripts/release.tstest/bundle.test.tstest/fixtures/basic-types/app/app-types.tstest/fixtures/basic-types/modules/test/index.tstest/fixtures/basic-types/nuxt.config.tstest/fixtures/minimal-pages/nuxt.config.tstest/fixtures/minimal-types/app-types.tstest/fixtures/minimal-types/nuxt.config.tstest/fixtures/minimal/nuxt.config.tstest/nuxt/client-only.test.tsvitest.config.ts
💤 Files with no reviewable changes (35)
- packages/nuxt/src/app/components/nuxt-teleport-island-component.ts
- packages/nitro-server/src/runtime/plugins/dev-server-logs.ts
- packages/nuxt/src/pages/runtime/plugins/prerender.server.ts
- packages/nuxt/src/app/plugins/revive-payload.client.ts
- packages/nuxt/src/app/plugins/dev-server-logs.ts
- packages/nuxt/src/app/entry.ts
- packages/nuxt/src/app/composables/fetch.ts
- packages/nuxt/src/app/config.ts
- packages/nuxt/src/app/plugins/router.ts
- packages/nitro-server/src/runtime/utils/cache.ts
- packages/nuxt/src/app/plugins/check-outdated-build.client.ts
- packages/nuxt/src/app/composables/cookie.ts
- packages/nuxt/src/app/composables/payload.ts
- packages/nuxt/src/components/runtime/client-component.ts
- packages/nuxt/src/app/components/island-renderer.ts
- packages/nuxt/src/app/plugins/revive-payload.server.ts
- packages/nitro-server/src/runtime/utils/app-config.ts
- packages/nuxt/src/app/composables/state.ts
- packages/nuxt/src/app/plugins/check-if-layout-used.ts
- packages/nuxt/src/app/components/nuxt-island.ts
- packages/nuxt/src/pages/runtime/page-placeholder.ts
- packages/nuxt/src/app/components/client-only.ts
- packages/nuxt/src/head/runtime/plugins/unhead-stream.client.ts
- packages/nuxt/src/app/plugins/view-transitions.client.ts
- packages/nuxt/src/app/composables/asyncData.ts
- packages/nuxt/src/app/components/test-component-wrapper.ts
- packages/nuxt/src/app/composables/ssr.ts
- packages/vite/src/fix-stacktrace.ts
- scripts/release.ts
- packages/nuxt/src/head/runtime/install-client-head.ts
- test/fixtures/basic-types/nuxt.config.ts
- packages/nuxt/src/pages/runtime/page.ts
- packages/nuxt/src/app/types/augments.ts
- packages/nuxt/src/head/runtime/plugins/unhead.client.ts
- packages/nuxt/src/app/components/server-placeholder.ts
| type LayoutName = keyof NuxtLayouts | false | 'default' | ||
| let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default' | ||
| if (layout && !(layout in layouts)) { | ||
| if (import.meta.dev && layout !== 'default') { | ||
| console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`) | ||
| } | ||
| if (props.fallback) { | ||
| layout = unref(props.fallback) | ||
| layout = unref(props.fallback as MaybeRef<LayoutName>) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix potential TypeScript error with LayoutName type assignment.
Assigning a string (from route?.meta.layout as string and routeRulesMatcher().appLayout) to LayoutName will cause a TypeScript compilation error if NuxtLayouts does not have a string index signature. Consider casting the entire evaluated expression to LayoutName.
🐛 Proposed fix
- let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default'
+ let layout: LayoutName = (unref(props.name) ?? route?.meta.layout ?? routeRulesMatcher(route?.path).appLayout ?? 'default') as LayoutName📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| type LayoutName = keyof NuxtLayouts | false | 'default' | |
| let layout: LayoutName = unref(props.name as LayoutName) ?? route?.meta.layout as string ?? routeRulesMatcher(route?.path).appLayout ?? 'default' | |
| if (layout && !(layout in layouts)) { | |
| if (import.meta.dev && layout !== 'default') { | |
| console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`) | |
| } | |
| if (props.fallback) { | |
| layout = unref(props.fallback) | |
| layout = unref(props.fallback as MaybeRef<LayoutName>) | |
| type LayoutName = keyof NuxtLayouts | false | 'default' | |
| let layout: LayoutName = (unref(props.name) ?? route?.meta.layout ?? routeRulesMatcher(route?.path).appLayout ?? 'default') as LayoutName | |
| if (layout && !(layout in layouts)) { | |
| if (import.meta.dev && layout !== 'default') { | |
| console.warn(`[nuxt] Invalid layout \`${layout}\` selected.`) | |
| } | |
| if (props.fallback) { | |
| layout = unref(props.fallback as MaybeRef<LayoutName>) |
🤖 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/src/app/components/nuxt-layout.ts` around lines 60 - 67, Update
the layout selection assignment in the Nuxt layout component so the complete
nullish-coalescing expression is cast to LayoutName after evaluating props.name,
route metadata, route rules, and the default. Preserve the existing precedence
and fallback behavior while ensuring intermediate string values do not violate
the LayoutName type.
Merging this PR will improve performance by 22.02%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | loadNuxtConfig in the minimal test fixture |
14.5 ms | 11.8 ms | +22.02% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/dev-exports (596cf52) with main (2e10cc4)
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. ↩
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
f09f644 to
1cb09c2
Compare
🔗 Linked issue
📚 Description
this is a pretty significant change which makes the nuxt monorepo no longer require a build step to do type checking or, indeed, any kind of testing in the repository.
probably more significant for contributors than anyone else, mind you!