Skip to content

Conversation

BobbieGoede
Copy link
Member

🔗 Linked issue

📚 Description

Noticed that addServerImports does not support passing a single import like addImports does. I haven't actually tested the code changes, but I matched the logic of addServerImportsDir.

While adding this I noticed the documentation was missing addServerImports entirely so I added that as well, this is basically the same as the documentation for addImports, feels a bit weird to duplicate it...

@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 08:36
@BobbieGoede BobbieGoede requested a review from danielroe as a code owner June 4, 2025 08:36
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for passing a single import object to addServerImports and includes its documentation.

  • Updated addServerImports to accept Import | Import[] by normalizing via toArray
  • Pushed normalized imports into config.imports.imports in Nitro hook
  • Added API docs for addServerImports in the Nitro section

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/kit/src/nitro.ts Extended addServerImports signature and added array handling
docs/3.api/5.kit/11.nitro.md Added and documented addServerImports API
Comments suppressed due to low confidence (3)

docs/3.api/5.kit/11.nitro.md:326

  • The parameter name dirs doesn’t match the function signature, which uses imports. Rename it to imports for consistency.
function addServerImports (dirs: Import | Import[]): void

packages/kit/src/nitro.ts:89

  • Add unit tests to cover the new single-import usage path of addServerImports to prevent regressions.
export function addServerImports (imports: Import | Import[]) {

packages/kit/src/nitro.ts:91

  • Ensure that toArray is imported in this module; otherwise this will cause a runtime error.
const _imports = toArray(imports)

Copy link

coderabbitai bot commented Jun 4, 2025

Walkthrough

A new section was added to the Nitro API documentation describing the addServerImports function, including its purpose, usage example, function signature, and a detailed parameters table. The function itself was updated to accept either a single Import object or an array of Import objects, with internal normalisation to handle both cases. This change is reflected in the documentation and the function signature, ensuring that the addServerImports function now supports both single and multiple import additions. The documentation update is positioned between the addPrerenderRoutes and addServerImportsDir sections. Additionally, minor formatting changes were made to the addImports example in the autoimports documentation, adjusting quotation marks and removing semicolons without affecting functionality.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25a0e41 and 8dc0e65.

📒 Files selected for processing (2)
  • docs/3.api/5.kit/11.nitro.md (1 hunks)
  • docs/3.api/5.kit/4.autoimports.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • docs/3.api/5.kit/4.autoimports.md
🧰 Additional context used
🪛 LanguageTool
docs/3.api/5.kit/11.nitro.md

[uncategorized] ~330-~330: Loose punctuation mark.
Context: ...[]): void ``` ### Parameters imports: An object or an array of objects with t...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: code
  • GitHub Check: lint-docs
🔇 Additional comments (3)
docs/3.api/5.kit/11.nitro.md (3)

296-299: Well-aligned section introduction.

The new addServerImports heading and description follow the established pattern and clearly state the feature’s purpose.


300-318: Usage example mirrors existing conventions.

The code sample correctly demonstrates single-item and array usage in a forEach loop, matching the style of addImports.


328-342: Parameters table alignment is clear.

The table accurately documents each property of the Import object(s) accepted by addServerImports.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~330-~330: Loose punctuation mark.
Context: ...[]): void ``` ### Parameters imports: An object or an array of objects with t...

(UNLIKELY_OPENING_PUNCTUATION)


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42114f4 and 25a0e41.

📒 Files selected for processing (2)
  • docs/3.api/5.kit/11.nitro.md (1 hunks)
  • packages/kit/src/nitro.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/kit/src/nitro.ts (1)
packages/kit/src/utils.ts (1)
  • toArray (2-4)
🪛 LanguageTool
docs/3.api/5.kit/11.nitro.md

[uncategorized] ~330-~330: Loose punctuation mark.
Context: ...[]): void ``` ### Parameters imports: An object or an array of objects with t...

(UNLIKELY_OPENING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-on, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, 20)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, 20)
  • GitHub Check: test-benchmark
  • GitHub Check: release-pr
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: code
  • GitHub Check: lint-docs
🔇 Additional comments (2)
packages/kit/src/nitro.ts (1)

89-97: LGTM! Implementation correctly supports single import arguments.

The function signature change and internal normalisation using toArray follows the established pattern used by other functions like addPrerenderRoutes. This maintains backward compatibility whilst enabling the desired single import functionality.

docs/3.api/5.kit/11.nitro.md (1)

296-342: Excellent documentation addition following established patterns.

The documentation is comprehensive, well-structured, and includes a practical usage example. The parameter table thoroughly describes all available import properties, which will be valuable for developers.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~330-~330: Loose punctuation mark.
Context: ...[]): void ``` ### Parameters imports: An object or an array of objects with t...

(UNLIKELY_OPENING_PUNCTUATION)

### Type

```ts
function addServerImports (dirs: Import | Import[]): void
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix parameter name inconsistency in type signature.

The function signature shows dirs as the parameter name, but it should be imports to match the actual implementation and parameter description.

-function addServerImports (dirs: Import | Import[]): void
+function addServerImports (imports: Import | Import[]): void
📝 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.

Suggested change
function addServerImports (dirs: Import | Import[]): void
function addServerImports (imports: Import | Import[]): void
🤖 Prompt for AI Agents
In docs/3.api/5.kit/11.nitro.md at line 325, rename the parameter in the
function signature from 'dirs' to 'imports' to ensure consistency with the
actual implementation and parameter description.

Copy link

pkg-pr-new bot commented Jun 4, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 51818f6

Copy link

codspeed-hq bot commented Jun 4, 2025

CodSpeed Performance Report

Merging #32289 will not alter performance

Comparing BobbieGoede:feat/add-server-imports-single-arg-and-docs (51818f6) with main (d0a61fc)

Summary

✅ 10 untouched benchmarks

@danielroe danielroe changed the title feat: support single import as argument for addServerImports feat(kit): support single import in addServerImports Jun 10, 2025
@danielroe danielroe merged commit 1927782 into nuxt:main Jun 10, 2025
49 of 50 checks passed
@github-actions github-actions bot mentioned this pull request Jun 10, 2025
@github-actions github-actions bot mentioned this pull request Jul 21, 2025
This was referenced Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants