Skip to content

fix(kit,nuxt,schema,vite): improve watching behaviour #30620

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

Merged
merged 10 commits into from
Jan 16, 2025
Merged

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Jan 15, 2025

🔗 Linked issue

vitejs/vite#8619, resolves #30459, resolves #30023

📚 Description

this bundles a range of fixes to watchers in Nuxt:

  1. create new createIsIgnored function that binds a Nuxt instance to an isIgnored handler - otherwise when restarting Nuxt, we could sometimes end up watching more files than expected
  2. correctly types watchers.chokidar
  3. sets the chokidar ignorePermissionErrors to true by default
  4. passes watchers.chokidar to vite's two watcher configs (server.watch and build.watch)
  5. move from glob ignore patterns (no longer supported in chokidar v4) to regexps

🚧 TODO

  • check actual metrics on linux, windows, macos to see whether this makes a positive difference

@danielroe danielroe requested a review from antfu January 15, 2025 23:22
@danielroe danielroe self-assigned this Jan 15, 2025
Copy link

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

Copy link

pkg-pr-new bot commented Jan 15, 2025

Open in Stackblitz

@nuxt/kit

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

@nuxt/rspack-builder

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

nuxt

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 0b6b172

@antfu
Copy link
Member

antfu commented Jan 16, 2025

Oh, nice catch! The changes LGTM

@danielroe
Copy link
Member Author

danielroe commented Jan 16, 2025

checked on windows, and it seems this removes the need for chokidar-granular preset 🚀

(it didn't make much difference vs chokidar-granular, but without it improved it (23s -> 4s start time in the basic fixture in playground)

@danielroe danielroe marked this pull request as ready for review January 16, 2025 13:54
Copy link

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request introduces a new function createIsIgnored in the Nuxt kit package, which provides a more flexible approach to handling file and path ignoring across various Nuxt modules. The changes span multiple packages, including kit, nuxt, schema, and vite, and focus on enhancing the file watching and import scanning mechanisms.

The primary modification involves updating the isIgnored function to accept an optional Nuxt context and introducing a new createIsIgnored function that generates an ignore checker. This change allows for more dynamic and context-aware file ignoring, particularly in scenarios like component transformation, import scanning, and file watching.

The implementation affects several core Nuxt processes, including build watchers, import regeneration, and Vite configuration, providing a more consistent and flexible approach to determining which files should be excluded from various operations.


📜 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 815b1b2 and 0b6b172.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (1)
  • packages/nuxt/src/core/schema.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nuxt/src/core/schema.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: code

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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: 0

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

13-13: Consider documenting the unused _stats parameter.

The _stats parameter is currently unused but might be intended for future use. Adding a comment explaining its purpose would improve code clarity.

packages/nuxt/src/core/builder.ts (1)

141-141: Consider extracting the node_modules regex pattern.

Since the regex pattern /[\\/]node_modules[\\/]/ is used in multiple places, consider extracting it into a constant to maintain DRY principles and ensure consistency.

+const NODE_MODULES_RE = /[\\/]node_modules[\\/]/
+
 function createGranularWatcher () {
   // ...
-    const watcher = chokidarWatch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored, /[\\/]node_modules[\\/]/] })
+    const watcher = chokidarWatch(dir, { ...nuxt.options.watchers.chokidar, ignoreInitial: false, depth: 0, ignored: [isIgnored, NODE_MODULES_RE] })
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 16d213b and 815b1b2.

⛔ Files ignored due to path filters (2)
  • packages/schema/package.json is excluded by !**/package.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (10)
  • packages/kit/src/ignore.ts (1 hunks)
  • packages/kit/src/index.ts (1 hunks)
  • packages/nuxt/src/components/plugins/transform.ts (1 hunks)
  • packages/nuxt/src/core/builder.ts (4 hunks)
  • packages/nuxt/src/core/cache.ts (2 hunks)
  • packages/nuxt/src/core/schema.ts (2 hunks)
  • packages/nuxt/src/imports/module.ts (2 hunks)
  • packages/schema/build.config.ts (1 hunks)
  • packages/schema/src/config/common.ts (1 hunks)
  • packages/vite/src/vite.ts (4 hunks)
🔇 Additional comments (12)
packages/schema/build.config.ts (1)

31-31: LGTM! Addition of chokidar as an external dependency.

The addition aligns with the PR's objective of improving watching behaviour.

packages/kit/src/index.ts (1)

22-22: LGTM! Export of new createIsIgnored function.

The export is properly grouped with related ignore functions and maintains alphabetical ordering.

packages/kit/src/ignore.ts (1)

6-8: LGTM! Well-designed factory function for creating bound ignore checkers.

The implementation follows the factory pattern, allowing for efficient reuse of the nuxt context.

packages/nuxt/src/components/plugins/transform.ts (1)

61-61: LGTM! Proper usage of modified isIgnored function.

The change correctly adapts to the new isIgnored signature by explicitly passing the nuxt instance.

packages/nuxt/src/core/schema.ts (1)

74-77: Improved watcher configuration with proper context and patterns

The watcher configuration has been enhanced to:

  1. Use context-aware ignore patterns via createIsIgnored(nuxt)
  2. Properly ignore node_modules directory
  3. Preserve existing chokidar options
packages/nuxt/src/imports/module.ts (1)

121-121: Enhanced import scanning with context-aware ignore patterns

The change improves the accuracy of import scanning by using createIsIgnored(nuxt), ensuring consistent ignore patterns across the application.

packages/nuxt/src/core/cache.ts (1)

122-122: Improved cache handling with context-aware ignore patterns

The change enhances cache handling by using createIsIgnored(nuxt), ensuring consistent file filtering across the application.

packages/vite/src/vite.ts (1)

56-56: Enhanced Vite watcher configuration with proper context and patterns

The changes improve Vite integration by:

  1. Using context-aware ignore patterns via createIsIgnored(nuxt)
  2. Properly configuring both build and server watchers
  3. Maintaining consistency with Nuxt's watcher configuration
  4. Preserving existing chokidar options

Also applies to: 92-92, 106-106

packages/schema/src/config/common.ts (1)

522-526: Excellent enhancement to watcher configuration!

The changes improve the robustness of file watching in two ways:

  1. Added type annotation ensures proper TypeScript validation of chokidar options
  2. Setting ignorePermissionErrors: true by default prevents watcher failures when encountering permission-related issues, which is particularly helpful in environments with complex file permissions
packages/nuxt/src/core/builder.ts (3)

4-4: LGTM: Import statement updated correctly.

The addition of createIsIgnored import aligns with the new approach to handling ignored paths.


103-103: Improved file watching configuration in createWatcher.

The changes enhance the file watching configuration by:

  1. Using createIsIgnored for dynamic path ignoring
  2. Replacing glob pattern with regex /[\\/]node_modules[\\/]/ for better cross-platform compatibility

Also applies to: 108-108


122-122: Consistent implementation in createGranularWatcher.

The same improvements have been correctly applied to the granular watcher:

  1. Using createIsIgnored for dynamic path ignoring
  2. Using the same regex pattern for node_modules
  3. Maintaining consistency with the main watcher implementation

Also applies to: 141-141

@danielroe danielroe merged commit bc669cb into main Jan 16, 2025
47 checks passed
@danielroe danielroe deleted the fix/watch branch January 16, 2025 15:02
@github-actions github-actions bot mentioned this pull request Jan 16, 2025
@github-actions github-actions bot mentioned this pull request Jan 17, 2025
Kamsou pushed a commit to Kamsou/nuxt that referenced this pull request Feb 5, 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.

Ignoring certain folders seems not to work watcher scans all files in root directory
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy