Skip to content

Commit

Permalink
Fixed file watching for Chokidar 4
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Oct 8, 2024
1 parent 25b2107 commit 2014b63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions tools/build/_/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import * as fs from "fs/promises"
import {
EMPTY,
Observable,
concatAll,
filter,
from,
fromEvent,
Expand All @@ -35,6 +34,7 @@ import {
map,
mergeWith,
of,
switchMap,
tap
} from "rxjs"
import glob from "tiny-glob"
Expand Down Expand Up @@ -110,33 +110,34 @@ export function resolve(
return from(glob(pattern, { dot: true, ...options }))
.pipe(
catchError(() => EMPTY),
concatAll(),
switchMap(files => from(files).pipe(

/* Start file watcher */
options?.watch
? mergeWith(watch(files, options))
: identity
)),

/* Build overrides */
!process.argv.includes("--all")
? filter(file => !file.startsWith(".overrides/"))
: identity,

/* Start file watcher */
options?.watch
? mergeWith(watch(pattern, options))
: identity
)
}

/**
* Watch all files matching the given pattern
* Watch all given files
*
* @param pattern - Pattern
* @param files - Files
* @param options - Options
*
* @returns File observable
*/
export function watch(
pattern: string, options: WatchOptions
files: string[], options: WatchOptions
): Observable<string> {
return fromEvent(
chokidar.watch(pattern, options),
chokidar.watch(files, options),
"change", file => file // see https://t.ly/dli_k
) as Observable<string>
}
Expand Down

0 comments on commit 2014b63

Please sign in to comment.