1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-13 18:40:54 +01:00

Fixed file watching for Chokidar 4

This commit is contained in:
squidfunk 2024-10-08 12:19:15 +02:00
parent 25b2107b53
commit 2014b634e8
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
2 changed files with 13 additions and 11 deletions

1
package-lock.json generated
View File

@ -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",

View File

@ -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<string> {
return fromEvent(
chokidar.watch(pattern, options),
chokidar.watch(files, options),
"change", file => file // see https://t.ly/dli_k
) as Observable<string>
}