Skip to content

Commit a3890cb

Browse files
committed
fix(swc): fix inverted chokidar ignored filter in watch mode
The ignored callback in watchFilesInSrcDir had two layered bugs: 1. Extension format mismatch: the extensions array contains dotted extensions (.ts) but the comparison stripped the dot, so the filter never matched any files. 2. Inverted logic: the filter ignored files that matched source extensions instead of ignoring files that don't match. The net effect was that all files in the source directory triggered the watcher, causing unnecessary recompilation for non-source files like .json, .css, or .env. Fix by using file.endsWith(ext) for robust matching and negating the condition to properly ignore non-source files.
1 parent be77cf3 commit a3890cb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/compiler/swc/swc-compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ export class SwcCompiler extends BaseCompiler {
276276
// or any other specified directory
277277
return;
278278
}
279-
const extensions = options.cliOptions?.extensions ?? ['ts'];
279+
const extensions = options.cliOptions?.extensions ?? ['.ts'];
280280
const watcher = chokidar.watch(srcDir, {
281281
ignored: (file, stats) =>
282282
(stats?.isFile() &&
283-
extensions.includes(path.extname(file).slice(1))) as boolean,
283+
!extensions.some((ext) => file.endsWith(ext))) as boolean,
284284
ignoreInitial: true,
285285
awaitWriteFinish: {
286286
stabilityThreshold: 50,

0 commit comments

Comments
 (0)