Skip to content

Commit 4311b8d

Browse files
authored
Merge pull request #10 from Realytics/feature/improve-readme
v0.1.5
2 parents f49e5bd + c32f4b4 commit 4311b8d

File tree

4 files changed

+74
-35
lines changed

4 files changed

+74
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v0.1.5
2+
* Disable tslint if module is not installed and no tslint path is passed
3+
* Improve README.md
4+
15
## v0.1.4
26
* Fix send to closed channel case
37
* Fix removed files case

README.md

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Webpack plugin that runs typescript type checker on a separate process.
66

7-
## Installation ##
7+
## Installation
88
This plugin requires minimum **webpack 2**, **typescript 2.1** and optionally **tslint 5.0**
99
```sh
1010
npm install --save-dev fork-ts-checker-webpack-plugin
@@ -41,52 +41,73 @@ var webpackConfig = {
4141
};
4242
```
4343

44-
## Motivation ##
44+
## Motivation
4545
There is already similar solution - [awesome-typescript-loader](https://github.com/s-panferov/awesome-typescript-loader). You can
4646
add `CheckerPlugin` and delegate checker to the separate process. The problem with `awesome-typescript-loader` was that, in our case,
4747
it was a lot slower than [ts-loader](https://github.com/TypeStrong/ts-loader) on an incremental build (~20s vs ~3s).
48-
Secondly, we use [tslint](https://palantir.github.io/tslint/) and we wanted to run this, along with type checker, in a separate process.
48+
Secondly, we use [tslint](https://palantir.github.io/tslint) and we wanted to run this, along with type checker, in a separate process.
4949
This is why we've created this plugin. To provide better performance, plugin reuses Abstract Syntax Trees between compilations and shares
5050
these trees with tslint. It can be scaled with a multi-process mode to utilize maximum CPU power.
5151

52-
## Options ##
53-
**tsconfig** `string` - Path to tsconfig.json file. If not set, plugin will use `path.resolve(compiler.options.context, './tsconfig.json')`.
52+
## Modules resolution
53+
It's very important to be aware that **this plugin uses [typescript](https://github.com/Microsoft/TypeScript)'s, not
54+
[webpack](https://github.com/webpack/webpack)'s modules resolution**. It means that you have to setup `tsconfig.json` correctly. For example
55+
if you set `files: ['./src/someFile.ts']` in `tsconfig.json`, this plugin will check only `someFile.ts` for semantic errors. It's because
56+
of performance. The goal of this plugin is to be *as fast as possible*. With typescript's module resolution we don't have to wait for webpack
57+
to compile files (which traverses dependency graph during compilation) - we have a full list of files from the begin.
5458

55-
**tslint** `string | false` - Path to tslint.json file. If not set, plugin will use `path.resolve(compiler.options.context, './tslint.json')`.
56-
If `false`, disables tslint.
59+
To debug typescript's modules resolution, you can use `tsc --traceResolution` command.
5760

58-
**watch** `string | string[]` - Directories or files to watch by service. Not necessary but improves performance
59-
(reduces number of `fs.stat` calls).
61+
## TSLint
62+
If you have installed [tslint](https://palantir.github.io/tslint), it's enabled by default. To disable it, set `tslint: false` in plugin
63+
options. We recommend changing `defaultSeverity` to the `"warning"` in `tslint.json` file. It helps to distinguish lints from typescript's
64+
diagnostics.
65+
66+
## Options
67+
* **tsconfig** `string`:
68+
Path to tsconfig.json file. Default: `path.resolve(compiler.options.context, './tsconfig.json')`
69+
70+
* **tslint** `string | false`:
71+
Path to tslint.json file. If `false`, disables tslint. Default: `path.resolve(compiler.options.context, './tslint.json')`
72+
73+
* **watch** `string | string[]`:
74+
Directories or files to watch by service. Not necessary but improves performance (reduces number of `fs.stat` calls).
6075

61-
**blockEmit** `boolean` - If `true`, plugin will block emit until check will be done. It's good setting for ci/production build because
62-
webpack will return code != 0 if there are type/lint errors. Default: `false`.
76+
* **blockEmit** `boolean`:
77+
If `true`, plugin will block emit until check will be done. It's good setting for ci/production build because webpack will return code != 0
78+
if there are type/lint errors. Default: `false`.
6379

64-
**ignoreDiagnostics** `number[]` - List of typescript diagnostic codes to ignore.
80+
* **ignoreDiagnostics** `number[]`:
81+
List of typescript diagnostic codes to ignore.
6582

66-
**ignoreLints** `string[]` - List of tslint rule names to ignore.
83+
* **ignoreLints** `string[]`:
84+
List of tslint rule names to ignore.
6785

68-
**colors** `boolean` - If `false`, disables built-in colors in logger messages. Default: `true`.
86+
* **colors** `boolean`:
87+
If `false`, disables built-in colors in logger messages. Default: `true`.
6988

70-
**logger** `object` - Logger instance. It should be object that implements method: `error`, `warn`, `info`. Default: `console`.
89+
* **logger** `object`:
90+
Logger instance. It should be object that implements method: `error`, `warn`, `info`. Default: `console`.
7191

72-
**silent** `boolean` - If `true`, logger will not be used. Default: `false`.
92+
* **silent** `boolean`:
93+
If `true`, logger will not be used. Default: `false`.
7394

74-
**workers** `number` - You can split type checking to a few workers to speed-up increment build.
75-
**Be careful** - if you don't want to increase build time, you should keep free 1 core for *build* and 1 core for
76-
a *system* *(for example system with 4 CPUs should use max 2 workers)*.
77-
Second thing - node doesn't share memory between workers - keep in mind that memory usage will increase.
78-
Be aware that in some scenarios increasing workers number **can increase checking time**.
79-
Default: `ForkTsCheckerWebpackPlugin.ONE_CPU`.
95+
* **memoryLimit** `number`:
96+
Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: `2048`.
8097

81-
Pre-computed consts:
98+
* **workers** `number`:
99+
You can split type checking to a few workers to speed-up increment build. **Be careful** - if you don't want to increase build time, you
100+
should keep free 1 core for *build* and 1 core for a *system* *(for example system with 4 CPUs should use max 2 workers)*. Second thing -
101+
node doesn't share memory between workers - keep in mind that memory usage will increase. Be aware that in some scenarios increasing workers
102+
number **can increase checking time**. Default: `ForkTsCheckerWebpackPlugin.ONE_CPU`.
103+
104+
### Pre-computed consts:
82105
* `ForkTsCheckerWebpackPlugin.ONE_CPU` - always use one CPU
106+
* `ForkTsCheckerWebpackPlugin.ALL_CPUS` - always use all CPUs (will increase build time)
83107
* `ForkTsCheckerWebpackPlugin.ONE_CPU_FREE` - leave only one CPU for build (probably will increase build time)
84-
* `ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE` - leave two CPUs free (one for build, one for system)
85-
86-
**memoryLimit** `number` - Memory limit for service process in MB. If service exits with allocation failed error, increase this number.
87-
Default: `2048`.
108+
* `ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE` - **recommended** - leave two CPUs free (one for build, one for system)
88109

89-
## Plugin Hooks ##
110+
## Plugin Hooks
90111
This plugin provides some custom webpack hooks (all are sync):
91112

92113
| Event name | Description | Params |
@@ -100,5 +121,5 @@ This plugin provides some custom webpack hooks (all are sync):
100121
|`fork-ts-checker-emit`| Service will add errors and warnings to webpack compilation (`blockEmit: true`) | `diagnostics`, `lints`, `elapsed` |
101122
|`fork-ts-checker-done`| Service finished type checking and webpack finished compilation (`blockEmit: false`) | `diagnostics`, `lints`, `elapsed` |
102123

103-
## License ##
124+
## License
104125
MIT

lib/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@ var NormalizedMessage = require('./NormalizedMessage');
1616
* Options description in README.md
1717
*/
1818
function ForkTsCheckerWebpackPlugin (options) {
19+
var tslintInstalled;
20+
21+
try {
22+
require.resolve('tslint');
23+
tslintInstalled = true;
24+
} catch (error) {
25+
tslintInstalled = false;
26+
}
27+
1928
this.options = Object.assign({}, options);
2029
this.tsconfig = options.tsconfig || './tsconfig.json';
21-
this.tslint = options.tslint === false ? false : options.tslint || './tslint.json';
30+
this.tslint = options.tslint === false ? false : (options.tslint || (tslintInstalled ? './tslint.json' : false));
2231
this.watch = isString(options.watch) ? [options.watch] : options.watch || [];
2332
this.blockEmit = !!options.blockEmit;
2433
this.ignoreDiagnostics = options.ignoreDiagnostics || [];
@@ -55,8 +64,9 @@ module.exports = ForkTsCheckerWebpackPlugin;
5564
ForkTsCheckerWebpackPlugin.DEFAULT_MEMORY_LIMIT = 2048;
5665

5766
ForkTsCheckerWebpackPlugin.ONE_CPU = 1;
58-
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, os.cpus().length - 1);
59-
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, os.cpus().length - 2);
67+
ForkTsCheckerWebpackPlugin.ALL_CPUS = os.cpus().length;
68+
ForkTsCheckerWebpackPlugin.ONE_CPU_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 1);
69+
ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE = Math.max(1, ForkTsCheckerWebpackPlugin.ALL_CPUS - 2);
6070

6171
ForkTsCheckerWebpackPlugin.prototype.apply = function (compiler) {
6272
this.compiler = compiler;

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fork-ts-checker-webpack-plugin",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Runs typescript type checker and linter on separate process.",
55
"main": "lib/index.js",
66
"scripts": {
@@ -23,7 +23,11 @@
2323
"linter",
2424
"fork",
2525
"fast",
26-
"speed"
26+
"speed",
27+
"ts-loader",
28+
"awesome-typescript-loader",
29+
"increment",
30+
"webpack-plugin"
2731
],
2832
"author": "Piotr Oleś <[email protected]>",
2933
"license": "MIT",
@@ -38,7 +42,7 @@
3842
"mock-fs": "^4.3.0",
3943
"mock-require": "^2.0.2",
4044
"rimraf": "^2.5.4",
41-
"sinon": "^2.2.0",
45+
"sinon": "^2.3.1",
4246
"typescript": "^2.1.0"
4347
},
4448
"peerDependencies": {

0 commit comments

Comments
 (0)