fix(swc): correct inverted ignored filter in watchFilesInSrcDir#3324
Open
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
Open
fix(swc): correct inverted ignored filter in watchFilesInSrcDir#3324yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
Conversation
The chokidar ignored callback in watchFilesInSrcDir was incorrectly filtering out files that matched the expected extensions (e.g., .ts) instead of filtering out files that did not match. This meant that newly added source files in watch mode could be missed by the watcher. Additionally, the extension comparison was inconsistent: swc-defaults provides extensions with dot prefixes (['.js', '.ts']) while the code stripped the dot via path.extname().slice(1), causing a format mismatch. This fix: - Inverts the ignored logic (adds !) to match watchFilesInOutDir pattern - Normalizes extensions to always use dot-prefixed format - Uses path.extname() directly without stripping the dot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
The
watchFilesInSrcDirmethod in the SWC compiler has an invertedignoredfilter in its chokidar watcher. The current logic ignores files whose extensions match the expected source extensions (e.g.,.ts,.js), which is the opposite of the intended behavior. It should ignore files that do not match.Additionally, there is an extension format inconsistency:
swc-defaults.tsprovides extensions with dot prefixes (['.js', '.ts']), but theignoredcallback strips the dot viapath.extname(file).slice(1), causing.tsto never match'.ts'. This mismatch accidentally prevents the inverted filter from causing harm with the default config, but the fallback default['ts'](without dots) would incorrectly ignore.tsfiles.For comparison, the sibling method
watchFilesInOutDircorrectly uses!negation in its ignored filter.What is the new behavior?
ignoredcallback now uses!extensions.includes(...)to ignore files that do not match the expected extensions (consistent withwatchFilesInOutDir)'ts'→'.ts')path.extname()is used directly without.slice(1), so comparisons are consistentThis ensures that in SWC watch mode, newly added source files (
.ts,.js) are properly detected and compiled, while non-source files (.json,.md, etc.) are correctly ignored.Additional context
Added 5 unit tests for
watchFilesInSrcDircovering:.ts,.js)ts,js)All existing tests continue to pass (20/20).