fix(cli): pass ignore option to chokidar watcher to prevent watching ignored files#17878
fix(cli): pass ignore option to chokidar watcher to prevent watching ignored files#17878sudip-kumar-prasad wants to merge 11 commits intobabel:mainfrom
Conversation
Fixes babel#9565 by passing the parsed babel ignore options to chokidar's ignored configuration, preventing system limit errors for wide ignore scopes like node_modules.
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61285 |
There was a problem hiding this comment.
Pull request overview
This PR aims to fix @babel/cli --watch watching files that Babel is configured to ignore (e.g. node_modules), reducing the risk of ENOSPC “too many file watchers” errors by passing ignore patterns down to chokidar.
Changes:
- Extend
watcher.enableto accept anignorelist. - Pass
babelOptions.ignoreinto the chokidar watcher options (ignored) for both file and directory watch modes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/babel-cli/src/babel/watcher.ts | Adds ignore parameter to enable and forwards it to chokidar’s ignored option. |
| packages/babel-cli/src/babel/file.ts | Passes babelOptions.ignore into watcher setup for --watch on file inputs. |
| packages/babel-cli/src/babel/dir.ts | Passes babelOptions.ignore into watcher setup for --watch on directory inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
commit: |
|
Hi 👋 just following up on this PR. All checks are passing, and I’ve addressed the review feedback. Thanks! |
JLHwung
left a comment
There was a problem hiding this comment.
Prior to 7.0, Babel-core uses micromatch to handle the ignore option. With #8327, we migrated to a much simpler match patterns.
The chokida 3.4 depended by Babel-cli also implements its own match item: https://github.com/paulmillr/chokidar/blob/c6d772a92f30004fdc437d00ecd54fbed041f30e/src/index.ts#L53.
Could you analyzes any discrepancies between these two and ensure that passing through the ignore option must not lead to uncompiled files? It is acceptable if a file ignored by Babel-core is accepted by chokidar, but it is not acceptable if a compilable file is ignored by chokidar due to different ignore interpretation.
Out of curiosity, did you use LLM to assist opening this PR?
|
Thanks for the detailed feedback! I’ve updated the implementation to rely on This ensures that chokidar only ignores files when Babel itself would ignore them (i.e., when it returns I’ve also added a small safety fallback so config errors don’t break the watcher. Regarding your question — yes, I did use AI to assist while working on this, but I verified the changes manually. Let me know if you’d like me to adjust anything further |
|
Hi, just a quick follow-up on this. Please let me know if anything else needs adjustment. Thanks! |
|
I've optimized the watcher by implementing a result cache for the ignored callback. This ensuring loadPartialConfigSync is called only once per unique path during the initial scan/watch session, significantly reducing the overhead on large projects while maintaining full parity with Babel's ignore logic. |
|
Thanks again for the detailed review! I took a deeper look into the potential differences between Babel’s ignore handling and chokidar’s pattern matching. To avoid any discrepancies, the watcher now relies on Additionally:
This way, we maintain correctness while still reducing unnecessary file watching. Let me know if you’d like me to add tests specifically covering edge cases around ignore behavior. |
…e to support showIgnoredFiles
…-cli-watcher-ignore # Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
Rename .babelrc to babel-config.json and move it into in-files/ since the test uses --config-file (project-wide config), not file-relative .babelrc configuration. This aligns the test name and config file with what is actually being tested.
FFixes #9565 by passing the parsed babel ignore options to chokidar's ignored configuration, preventing system limit errors for wide ignore scopes like
node_modules.Currently, when
@babel/cliis run with the--watchflag,chokidaris initialized without knowing which files Babel is configured to ignore. This causes it to unnecessarily track large directories (such asnode_modules), potentially leading toENOSPCfile watcher limit errors. This PR ensures thatbabelOptions.ignoreis properly propagated down tochokidar'signoredarray.