@@ -41,10 +41,29 @@ class StylelintWebpackPlugin {
41
41
// this differentiates one from the other when being cached.
42
42
this . key = compiler . name || `${ this . key } _${ ( counter += 1 ) } ` ;
43
43
44
+ const context = this . getContext ( compiler ) ;
45
+ const excludeDefault = [
46
+ '**/node_modules/**' ,
47
+ String ( compiler . options . output . path ) ,
48
+ ] ;
49
+
50
+ const options = {
51
+ ...this . options ,
52
+ context,
53
+ exclude : parseFiles ( this . options . exclude || excludeDefault , context ) ,
54
+ extensions : arrify ( this . options . extensions ) ,
55
+ files : parseFiles ( this . options . files || '' , context ) ,
56
+ } ;
57
+
58
+ const wanted = parseFoldersToGlobs ( options . files , options . extensions ) ;
59
+ const exclude = parseFoldersToGlobs ( options . exclude ) ;
60
+
44
61
// If `lintDirtyModulesOnly` is disabled,
45
62
// execute the linter on the build
46
63
if ( ! this . options . lintDirtyModulesOnly ) {
47
- compiler . hooks . run . tapPromise ( this . key , this . run ) ;
64
+ compiler . hooks . run . tapPromise ( this . key , ( c ) =>
65
+ this . run ( c , options , wanted , exclude )
66
+ ) ;
48
67
}
49
68
50
69
let isFirstRun = this . options . lintDirtyModulesOnly ;
@@ -55,14 +74,17 @@ class StylelintWebpackPlugin {
55
74
return Promise . resolve ( ) ;
56
75
}
57
76
58
- return this . run ( c ) ;
77
+ return this . run ( c , options , wanted , exclude ) ;
59
78
} ) ;
60
79
}
61
80
62
81
/**
63
82
* @param {Compiler } compiler
83
+ * @param {Options } options
84
+ * @param {string[] } wanted
85
+ * @param {string[] } exclude
64
86
*/
65
- async run ( compiler ) {
87
+ async run ( compiler , options , wanted , exclude ) {
66
88
// Do not re-hook
67
89
/* istanbul ignore if */
68
90
if (
@@ -72,23 +94,6 @@ class StylelintWebpackPlugin {
72
94
return ;
73
95
}
74
96
75
- const context = this . getContext ( compiler ) ;
76
- const options = {
77
- ...this . options ,
78
- exclude : parseFiles (
79
- this . options . exclude || [
80
- '**/node_modules/**' ,
81
- compiler . options . output . path ,
82
- ] ,
83
- context
84
- ) ,
85
- extensions : arrify ( this . options . extensions ) ,
86
- files : parseFiles ( this . options . files || '' , context ) ,
87
- } ;
88
-
89
- const wanted = parseFoldersToGlobs ( options . files , options . extensions ) ;
90
- const exclude = parseFoldersToGlobs ( options . exclude ) ;
91
-
92
97
compiler . hooks . thisCompilation . tap ( this . key , ( compilation ) => {
93
98
/** @type {import('./linter').Linter } */
94
99
let lint ;
@@ -109,10 +114,10 @@ class StylelintWebpackPlugin {
109
114
110
115
if ( threads > 1 ) {
111
116
for ( const file of files ) {
112
- lint ( parseFiles ( file , context ) ) ;
117
+ lint ( parseFiles ( file , options . context || '' ) ) ;
113
118
}
114
119
} else if ( files . length > 0 ) {
115
- lint ( parseFiles ( files , context ) ) ;
120
+ lint ( parseFiles ( files , options . context || '' ) ) ;
116
121
}
117
122
} ) ;
118
123
0 commit comments