File tree Expand file tree Collapse file tree 3 files changed +64
-4
lines changed Expand file tree Collapse file tree 3 files changed +64
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ const linter = require('./linter');
7
7
const { arrify, parseFiles, parseFoldersToGlobs } = require ( './utils' ) ;
8
8
9
9
/** @typedef {import('webpack').Compiler } Compiler */
10
+ /** @typedef {import('webpack').Module } Module */
11
+ /** @typedef {import('webpack').NormalModule } NormalModule */
10
12
/** @typedef {import('./options').Options } Options */
11
13
12
14
const ESLINT_PLUGIN = 'ESLintWebpackPlugin' ;
@@ -108,9 +110,16 @@ class ESLintWebpackPlugin {
108
110
/** @type {string[] } */
109
111
const files = [ ] ;
110
112
111
- // @ts -ignore
112
113
// Add the file to be linted
113
- compilation . hooks . succeedModule . tap ( this . key , ( { resource } ) => {
114
+ compilation . hooks . succeedModule . tap ( this . key , addFile ) ;
115
+ compilation . hooks . stillValidModule . tap ( this . key , addFile ) ;
116
+
117
+ /**
118
+ * @param {Module } module
119
+ */
120
+ function addFile ( module ) {
121
+ const { resource } = /** @type {NormalModule } */ ( module ) ;
122
+
114
123
if ( ! resource ) return ;
115
124
116
125
const [ file , query ] = resource . split ( '?' ) ;
@@ -127,7 +136,7 @@ class ESLintWebpackPlugin {
127
136
128
137
if ( threads > 1 ) lint ( file ) ;
129
138
}
130
- } ) ;
139
+ }
131
140
132
141
// Lint all files added
133
142
compilation . hooks . finishModules . tap ( this . key , ( ) => {
Original file line number Diff line number Diff line change
1
+ import { join } from 'path' ;
2
+
3
+ import { removeSync } from 'fs-extra' ;
4
+
5
+ import webpack from 'webpack' ;
6
+
7
+ import conf from './utils/conf' ;
8
+
9
+ describe ( 'error (cached module)' , ( ) => {
10
+ const cacheLocation = join ( __dirname , 'cache' ) ;
11
+
12
+ beforeEach ( ( ) => {
13
+ removeSync ( cacheLocation ) ;
14
+ } ) ;
15
+
16
+ afterAll ( ( ) => {
17
+ removeSync ( cacheLocation ) ;
18
+ } ) ;
19
+
20
+ it ( 'should return error even if module is cached' , ( done ) => {
21
+ const config = conf ( 'error' ) ;
22
+ config . cache = {
23
+ type : 'filesystem' ,
24
+ idleTimeout : 0 ,
25
+ idleTimeoutAfterLargeChanges : 0 ,
26
+ idleTimeoutForInitialStore : 0 ,
27
+ cacheLocation,
28
+ } ;
29
+
30
+ const c1 = webpack ( config ) ;
31
+
32
+ c1 . run ( ( err1 , stats1 ) => {
33
+ expect ( err1 ) . toBeNull ( ) ;
34
+ expect ( stats1 . hasWarnings ( ) ) . toBe ( false ) ;
35
+ expect ( stats1 . hasErrors ( ) ) . toBe ( true ) ;
36
+
37
+ c1 . close ( ( ) => {
38
+ const c2 = webpack ( config ) ;
39
+ c2 . run ( ( err2 , stats2 ) => {
40
+ expect ( err2 ) . toBeNull ( ) ;
41
+ expect ( stats2 . hasWarnings ( ) ) . toBe ( false ) ;
42
+ expect ( stats2 . hasErrors ( ) ) . toBe ( true ) ;
43
+
44
+ done ( ) ;
45
+ } ) ;
46
+ } ) ;
47
+ } ) ;
48
+ } ) ;
49
+ } ) ;
Original file line number Diff line number Diff line change @@ -33,7 +33,9 @@ declare class ESLintWebpackPlugin {
33
33
getContext ( compiler : Compiler ) : string ;
34
34
}
35
35
declare namespace ESLintWebpackPlugin {
36
- export { Compiler , Options } ;
36
+ export { Compiler , Module , NormalModule , Options } ;
37
37
}
38
38
type Compiler = import ( 'webpack' ) . Compiler ;
39
39
type Options = import ( './options' ) . Options ;
40
+ type Module = import ( 'webpack' ) . Module ;
41
+ type NormalModule = import ( 'webpack' ) . NormalModule ;
You can’t perform that action at this time.
0 commit comments