diff --git a/src/index.js b/src/index.js index 798d750..087575a 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,8 @@ const linter = require('./linter'); const { arrify, parseFiles, parseFoldersToGlobs } = require('./utils'); /** @typedef {import('webpack').Compiler} Compiler */ +/** @typedef {import('webpack').Module} Module */ +/** @typedef {import('webpack').NormalModule} NormalModule */ /** @typedef {import('./options').Options} Options */ const ESLINT_PLUGIN = 'ESLintWebpackPlugin'; @@ -108,9 +110,16 @@ class ESLintWebpackPlugin { /** @type {string[]} */ const files = []; - // @ts-ignore // Add the file to be linted - compilation.hooks.succeedModule.tap(this.key, ({ resource }) => { + compilation.hooks.succeedModule.tap(this.key, addFile); + compilation.hooks.stillValidModule.tap(this.key, addFile); + + /** + * @param {Module} module + */ + function addFile(module) { + const { resource } = /** @type {NormalModule} */ (module); + if (!resource) return; const [file, query] = resource.split('?'); @@ -127,7 +136,7 @@ class ESLintWebpackPlugin { if (threads > 1) lint(file); } - }); + } // Lint all files added compilation.hooks.finishModules.tap(this.key, () => { diff --git a/test/cached.test.js b/test/cached.test.js new file mode 100644 index 0000000..2497c80 --- /dev/null +++ b/test/cached.test.js @@ -0,0 +1,49 @@ +import { join } from 'path'; + +import { removeSync } from 'fs-extra'; + +import webpack from 'webpack'; + +import conf from './utils/conf'; + +describe('error (cached module)', () => { + const cacheLocation = join(__dirname, 'cache'); + + beforeEach(() => { + removeSync(cacheLocation); + }); + + afterAll(() => { + removeSync(cacheLocation); + }); + + it('should return error even if module is cached', (done) => { + const config = conf('error'); + config.cache = { + type: 'filesystem', + idleTimeout: 0, + idleTimeoutAfterLargeChanges: 0, + idleTimeoutForInitialStore: 0, + cacheLocation, + }; + + const c1 = webpack(config); + + c1.run((err1, stats1) => { + expect(err1).toBeNull(); + expect(stats1.hasWarnings()).toBe(false); + expect(stats1.hasErrors()).toBe(true); + + c1.close(() => { + const c2 = webpack(config); + c2.run((err2, stats2) => { + expect(err2).toBeNull(); + expect(stats2.hasWarnings()).toBe(false); + expect(stats2.hasErrors()).toBe(true); + + done(); + }); + }); + }); + }); +}); diff --git a/types/index.d.ts b/types/index.d.ts index 58cb948..abe8d01 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -33,7 +33,9 @@ declare class ESLintWebpackPlugin { getContext(compiler: Compiler): string; } declare namespace ESLintWebpackPlugin { - export { Compiler, Options }; + export { Compiler, Module, NormalModule, Options }; } type Compiler = import('webpack').Compiler; type Options = import('./options').Options; +type Module = import('webpack').Module; +type NormalModule = import('webpack').NormalModule;