Skip to content

Commit 011cc15

Browse files
committed
Add support for reportFiles option
1 parent 458cd74 commit 011cc15

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@types/babel-code-frame": "^6.20.1",
5353
"@types/chokidar": "^1.7.5",
5454
"@types/lodash": "^4.14.117",
55+
"@types/micromatch": "^3.1.0",
5556
"@types/minimatch": "^3.0.1",
5657
"@types/node": "^8.0.26",
5758
"@types/resolve": "0.0.4",
@@ -88,6 +89,7 @@
8889
"chalk": "^2.4.1",
8990
"chokidar": "^2.0.4",
9091
"lodash": "^4.17.11",
92+
"micromatch": "^3.1.10",
9193
"minimatch": "^3.0.4",
9294
"resolve": "^1.5.0",
9395
"tapable": "^1.0.0"

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as process from 'process';
33
import * as childProcess from 'child_process';
44
import chalk, { Chalk } from 'chalk';
55
import * as fs from 'fs';
6+
import * as micromatch from 'micromatch';
67
import * as os from 'os';
78
import * as webpack from 'webpack';
89
import isString = require('lodash/isString');
@@ -45,6 +46,7 @@ interface Options {
4546
async: boolean;
4647
ignoreDiagnostics: number[];
4748
ignoreLints: string[];
49+
reportFiles: string[];
4850
colors: boolean;
4951
logger: Logger;
5052
formatter: 'default' | 'codeframe' | Formatter;
@@ -77,6 +79,7 @@ class ForkTsCheckerWebpackPlugin {
7779
watch: string[];
7880
ignoreDiagnostics: number[];
7981
ignoreLints: string[];
82+
reportFiles: string[];
8083
logger: Logger;
8184
silent: boolean;
8285
async: boolean;
@@ -130,6 +133,7 @@ class ForkTsCheckerWebpackPlugin {
130133
: options.watch || [];
131134
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
132135
this.ignoreLints = options.ignoreLints || [];
136+
this.reportFiles = options.reportFiles || [];
133137
this.logger = options.logger || console;
134138
this.silent = options.silent === true; // default false
135139
this.async = options.async !== false; // default true
@@ -674,6 +678,26 @@ class ForkTsCheckerWebpackPlugin {
674678
);
675679
}
676680

681+
if (this.reportFiles.length) {
682+
const reportFilesPredicate = (diagnostic: NormalizedMessage): boolean => {
683+
if (diagnostic.file) {
684+
const relativeFileName = path.relative(
685+
this.compiler.options.context,
686+
diagnostic.file
687+
);
688+
const matchResult = micromatch([relativeFileName], this.reportFiles);
689+
690+
if (matchResult.length === 0) {
691+
return false;
692+
}
693+
}
694+
return true;
695+
};
696+
697+
this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
698+
this.lints = this.lints.filter(reportFilesPredicate);
699+
}
700+
677701
if ('hooks' in this.compiler) {
678702
// webpack 4
679703
this.compiler.hooks.forkTsCheckerReceive.call(

test/integration/index.spec.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,26 @@ describe('[INTEGRATION] index', function() {
6161
it('should detect paths', function() {
6262
var plugin = new ForkTsCheckerWebpackPlugin({ tslint: true });
6363

64-
expect(plugin.tsconfig).to.be.equal('./tsconfig.json');
65-
expect(plugin.tslint).to.be.equal('./tslint.json');
64+
expect(plugin.tsconfig).to.equal('./tsconfig.json');
65+
expect(plugin.tslint).to.equal('./tslint.json');
6666
});
6767

6868
it('should set logger to console by default', function() {
6969
var plugin = new ForkTsCheckerWebpackPlugin({});
7070

71-
expect(plugin.logger).to.be.equal(console);
71+
expect(plugin.logger).to.equal(console);
7272
});
7373

7474
it('should set watch to empty array by default', function() {
7575
var plugin = new ForkTsCheckerWebpackPlugin({});
7676

77-
expect(plugin.watch).to.be.deep.equal([]);
77+
expect(plugin.watch).to.deep.equal([]);
7878
});
7979

8080
it('should set watch to one element array for string', function() {
8181
var plugin = new ForkTsCheckerWebpackPlugin({ watch: '/test' });
8282

83-
expect(plugin.watch).to.be.deep.equal(['/test']);
83+
expect(plugin.watch).to.deep.equal(['/test']);
8484
});
8585

8686
it('should work without configuration', function(callback) {
@@ -227,8 +227,8 @@ describe('[INTEGRATION] index', function() {
227227
});
228228

229229
function compareResults() {
230-
expect(errorsA).to.be.deep.equal(errorsB);
231-
expect(warningsA).to.be.deep.equal(warningsB);
230+
expect(errorsA).to.deep.equal(errorsB);
231+
expect(warningsA).to.deep.equal(warningsB);
232232
callback();
233233
}
234234
});
@@ -284,7 +284,7 @@ describe('[INTEGRATION] index', function() {
284284
var compiler = createCompiler({}, true);
285285

286286
compiler.run(function(error, stats) {
287-
expect(stats.compilation.errors.length).to.be.equal(1);
287+
expect(stats.compilation.errors.length).to.equal(1);
288288
callback();
289289
});
290290
});
@@ -293,7 +293,20 @@ describe('[INTEGRATION] index', function() {
293293
var compiler = createCompiler({ checkSyntacticErrors: true }, true);
294294

295295
compiler.run(function(error, stats) {
296-
expect(stats.compilation.errors.length).to.be.equal(2);
296+
expect(stats.compilation.errors.length).to.equal(2);
297+
callback();
298+
});
299+
});
300+
301+
it('should only show errors matching paths specified in reportFiles when provided', function(callback) {
302+
var compiler = createCompiler(
303+
{ checkSyntacticErrors: true, reportFiles: ['**/index.ts'] },
304+
true
305+
);
306+
307+
compiler.run(function(error, stats) {
308+
expect(stats.compilation.errors.length).to.equal(1);
309+
expect(stats.compilation.errors[0].file.endsWith('index.ts')).to.be.true;
297310
callback();
298311
});
299312
});

0 commit comments

Comments
 (0)