-
-
Notifications
You must be signed in to change notification settings - Fork 772
feat(vite): auto-register server consumer environments as services #3928
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds automatic registration of server-consumer environments as services during Nitro context setup. The change iterates through configured environments, resolves entry points, and assigns them to the services collection, enabling additional server-side environments to be recognized as services. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
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 (2)
src/build/vite/plugin.ts (2)
386-410: Consider extracting entry resolution logic to reduce duplication.The entry resolution pattern (lines 402-408) duplicates similar logic from the SSR handling block (lines 352-358). While both work correctly, extracting this into a helper function would improve maintainability and adhere to the DRY principle.
♻️ Suggested refactor
Create a helper function:
function resolveServiceEntry( entry: string, ctx: NitroPluginContext ): string { return ( resolveModulePath(entry, { from: [ctx.nitro!.options.rootDir, ...ctx.nitro!.options.scanDirs], extensions: DEFAULT_EXTENSIONS, suffixes: ["", "/index"], try: true, }) || entry ); }Then use it in both places:
if (typeof ssrEntry === "string") { - ssrEntry = - resolveModulePath(ssrEntry, { - from: [ctx.nitro.options.rootDir, ...ctx.nitro.options.scanDirs], - extensions: DEFAULT_EXTENSIONS, - suffixes: ["", "/index"], - try: true, - }) || ssrEntry; + ssrEntry = resolveServiceEntry(ssrEntry, ctx); ctx.services.ssr = { entry: ssrEntry }; }const entry = getEntry(envConfig.build?.rollupOptions?.input); if (typeof entry === "string") { - const resolvedEntry = - resolveModulePath(entry, { - from: [ctx.nitro.options.rootDir, ...ctx.nitro.options.scanDirs], - extensions: DEFAULT_EXTENSIONS, - suffixes: ["", "/index"], - try: true, - }) || entry; + const resolvedEntry = resolveServiceEntry(entry, ctx); ctx.services[envName] = { entry: resolvedEntry }; }
386-410: Add logging for auto-registered environments to match SSR registration pattern.The SSR environment registration logs when an entry is found (lines 342-344), but the auto-registration logic for server consumer environments doesn't. For consistency and observability, add logging when environments are auto-registered as services.
Suggested enhancement
const entry = getEntry(envConfig.build?.rollupOptions?.input); if (typeof entry === "string") { const resolvedEntry = resolveModulePath(entry, { from: [ctx.nitro.options.rootDir, ...ctx.nitro.options.scanDirs], extensions: DEFAULT_EXTENSIONS, suffixes: ["", "/index"], try: true, }) || entry; ctx.services[envName] = { entry: resolvedEntry }; + ctx.nitro.logger.info( + `Auto-registered \`${envName}\` environment as service with entry \`${prettyPath(resolvedEntry)}\`.` + ); } }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/build/vite/plugin.ts
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.{ts,js,tsx,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.{ts,js,tsx,jsx}: Usepathefor cross-platform path operations instead of Node.jsnode:path
Use ESM and modern JavaScript
Do not add comments explaining what the line does unless prompted
Files:
src/build/vite/plugin.ts
src/{build,dev,runner,cli}/**/*.{ts,js}
📄 CodeRabbit inference engine (AGENTS.md)
Use
consolafor logging in build/dev code; usenitro.loggerwhen available
Files:
src/build/vite/plugin.ts
src/**/*.{ts,js}
📄 CodeRabbit inference engine (AGENTS.md)
Use
unstoragefor storage abstraction
Files:
src/build/vite/plugin.ts
src/build/**/*.{ts,js}
📄 CodeRabbit inference engine (AGENTS.md)
Virtual modules must be registered in
src/build/virtual.ts
Files:
src/build/vite/plugin.ts
⏰ 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). (4)
- GitHub Check: tests-rollup (windows-latest)
- GitHub Check: tests-rollup (ubuntu-latest)
- GitHub Check: tests-rolldown (ubuntu-latest)
- GitHub Check: tests-rolldown (windows-latest)
commit: |
No description provided.