Skip to content

Commit 8c83a1f

Browse files
committed
perf: parse patterns to globs only on startup
Refactor to parse patterns only on startup instead of parsing them to globs on each run. In watch mode Webpack does not watch it's own configuration so the plugin configuration does not change when Webpack is running. Because the file patterns and extensions do not change there is no need to process them into globs separately for each run.
1 parent ecb06be commit 8c83a1f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/DirtyFileWatcher.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { isMatch } from 'micromatch';
44

55
export default class DirtyFileWatcher {
66
constructor({ files = [], extensions = ['js'] }) {
7-
this.patterns = files;
8-
this.extensions = extensions;
97
this.startTime = Date.now();
108
this.prevTimestamps = {};
119
this.isFirstRun = true;
10+
11+
const unixPatterns = files.map((pattern) => {
12+
return pattern.replace(/\\/gu, '/');
13+
});
14+
this.globs = parseFoldersToGlobs(unixPatterns, extensions);
1215
}
1316

1417
getDirtyFiles({ fileTimestamps = new Map() }) {
@@ -17,15 +20,11 @@ export default class DirtyFileWatcher {
1720
this.prevTimestamps = fileTimestamps;
1821
return [];
1922
}
20-
if (this.patterns.length <= 0 || fileTimestamps.length <= 0) {
23+
if (this.globs.length <= 0 || fileTimestamps.length <= 0) {
2124
return [];
2225
}
2326

24-
const unixPatterns = this.patterns.map((pattern) => {
25-
return pattern.replace(/\\/gu, '/');
26-
});
27-
const globs = parseFoldersToGlobs(unixPatterns, this.extensions);
28-
const changedFiles = this.filterChangedFiles(fileTimestamps, globs);
27+
const changedFiles = this.filterChangedFiles(fileTimestamps, this.globs);
2928

3029
this.prevTimestamps = fileTimestamps;
3130

0 commit comments

Comments
 (0)