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');
77const { arrify, parseFiles, parseFoldersToGlobs } = require ( './utils' ) ;
88
99/** @typedef {import('webpack').Compiler } Compiler */
10+ /** @typedef {import('webpack').Module } Module */
11+ /** @typedef {import('webpack').NormalModule } NormalModule */
1012/** @typedef {import('./options').Options } Options */
1113
1214const ESLINT_PLUGIN = 'ESLintWebpackPlugin' ;
@@ -108,9 +110,16 @@ class ESLintWebpackPlugin {
108110 /** @type {string[] } */
109111 const files = [ ] ;
110112
111- // @ts -ignore
112113 // 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+
114123 if ( ! resource ) return ;
115124
116125 const [ file , query ] = resource . split ( '?' ) ;
@@ -127,7 +136,7 @@ class ESLintWebpackPlugin {
127136
128137 if ( threads > 1 ) lint ( file ) ;
129138 }
130- } ) ;
139+ }
131140
132141 // Lint all files added
133142 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 {
3333 getContext ( compiler : Compiler ) : string ;
3434}
3535declare namespace ESLintWebpackPlugin {
36- export { Compiler , Options } ;
36+ export { Compiler , Module , NormalModule , Options } ;
3737}
3838type Compiler = import ( 'webpack' ) . Compiler ;
3939type 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