From 2014b634e88bc8c035d06558f46b607a328b7012 Mon Sep 17 00:00:00 2001 From: squidfunk Date: Tue, 8 Oct 2024 12:19:15 +0200 Subject: [PATCH] Fixed file watching for Chokidar 4 --- package-lock.json | 1 + tools/build/_/index.ts | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 97a722af54c..0fe28ebd6cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3228,6 +3228,7 @@ "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", diff --git a/tools/build/_/index.ts b/tools/build/_/index.ts index 535ccce3ea0..22a644794ae 100644 --- a/tools/build/_/index.ts +++ b/tools/build/_/index.ts @@ -25,7 +25,6 @@ import * as fs from "fs/promises" import { EMPTY, Observable, - concatAll, filter, from, fromEvent, @@ -35,6 +34,7 @@ import { map, mergeWith, of, + switchMap, tap } from "rxjs" import glob from "tiny-glob" @@ -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 { return fromEvent( - chokidar.watch(pattern, options), + chokidar.watch(files, options), "change", file => file // see https://t.ly/dli_k ) as Observable }