Skip to content

Commit 547d087

Browse files
authored
default to incremental api usage to true if TS 3+ (#217)
* default to incremental api usage to true if TS 3+ * update version
1 parent 03c612e commit 547d087

File tree

6 files changed

+114
-63
lines changed

6 files changed

+114
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v1.0.0-alpha.9
2+
3+
* [Default to incremental api usage to true if TS 3+](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/217)
4+
15
## v1.0.0-alpha.8
26

37
* [Respect tslint configs hierarchical order](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/214)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ If `true`, the linter and compiler will process VueJs single-file-component (.vu
146146
* **useTypescriptIncrementalApi** `boolean`:
147147
If true, the plugin will use incremental compilation API introduced in typescript 2.7. In this mode you can only have 1
148148
worker, but if the changes in your code are small (like you normally have when you work in 'watch' mode), the compilation
149-
may be much faster, even compared to multi-threaded compilation.
149+
may be much faster, even compared to multi-threaded compilation. Defaults to `true` when working with typescript 3+ and `false` when below 3. The default can be overridden by directly specifying a value.
150150

151151
* **measureCompilationTime** `boolean`:
152152
If true, the plugin will measure the time spent inside the compilation code. This may be useful to compare modes,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "1.0.0-alpha.8",
3+
"version": "1.0.0-alpha.9",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,6 @@ class ForkTsCheckerWebpackPlugin {
165165
options.formatterOptions || {}
166166
);
167167

168-
this.useTypescriptIncrementalApi =
169-
options.useTypescriptIncrementalApi || false;
170-
171168
this.tsconfigPath = undefined;
172169
this.tslintPath = undefined;
173170
this.watchPaths = [];
@@ -208,6 +205,11 @@ class ForkTsCheckerWebpackPlugin {
208205

209206
this.validateVersions();
210207

208+
this.useTypescriptIncrementalApi =
209+
options.useTypescriptIncrementalApi === undefined
210+
? semver.gte(this.typescriptVersion, '3.0.0')
211+
: options.useTypescriptIncrementalApi;
212+
211213
this.vue = options.vue === true; // default false
212214
this.measureTime = options.measureCompilationTime === true;
213215
if (this.measureTime) {

test/integration/index.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ function makeCommonTests(useTypescriptIncrementalApi) {
7070
});
7171

7272
it('should set watch to one element array for string', function() {
73-
var plugin = new ForkTsCheckerWebpackPlugin({ watch: '/test' });
73+
var plugin = new ForkTsCheckerWebpackPlugin({
74+
useTypescriptIncrementalApi: false,
75+
watch: '/test'
76+
});
7477

7578
expect(plugin.watch).to.deep.equal(['/test']);
7679
});

test/unit/index.spec.js

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,114 @@ describe('[UNIT] ForkTsCheckerWebpackPlugin', function() {
99
mockRequire.stopAll();
1010
});
1111

12-
it('should throw if typescript not present', function() {
13-
mockRequire('typescript', undefined);
14-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
15-
16-
expect(function() {
17-
new ForkTsCheckerWebpackPlugin();
18-
}).to.throw(
19-
Error,
20-
'When you use this plugin you must install `typescript`.'
21-
);
22-
});
12+
describe('typescript', () => {
13+
it('should throw if typescript not present', function() {
14+
mockRequire('typescript', undefined);
15+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
2316

24-
it('should not throw if typescript version >= 2.1.0', function() {
25-
mockRequire('typescript', { version: '2.1.0' });
26-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
17+
expect(function() {
18+
new ForkTsCheckerWebpackPlugin();
19+
}).to.throw(
20+
Error,
21+
'When you use this plugin you must install `typescript`.'
22+
);
23+
});
2724

28-
expect(function() {
29-
new ForkTsCheckerWebpackPlugin();
30-
}).to.not.throw();
31-
});
25+
it('should not throw if typescript version >= 2.1.0', function() {
26+
mockRequire('typescript', { version: '2.1.0' });
27+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
3228

33-
it('should throw if typescript version < 2.1.0', function() {
34-
mockRequire('typescript', { version: '2.0.8' });
35-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
29+
expect(function() {
30+
new ForkTsCheckerWebpackPlugin();
31+
}).to.not.throw();
32+
});
3633

37-
expect(function() {
38-
new ForkTsCheckerWebpackPlugin();
39-
}).to.throw(
40-
Error,
41-
'Cannot use current typescript version of 2.0.8, the minimum required version is 2.1.0'
42-
);
43-
});
34+
it('should throw if typescript version < 2.1.0', function() {
35+
mockRequire('typescript', { version: '2.0.8' });
36+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
4437

45-
it('should throw if tslint not present', function() {
46-
mockRequire('typescript', { version: '2.1.0' });
47-
mockRequire('tslint', undefined);
48-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
49-
50-
expect(function() {
51-
new ForkTsCheckerWebpackPlugin({ tslint: true });
52-
}).to.throw(
53-
Error,
54-
'When you use `tslint` option, make sure to install `tslint`.'
55-
);
38+
expect(function() {
39+
new ForkTsCheckerWebpackPlugin();
40+
}).to.throw(
41+
Error,
42+
'Cannot use current typescript version of 2.0.8, the minimum required version is 2.1.0'
43+
);
44+
});
5645
});
5746

58-
it('should not throw if tslint version >= 4.0.0', function() {
59-
mockRequire('typescript', { version: '2.1.0' });
60-
mockRequire('tslint', { Linter: { VERSION: '4.0.0' } });
61-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
47+
describe('tslint', () => {
48+
it('should throw if tslint not present', function() {
49+
mockRequire('typescript', { version: '2.1.0' });
50+
mockRequire('tslint', undefined);
51+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
52+
53+
expect(function() {
54+
new ForkTsCheckerWebpackPlugin({ tslint: true });
55+
}).to.throw(
56+
Error,
57+
'When you use `tslint` option, make sure to install `tslint`.'
58+
);
59+
});
60+
61+
it('should not throw if tslint version >= 4.0.0', function() {
62+
mockRequire('typescript', { version: '2.1.0' });
63+
mockRequire('tslint', { Linter: { VERSION: '4.0.0' } });
64+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
65+
66+
expect(function() {
67+
new ForkTsCheckerWebpackPlugin({ tslint: true });
68+
}).to.not.throw();
69+
});
70+
71+
it('should throw if tslint version < 4.0.0', function() {
72+
mockRequire('typescript', { version: '2.1.0' });
73+
mockRequire('tslint', { Linter: { VERSION: '3.15.1' } });
74+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
6275

63-
expect(function() {
64-
new ForkTsCheckerWebpackPlugin({ tslint: true });
65-
}).to.not.throw();
76+
expect(function() {
77+
new ForkTsCheckerWebpackPlugin({ tslint: true });
78+
}).to.throw(
79+
Error,
80+
'Cannot use current tslint version of 3.15.1, the minimum required version is 4.0.0'
81+
);
82+
});
6683
});
6784

68-
it('should throw if tslint version < 4.0.0', function() {
69-
mockRequire('typescript', { version: '2.1.0' });
70-
mockRequire('tslint', { Linter: { VERSION: '3.15.1' } });
71-
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
72-
73-
expect(function() {
74-
new ForkTsCheckerWebpackPlugin({ tslint: true });
75-
}).to.throw(
76-
Error,
77-
'Cannot use current tslint version of 3.15.1, the minimum required version is 4.0.0'
78-
);
85+
describe('useTypescriptIncrementalApi', () => {
86+
it('should be true if useTypescriptIncrementalApi: true supplied', function() {
87+
mockRequire('typescript', { version: '2.1.0' });
88+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
89+
90+
expect(
91+
new ForkTsCheckerWebpackPlugin({ useTypescriptIncrementalApi: true })
92+
.useTypescriptIncrementalApi
93+
).to.be.true;
94+
});
95+
96+
it('should be true if useTypescriptIncrementalApi: false supplied', function() {
97+
mockRequire('typescript', { version: '3.0.0' });
98+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
99+
100+
expect(
101+
new ForkTsCheckerWebpackPlugin({ useTypescriptIncrementalApi: false })
102+
.useTypescriptIncrementalApi
103+
).to.be.false;
104+
});
105+
106+
it('should be false if useTypescriptIncrementalApi not supplied and typescript version < 3.0.0', function() {
107+
mockRequire('typescript', { version: '2.1.0' });
108+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
109+
110+
expect(new ForkTsCheckerWebpackPlugin().useTypescriptIncrementalApi).to.be
111+
.false;
112+
});
113+
114+
it('should be true if useTypescriptIncrementalApi not supplied and typescript version >= 3.0.0', function() {
115+
mockRequire('typescript', { version: '3.0.0' });
116+
var ForkTsCheckerWebpackPlugin = mockRequire.reRequire('../../lib/index');
117+
118+
expect(new ForkTsCheckerWebpackPlugin().useTypescriptIncrementalApi).to.be
119+
.true;
120+
});
79121
});
80122
});

0 commit comments

Comments
 (0)