Skip to content

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

resolves #31298

📚 Description

we can safely not exclude node_modules from the typescript project references if there's a custom source directory (e.g. no perf cost)

@bolt-new-by-stackblitz
Copy link

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

@coderabbitai
Copy link

coderabbitai bot commented Aug 18, 2025

Walkthrough

  • Computes sourceDirs from nuxt.options._layers using withTrailingSlash(layer.config.srcDir ?? layer.cwd).
  • Changes node_modules exclusion to only exclude directories that do not start with any of the computed sourceDirs.
  • Adds a comment explaining why node_modules outside source directories are excluded.
  • In _generateTypes, updating exclude for modulesDir is now conditional while nodeExclude and legacyExclude are still updated unconditionally.
  • No exported/public API signatures were changed.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c7cb3e0 and cebfa0d.

📒 Files selected for processing (1)
  • packages/kit/test/generate-types.spec.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/kit/test/generate-types.spec.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). (17)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: test-benchmark
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/node_types

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

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

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

🧹 Nitpick comments (1)
packages/kit/src/template.ts (1)

221-221: Normalise srcDir paths before prefix checks to avoid edge-case mismatches

If any layer’s srcDir were ever relative (or differently normalised), prefix checks may fail. Minor hardening: ensure absolute, normalised paths before adding a trailing slash.

Apply this diff:

-  const sourceDirs = nuxt.options._layers.map(layer => withTrailingSlash(layer.config.srcDir ?? layer.cwd))
+  const sourceDirs = nuxt.options._layers.map((layer) => {
+    const src = layer.config.srcDir ?? layer.cwd
+    return withTrailingSlash(isAbsolute(src) ? src : resolve(layer.cwd, src))
+  })
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6ff3fbe and c7cb3e0.

📒 Files selected for processing (1)
  • packages/kit/src/template.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/kit/src/template.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). (2)
  • GitHub Check: build
  • GitHub Check: code

Comment on lines +225 to +229
// we only need to exclude node_modules directories if they are
// being included automatically by being inside the source directory
if (!sourceDirs.some(srcDir => dir.startsWith(srcDir))) {
exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Inverted condition: node_modules exclusion logic contradicts comment and PR intent

The comment says “we only need to exclude node_modules directories if they are being included automatically by being inside the source directory”, but the code excludes when they are NOT inside a source directory. This inverts the intended behaviour:

  • With a custom srcDir (node_modules outside srcDir), this still excludes node_modules — which defeats the purpose of the PR.
  • With default srcDir=rootDir (node_modules inside srcDir), this will not exclude node_modules — likely causing a large performance regression.

Flip the condition and normalise the compared paths to avoid prefix false negatives.

Apply this diff:

   // node_modules folders
   for (const dir of nuxt.options.modulesDir) {
-    // we only need to exclude node_modules directories if they are
-    // being included automatically by being inside the source directory
-    if (!sourceDirs.some(srcDir => dir.startsWith(srcDir))) {
-      exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
-    }
+    const dirWithSlash = withTrailingSlash(dir)
+    // Exclude node_modules only when they are included automatically
+    // by being inside any source directory (e.g. srcDir === rootDir).
+    if (sourceDirs.some(srcDir => dirWithSlash.startsWith(srcDir))) {
+      exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
+    }
     nodeExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
     legacyExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
   }

Follow-up:

  • Please double-check with both scenarios:
    • Default srcDir (rootDir): node_modules should be excluded.
    • Custom srcDir (e.g. /src): node_modules should not be excluded.

🏁 Script executed:

#!/bin/bash
# Show the exclusion logic around the reported lines
sed -n '220,240p' packages/kit/src/template.ts

# Locate where sourceDirs is defined
rg -n 'const sourceDirs' -t ts -C3 packages/kit/src/template.ts

Length of output: 1517


Reverse node_modules exclusion to align with comment and PR intent

The current logic in packages/kit/src/template.ts (around lines 223–228) uses if (!sourceDirs.some(...)), which excludes modules outside your source directories and leaves those inside—exactly the opposite of what the comment and intended behaviour describe. We need to:

• Flip the condition so that we only exclude node_modules when they are within a source directory.
• Normalise both paths with withTrailingSlash to avoid prefix collisions.

Apply this diff:

   // node_modules folders
   for (const dir of nuxt.options.modulesDir) {
-    // we only need to exclude node_modules directories if they are
-    // being included automatically by being inside the source directory
-    if (!sourceDirs.some(srcDir => dir.startsWith(srcDir))) {
-      exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
-    }
+    const dirWithSlash = withTrailingSlash(dir)
+    // Exclude node_modules only when they are included automatically
+    // by being inside any source directory (e.g. srcDir === rootDir).
+    if (sourceDirs.some(srcDir => dirWithSlash.startsWith(srcDir))) {
+      exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
+    }
     nodeExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
     legacyExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
   }

Please verify both scenarios after this change:

  • Default srcDir (rootDir): node_modules should now be excluded.
  • Custom srcDir (e.g. <root>/src): node_modules should not be excluded.
📝 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
// we only need to exclude node_modules directories if they are
// being included automatically by being inside the source directory
if (!sourceDirs.some(srcDir => dir.startsWith(srcDir))) {
exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
}
// node_modules folders
for (const dir of nuxt.options.modulesDir) {
const dirWithSlash = withTrailingSlash(dir)
// Exclude node_modules only when they are included automatically
// by being inside any source directory (e.g. srcDir === rootDir).
if (sourceDirs.some(srcDir => dirWithSlash.startsWith(srcDir))) {
exclude.add(relativeWithDot(nuxt.options.buildDir, dir))
}
nodeExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
legacyExclude.add(relativeWithDot(nuxt.options.buildDir, dir))
}
🤖 Prompt for AI Agents
In packages/kit/src/template.ts around lines 225 to 229, the condition for
excluding node_modules is inverted relative to the comment and intent; change
the predicate to exclude node_modules only when the node_modules path is inside
one of the source directories (i.e. flip the ! to remove the negation), and
normalize both srcDir and dir with withTrailingSlash (or equivalent) before
comparing to avoid prefix collisions; update the exclude.add call to use
relativeWithDot as before and verify that with default srcDir (rootDir)
node_modules is excluded and with a custom srcDir (e.g. <root>/src) node_modules
inside root is not excluded.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 18, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: cebfa0d

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 18, 2025

CodSpeed Performance Report

Merging #32987 will not alter performance

Comparing fix/node_types (cebfa0d) with main (17ef50b)1

Summary

✅ 10 untouched benchmarks

Footnotes

  1. No successful run was found on main (6ff3fbe) during the generation of this report, so 17ef50b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@danielroe danielroe merged commit 1c0251b into main Aug 18, 2025
46 checks passed
@danielroe danielroe deleted the fix/node_types branch August 18, 2025 17:28
@github-actions github-actions bot mentioned this pull request Aug 18, 2025
danielroe added a commit that referenced this pull request Sep 2, 2025
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request 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.

Layer aliases not resolving, when it is installed as dependency

2 participants