mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
switch out chokidar for @parcel/watcher in dev cli (#148924)
After the recent changes to limit the dev-cli watcher to relevant packages, the watcher started logging tons of unnecessary changes, and in some cases breaking based on the state of the repo. I have seen this happen with Chokidar before, and I'm not convinced we'll be able to fix it, so instead I decided to swap it out with `@parcel/watcher`, which is a conceptually simpler implementation that automatically batches changes and watches an entire directory, rather than tons of unique directories/files. This new implementation is conceptually simpler, and because of the design of the `@parcel/watcher` module I was pushed to reuse the `RepoSourceClassifier` to determine if we should restart the server based on a specific change. This means we now have a single source of truth for test files and the like (the classifier will tell us if a file is a test file, regardless of where it exists in the repo). Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
a94a1b620e
commit
99013bdab8
14 changed files with 107 additions and 538 deletions
|
@ -16,4 +16,6 @@ export interface ModuleId {
|
|||
repoRel: string;
|
||||
/** info about the package the source file is within, in the case the file is found within a package */
|
||||
pkgInfo?: PkgInfo;
|
||||
/** path segments of the dirname of this */
|
||||
dirs: string[];
|
||||
}
|
||||
|
|
|
@ -60,10 +60,12 @@ export class RepoPath {
|
|||
}
|
||||
|
||||
private segs: string[] | undefined;
|
||||
/** get and cache the path segments from the repo-realtive versions of this path */
|
||||
/** get and cache the path segments from the repo-realtive dirname of this path */
|
||||
getSegs() {
|
||||
if (this.segs === undefined) {
|
||||
this.segs = Path.dirname(this.getRepoRel()).split('/');
|
||||
this.segs = Path.dirname(this.getRepoRel())
|
||||
.split('/')
|
||||
.filter((s) => s !== '.');
|
||||
}
|
||||
|
||||
return this.segs;
|
||||
|
|
|
@ -12,6 +12,10 @@ import { ModuleType } from './module_type';
|
|||
import { RANDOM_TEST_FILE_NAMES, TEST_DIR, TEST_TAG } from './config';
|
||||
import { RepoPath } from './repo_path';
|
||||
|
||||
const STATIC_EXTS = new Set(
|
||||
'json|woff|woff2|ttf|eot|svg|ico|png|jpg|gif|jpeg|html|md|txt|tmpl'.split('|').map((e) => `.${e}`)
|
||||
);
|
||||
|
||||
export class RepoSourceClassifier {
|
||||
constructor(private readonly resolver: ImportResolver) {}
|
||||
|
||||
|
@ -124,7 +128,7 @@ export class RepoSourceClassifier {
|
|||
* Determine the "type" of a file
|
||||
*/
|
||||
private getType(path: RepoPath): ModuleType {
|
||||
if (path.getExtname() === '.json') {
|
||||
if (STATIC_EXTS.has(path.getExtname())) {
|
||||
return 'static';
|
||||
}
|
||||
|
||||
|
@ -214,6 +218,7 @@ export class RepoSourceClassifier {
|
|||
type: this.getType(path),
|
||||
repoRel: path.getRepoRel(),
|
||||
pkgInfo: path.getPkgInfo() ?? undefined,
|
||||
dirs: path.getSegs(),
|
||||
};
|
||||
this.ids.set(path, id);
|
||||
return id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue