Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Listen for file changes in watch mode in longest common directory
Prior to dotansimha#9009, which moved from Chokidar to `@parcel/watcher`, the behavior was to watch for all relevant files. However, since switching to `@parcel/watcher`, the new behavior has been to watch all files below `process.cwd()`, and then filter the change events for only the relevant files. This approach works fine, except that it's possible for a valid config to reference paths outside of the current working directory (e.g. `documents: "../some-other/*.graphql`), and these paths are included in build mode, but were not being included in watch mode because they're outside of `process.cwd()`. This commit adds logic, after parsing all relevant file paths, to find the "longest common directory prefix" of all those file paths, i.e. the "highest" (closest to `/`) directory that contains all the relevant file paths. Then, when subscribing to the Parcel watcher, this directory is used instead of `process.cwd()`. For example, the longest common directory of the paths `/foo/bar/*.graphql` and `/foo/fizz/*.graphql` would be `/foo`. Note that the filtering behavior is left unchanged, and this only affects the root path given to the Parcel watcher. When an event is received, the filtering can still filter out irrelevant paths, including those filtered by `config.watchPattern` if it's defined.
- Loading branch information