Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

No description provided.

@schiller-manuel schiller-manuel requested a review from pi0 as a code owner January 7, 2026 22:58
@vercel
Copy link

vercel bot commented Jan 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nitro.build Ready Ready Preview, Comment Jan 7, 2026 11:46pm

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Nitro Service Registration
src/build/vite/plugin.ts
Implements automatic registration of server-consumer environments as services. Iterates through userConfig.environments, skips ssr/client/nitro or non-server consumers or already-registered environments, resolves environment entry via getEntry and resolveModulePath with defaults, and assigns to ctx.services[name] as { entry }.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author. Add a description explaining the motivation, implementation details, and any relevant context for the changes made.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'feat' prefix and clearly describes the main change of auto-registering server consumer environments as services in the vite plugin.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch auto-register-vite-server-env

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c2f1c0 and 704b47a.

📒 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}: Use pathe for cross-platform path operations instead of Node.js node: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 consola for logging in build/dev code; use nitro.logger when available

Files:

  • src/build/vite/plugin.ts
src/**/*.{ts,js}

📄 CodeRabbit inference engine (AGENTS.md)

Use unstorage for 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)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitrojs/nitro@3928

commit: 190f91d

@pi0 pi0 changed the title vite: Auto-register server consumer environments as services feat(vite): auto-register server consumer environments as services Jan 7, 2026
@pi0 pi0 merged commit 67b43f2 into main Jan 8, 2026
16 of 17 checks passed
@pi0 pi0 deleted the auto-register-vite-server-env branch January 8, 2026 00:35
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.

3 participants