1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-27 17:00: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", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz",
"integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.stat": "^2.0.2",
"@nodelib/fs.walk": "^1.2.3", "@nodelib/fs.walk": "^1.2.3",

View File

@ -25,7 +25,6 @@ import * as fs from "fs/promises"
import { import {
EMPTY, EMPTY,
Observable, Observable,
concatAll,
filter, filter,
from, from,
fromEvent, fromEvent,
@ -35,6 +34,7 @@ import {
map, map,
mergeWith, mergeWith,
of, of,
switchMap,
tap tap
} from "rxjs" } from "rxjs"
import glob from "tiny-glob" import glob from "tiny-glob"
@ -110,33 +110,34 @@ export function resolve(
return from(glob(pattern, { dot: true, ...options })) return from(glob(pattern, { dot: true, ...options }))
.pipe( .pipe(
catchError(() => EMPTY), catchError(() => EMPTY),
concatAll(), switchMap(files => from(files).pipe(
/* Start file watcher */
options?.watch
? mergeWith(watch(files, options))
: identity
)),
/* Build overrides */ /* Build overrides */
!process.argv.includes("--all") !process.argv.includes("--all")
? filter(file => !file.startsWith(".overrides/")) ? filter(file => !file.startsWith(".overrides/"))
: identity, : 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 * @param options - Options
* *
* @returns File observable * @returns File observable
*/ */
export function watch( export function watch(
pattern: string, options: WatchOptions files: string[], options: WatchOptions
): Observable<string> { ): Observable<string> {
return fromEvent( return fromEvent(
chokidar.watch(pattern, options), chokidar.watch(files, options),
"change", file => file // see https://t.ly/dli_k "change", file => file // see https://t.ly/dli_k
) as Observable<string> ) as Observable<string>
} }