Skip to content

Commit 972c887

Browse files
authored
fix(cli): Compile newly created files in watch mode (#114)
Currently in watch mode, the CLI will only watch files that existed at the time the command was started. This means newly added files won't trigger a rebuild. Fixing by moving the globbing logic into the `ignored` callback instead & watching the sources in their entirety. This should address https://github.com/swc-project/swc/issues/10520
1 parent ac1ef1b commit 972c887

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

.changeset/little-spoons-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@swc/cli": patch
3+
---
4+
5+
fix(cli): Include newly added files in watch mode

packages/cli/src/swc/sources.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,17 @@ export async function watchSources(
114114
ignore: string[] = []
115115
) {
116116
const chokidar = await requireChokidar();
117-
const sourceFiles = await globSources(
118-
sources,
119-
only,
120-
ignore,
121-
includeDotfiles
122-
);
123-
return chokidar.watch(sourceFiles, {
124-
ignored: includeDotfiles
125-
? undefined
126-
: (filename: string) => basename(filename).startsWith("."),
117+
return chokidar.watch(sources, {
118+
ignored: (filename: string) => {
119+
if (!includeDotfiles && basename(filename).startsWith(".")) {
120+
return true;
121+
}
122+
if (ignore.some(ignore => minimatch(slash(filename), ignore))) {
123+
return true;
124+
}
125+
126+
return only.length > 0 && !only.some(only => minimatch(slash(filename), only));
127+
},
127128
ignoreInitial: true,
128129
awaitWriteFinish: {
129130
stabilityThreshold: 50,

pnpm-lock.yaml

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)