@@ -33,16 +33,30 @@ class ESLintWebpackPlugin {
33
33
// this differentiates one from the other when being cached.
34
34
this . key = compiler . name || `${ this . key } _${ ( counter += 1 ) } ` ;
35
35
36
+ const options = {
37
+ ...this . options ,
38
+ exclude : parseFiles (
39
+ this . options . exclude || [ ] ,
40
+ this . getContext ( compiler )
41
+ ) ,
42
+ extensions : arrify ( this . options . extensions ) ,
43
+ files : parseFiles ( this . options . files || '' , this . getContext ( compiler ) ) ,
44
+ } ;
45
+
46
+ const wanted = parseFoldersToGlobs ( options . files , options . extensions ) ;
47
+ const exclude = parseFoldersToGlobs (
48
+ this . options . exclude ? options . exclude : '**/node_modules/**' ,
49
+ [ ]
50
+ ) ;
51
+
36
52
// If `lintDirtyModulesOnly` is disabled,
37
53
// execute the linter on the build
38
54
if ( ! this . options . lintDirtyModulesOnly ) {
39
- compiler . hooks . run . tapPromise ( this . key , this . run ) ;
55
+ compiler . hooks . run . tapPromise ( this . key , ( c ) =>
56
+ this . run ( c , options , wanted , exclude )
57
+ ) ;
40
58
}
41
59
42
- // TODO: Figure out want `compiler.watching` is and how to use it in Webpack5.
43
- // From my testing of compiler.watch() ... compiler.watching is always
44
- // undefined (webpack 4 doesn't define it either) I'm leaving it out
45
- // for now.
46
60
let isFirstRun = this . options . lintDirtyModulesOnly ;
47
61
compiler . hooks . watchRun . tapPromise ( this . key , ( c ) => {
48
62
if ( isFirstRun ) {
@@ -51,39 +65,26 @@ class ESLintWebpackPlugin {
51
65
return Promise . resolve ( ) ;
52
66
}
53
67
54
- return this . run ( c ) ;
68
+ return this . run ( c , options , wanted , exclude ) ;
55
69
} ) ;
56
70
}
57
71
58
72
/**
59
73
* @param {Compiler } compiler
74
+ * @param {Options } options
75
+ * @param {string[] } wanted
76
+ * @param {string[] } exclude
60
77
*/
61
- async run ( compiler ) {
78
+ async run ( compiler , options , wanted , exclude ) {
62
79
// Do not re-hook
63
80
if (
64
81
// @ts -ignore
65
- compiler . hooks . compilation . taps . find ( ( { name } ) => name === this . key )
82
+ compiler . hooks . thisCompilation . taps . find ( ( { name } ) => name === this . key )
66
83
) {
67
84
return ;
68
85
}
69
86
70
- const options = {
71
- ...this . options ,
72
- exclude : parseFiles (
73
- this . options . exclude || [ ] ,
74
- this . getContext ( compiler )
75
- ) ,
76
- extensions : arrify ( this . options . extensions ) ,
77
- files : parseFiles ( this . options . files || '' , this . getContext ( compiler ) ) ,
78
- } ;
79
-
80
- const wanted = parseFoldersToGlobs ( options . files , options . extensions ) ;
81
- const exclude = parseFoldersToGlobs (
82
- this . options . exclude ? options . exclude : '**/node_modules/**' ,
83
- [ ]
84
- ) ;
85
-
86
- compiler . hooks . compilation . tap ( this . key , ( compilation ) => {
87
+ compiler . hooks . thisCompilation . tap ( this . key , ( compilation ) => {
87
88
/** @type {import('./linter').Linter } */
88
89
let lint ;
89
90
/** @type {import('./linter').Reporter } */
0 commit comments