fix(fs-watcher) ignore node_modules on windows (#31341)

Partially fixes https://github.com/microsoft/playwright/issues/31337 by
supporting ignoring node_modules on windows.

When I debug the function it gets a unix style path filename on windows,
so the function never ignores node_modules. The ignore path globs are
expected to use the unix path seperator and I've tested this fix works
on windows and I assume that since mac uses unix style, it also works
there (this is a pretty standard glob construct (chokidar points at any
match https://github.com/micromatch/anymatch and anymatch has this exact
example in their readme.md)

Signed-off-by: Luke Page <137174537+lukpsaxo@users.noreply.github.com>
This commit is contained in:
Luke Page 2024-06-19 20:14:10 +02:00 committed by GitHub
parent 82a44f28e2
commit 94f0cadea3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -16,7 +16,6 @@
import { chokidar } from './utilsBundle';
import type { FSWatcher } from 'chokidar';
import path from 'path';
export type FSEvent = { event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', file: string };
@ -52,7 +51,7 @@ export class Watcher {
if (!this._watchedFiles.length)
return;
const ignored = [...this._ignoredFolders, (name: string) => name.includes(path.sep + 'node_modules' + path.sep)];
const ignored = [...this._ignoredFolders, '**/node_modules/**'];
this._fsWatcher = chokidar.watch(watchedFiles, { ignoreInitial: true, ignored }).on('all', async (event, file) => {
if (this._throttleTimer)
clearTimeout(this._throttleTimer);