Skip to content

Commit 540c634

Browse files
committed
Merge remote-tracking branch 'upstream/master' into good-neighbor
2 parents 927b5c5 + 7967402 commit 540c634

14 files changed

+1028
-227
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## v0.4.14
2+
3+
* [Add support for `reportFiles` option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/179) (#179)
4+
5+
## v0.4.13
6+
7+
* [Merge in `compilerOptions` prior to calling `parseJsonConfigFileContent`](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/176) (#176)
8+
9+
## v0.4.12
10+
11+
* [Add `compilerOptions` option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/173) (#173)
12+
13+
## v0.4.11
14+
15+
* [Fix os.cpus is not a function](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/172) (#172)
16+
117
## v0.4.10
218

319
* [Allow fork-ts-checker-webpack-plugin to be imported in .ts files using ESM import syntax](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/163) (#163)

package.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin-alt",
3-
"version": "0.4.10",
3+
"version": "0.4.14",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"types": "lib/types/index.d.ts",
@@ -9,8 +9,8 @@
99
],
1010
"scripts": {
1111
"build": "tsc --version && tsc --project \"./src\"",
12-
"test:unit": "mocha -R spec ./test/unit",
13-
"test:integration": "mocha -R spec ./test/integration && rimraf tmp",
12+
"test:unit": "mocha -R spec ./test/unit --exit",
13+
"test:integration": "mocha -R spec ./test/integration --exit && rimraf tmp",
1414
"test": "npm run build && npm run test:unit && npm run test:integration",
1515
"test:watch": "mocha -R spec --watch ./test/unit",
1616
"test:coverage": "rimraf coverage && istanbul cover -root lib --include-all-sources mocha -- -R spec ./test/unit ./test/integration",
@@ -51,10 +51,8 @@
5151
"devDependencies": {
5252
"@types/babel-code-frame": "^6.20.1",
5353
"@types/chokidar": "^1.7.5",
54-
"@types/lodash.endswith": "^4.2.3",
55-
"@types/lodash.isfunction": "^3.0.3",
56-
"@types/lodash.isstring": "^4.0.3",
57-
"@types/lodash.startswith": "^4.2.3",
54+
"@types/lodash": "^4.14.117",
55+
"@types/micromatch": "^3.1.0",
5856
"@types/minimatch": "^3.0.1",
5957
"@types/node": "^8.0.26",
6058
"@types/resolve": "0.0.4",
@@ -65,7 +63,7 @@
6563
"husky": "^1.1.2",
6664
"istanbul": "^0.4.5",
6765
"lint-staged": "^7.3.0",
68-
"mocha": "^3.4.1",
66+
"mocha": "^5.2.0",
6967
"mock-fs": "^4.3.0",
7068
"mock-require": "^2.0.2",
7169
"prettier": "^1.14.3",
@@ -88,10 +86,8 @@
8886
"babel-code-frame": "^6.22.0",
8987
"chalk": "^2.4.1",
9088
"chokidar": "^2.0.4",
91-
"lodash.endswith": "^4.2.1",
92-
"lodash.isfunction": "^3.0.8",
93-
"lodash.isstring": "^4.0.1",
94-
"lodash.startswith": "^4.2.1",
89+
"lodash": "^4.17.11",
90+
"micromatch": "^3.1.10",
9591
"minimatch": "^3.0.4",
9692
"resolve": "^1.5.0",
9793
"tapable": "^1.0.0"

src/FilesWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as chokidar from 'chokidar';
22
import * as path from 'path';
3-
import startsWith = require('lodash.startswith');
3+
import startsWith = require('lodash/startsWith');
44

55
export class FilesWatcher {
66
watchPaths: string[];

src/IncrementalChecker.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import endsWith = require('lodash.endswith');
2+
import endsWith = require('lodash/endsWith');
33
import * as path from 'path';
44
// tslint:disable-next-line:no-implicit-dependencies
55
import * as ts from 'typescript';
@@ -25,6 +25,7 @@ interface ConfigurationFile extends Configuration.IConfigurationFile {
2525

2626
export class IncrementalChecker {
2727
programConfigFile: string;
28+
compilerOptions: object;
2829
linterConfigFile: string | false;
2930
watchPaths: string[];
3031
workNumber: number;
@@ -46,6 +47,7 @@ export class IncrementalChecker {
4647
constructor(
4748
typescriptPath: string,
4849
programConfigFile: string,
50+
compilerOptions: object,
4951
linterConfigFile: string | false,
5052
watchPaths: string[],
5153
workNumber: number,
@@ -55,6 +57,7 @@ export class IncrementalChecker {
5557
) {
5658
this.typescript = require(typescriptPath);
5759
this.programConfigFile = programConfigFile;
60+
this.compilerOptions = compilerOptions;
5861
this.linterConfigFile = linterConfigFile;
5962
this.watchPaths = watchPaths;
6063
this.workNumber = workNumber || 0;
@@ -74,18 +77,29 @@ export class IncrementalChecker {
7477
}));
7578
}
7679

77-
static loadProgramConfig(typescript: TypeScriptInstance, configFile: string) {
78-
return typescript.parseJsonConfigFileContent(
79-
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
80-
Object.assign(
81-
typescript.readConfigFile(configFile, typescript.sys.readFile).config,
82-
{
83-
isolatedModules: false
84-
}
85-
),
80+
static loadProgramConfig(
81+
typescript: TypeScriptInstance,
82+
configFile: string,
83+
compilerOptions: object
84+
) {
85+
const tsconfig = typescript.readConfigFile(
86+
configFile,
87+
typescript.sys.readFile
88+
).config;
89+
90+
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
91+
tsconfig.compilerOptions = {
92+
...tsconfig.compilerOptions,
93+
...compilerOptions
94+
};
95+
96+
const parsed = typescript.parseJsonConfigFileContent(
97+
tsconfig,
8698
typescript.sys,
8799
path.dirname(configFile)
88100
);
101+
102+
return parsed;
89103
}
90104

91105
static loadLinterConfig(configFile: string): ConfigurationFile {
@@ -201,7 +215,11 @@ export class IncrementalChecker {
201215
loadVueProgram() {
202216
this.programConfig =
203217
this.programConfig ||
204-
VueProgram.loadProgramConfig(this.typescript, this.programConfigFile);
218+
VueProgram.loadProgramConfig(
219+
this.typescript,
220+
this.programConfigFile,
221+
this.compilerOptions
222+
);
205223

206224
return VueProgram.createProgram(
207225
this.typescript,
@@ -218,7 +236,8 @@ export class IncrementalChecker {
218236
this.programConfig ||
219237
IncrementalChecker.loadProgramConfig(
220238
this.typescript,
221-
this.programConfigFile
239+
this.programConfigFile,
240+
this.compilerOptions
222241
);
223242

224243
return IncrementalChecker.createProgram(

src/VueProgram.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ interface ResolvedScript {
1414
}
1515

1616
export class VueProgram {
17-
static loadProgramConfig(typescript: TypeScriptInstance, configFile: string) {
17+
static loadProgramConfig(
18+
typescript: TypeScriptInstance,
19+
configFile: string,
20+
compilerOptions: object
21+
) {
1822
const extraExtensions = ['vue'];
1923

2024
const parseConfigHost: ts.ParseConfigHost = {
@@ -32,14 +36,19 @@ export class VueProgram {
3236
}
3337
};
3438

39+
const tsconfig = typescript.readConfigFile(
40+
configFile,
41+
typescript.sys.readFile
42+
).config;
43+
44+
tsconfig.compilerOptions = tsconfig.compilerOptions || {};
45+
tsconfig.compilerOptions = {
46+
...tsconfig.compilerOptions,
47+
...compilerOptions
48+
};
49+
3550
const parsed = typescript.parseJsonConfigFileContent(
36-
// Regardless of the setting in the tsconfig.json we want isolatedModules to be false
37-
Object.assign(
38-
typescript.readConfigFile(configFile, typescript.sys.readFile).config,
39-
{
40-
isolatedModules: false
41-
}
42-
),
51+
tsconfig,
4352
parseConfigHost,
4453
path.dirname(configFile)
4554
);

src/index.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ 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';
8-
import isString = require('lodash.isstring');
9-
import isFunction = require('lodash.isfunction');
9+
import isString = require('lodash/isString');
10+
import isFunction = require('lodash/isFunction');
1011
import { CancellationToken } from './CancellationToken';
1112
import { NormalizedMessage } from './NormalizedMessage';
1213
import { createDefaultFormatter } from './formatter/defaultFormatter';
@@ -40,11 +41,13 @@ interface Logger {
4041
interface Options {
4142
typescript?: string;
4243
tsconfig: string;
44+
compilerOptions: object;
4345
tslint: string | true;
4446
watch: string | string[];
4547
async: boolean;
4648
ignoreDiagnostics: number[];
4749
ignoreLints: string[];
50+
reportFiles: string[];
4851
colors: boolean;
4952
logger: Logger;
5053
formatter: 'default' | 'codeframe' | Formatter;
@@ -66,17 +69,19 @@ interface Options {
6669
class ForkTsCheckerWebpackPlugin {
6770
static DEFAULT_MEMORY_LIMIT = 2048;
6871
static ONE_CPU = 1;
69-
static ALL_CPUS = os.cpus() ? os.cpus().length : 1;
72+
static ALL_CPUS = os.cpus && os.cpus() ? os.cpus().length : 1;
7073
static ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
7174
static TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
7275

7376
typescriptPath: string;
7477
options: Partial<Options>;
7578
tsconfig: string;
79+
compilerOptions: object;
7680
tslint: string | true;
7781
watch: string[];
7882
ignoreDiagnostics: number[];
7983
ignoreLints: string[];
84+
reportFiles: string[];
8085
logger: Logger;
8186
silent: boolean;
8287
async: boolean;
@@ -116,6 +121,10 @@ class ForkTsCheckerWebpackPlugin {
116121
this.options = Object.assign({}, options);
117122

118123
this.tsconfig = options.tsconfig || './tsconfig.json';
124+
this.compilerOptions =
125+
typeof options.compilerOptions === 'object'
126+
? options.compilerOptions
127+
: {};
119128
this.tslint = options.tslint
120129
? options.tslint === true
121130
? './tslint.json'
@@ -126,6 +135,7 @@ class ForkTsCheckerWebpackPlugin {
126135
: options.watch || [];
127136
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
128137
this.ignoreLints = options.ignoreLints || [];
138+
this.reportFiles = options.reportFiles || [];
129139
this.logger = options.logger || console;
130140
this.silent = options.silent === true; // default false
131141
this.async = options.async !== false; // default true
@@ -572,6 +582,7 @@ class ForkTsCheckerWebpackPlugin {
572582
env: Object.assign({}, process.env, {
573583
TYPESCRIPT_PATH: this.typescriptPath,
574584
TSCONFIG: this.tsconfigPath,
585+
COMPILER_OPTIONS: JSON.stringify(this.compilerOptions),
575586
TSLINT: this.tslintPath || '',
576587
WATCH: this.isWatching ? this.watchPaths.join('|') : '',
577588
WORK_DIVISION: Math.max(1, this.workersNumber),
@@ -685,6 +696,26 @@ class ForkTsCheckerWebpackPlugin {
685696
);
686697
}
687698

699+
if (this.reportFiles.length) {
700+
const reportFilesPredicate = (diagnostic: NormalizedMessage): boolean => {
701+
if (diagnostic.file) {
702+
const relativeFileName = path.relative(
703+
this.compiler.options.context,
704+
diagnostic.file
705+
);
706+
const matchResult = micromatch([relativeFileName], this.reportFiles);
707+
708+
if (matchResult.length === 0) {
709+
return false;
710+
}
711+
}
712+
return true;
713+
};
714+
715+
this.diagnostics = this.diagnostics.filter(reportFilesPredicate);
716+
this.lints = this.lints.filter(reportFilesPredicate);
717+
}
718+
688719
if ('hooks' in this.compiler) {
689720
// webpack 4
690721
this.compiler.hooks.forkTsCheckerReceive.call(

src/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { OperationCanceledException } from './OperationCanceledException';
77
const checker = new IncrementalChecker(
88
process.env.TYPESCRIPT_PATH,
99
process.env.TSCONFIG,
10+
JSON.parse(process.env.COMPILER_OPTIONS),
1011
process.env.TSLINT === '' ? false : process.env.TSLINT,
1112
process.env.WATCH === '' ? [] : process.env.WATCH.split('|'),
1213
parseInt(process.env.WORK_NUMBER, 10),

src/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"noUnusedParameters": true,
99
"suppressImplicitAnyIndexErrors": true,
1010
"strictNullChecks": false,
11-
"lib": ["es5", "es2015.core", "dom"],
11+
"lib": ["es5", "es2015", "dom"],
1212
"module": "commonjs",
1313
"moduleResolution": "node",
1414
"declaration": true,

src/tslint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"allow-pascal-case"
2323
],
2424
"no-namespace": false,
25-
"array-type": [true, "array"]
25+
"array-type": [true, "array"],
26+
"no-submodule-imports": [true, "lodash"]
27+
2628
}
2729
}

0 commit comments

Comments
 (0)