Skip to content

Commit 5008da9

Browse files
authored
Merge pull request #377 from TypeStrong/beta
v4.0.0 release
2 parents f07881e + c7a1b2c commit 5008da9

File tree

105 files changed

+3861
-6992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3861
-6992
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/src/types/**
2+
/lib/**

.eslintrc.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: ['plugin:node/recommended', 'plugin:prettier/recommended'],
4+
parserOptions: {
5+
ecmaVersion: 2018,
6+
sourceType: 'module'
7+
},
8+
settings: {
9+
node: {
10+
tryExtensions: ['.js', '.json', '.ts', '.d.ts']
11+
}
12+
},
13+
rules: {
14+
'no-process-exit': 'off', // to investigate if we should throw an error instead of process.exit()
15+
'node/no-unsupported-features/es-builtins': 'off',
16+
'node/no-unsupported-features/es-syntax': 'off'
17+
},
18+
overrides: [
19+
{
20+
files: ['*.ts'],
21+
extends: [
22+
'plugin:@typescript-eslint/recommended',
23+
'prettier/@typescript-eslint'
24+
],
25+
rules: {
26+
'@typescript-eslint/explicit-function-return-type': 'off',
27+
'@typescript-eslint/no-namespace': 'off' // maybe we should consider enabling it in the future
28+
}
29+
}
30+
]
31+
};

.github/workflows/main.yml

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ jobs:
4242
os:
4343
- ubuntu-latest
4444
- macos-latest
45-
# - windows-latest # to be uncommented when we drop multi-process mode
46-
node:
45+
- windows-latest
46+
node:
47+
- '6'
4748
- '8'
4849
- '10'
4950
- '12'
5051
packages:
51-
- webpack@^5.0.0-alpha.5 ts-loader@^5.0.0 vue-loader@^15.2.4
52+
- [email protected] ts-loader@^5.0.0 vue-loader@^15.2.4
5253
- webpack@^4.0.0 ts-loader@^5.0.0 vue-loader@^15.2.4
53-
- webpack@^3.10.0 ts-loader@^3.4.0 vue-loader@^13.5.0
54-
- webpack@^2.7.0 ts-loader@^3.4.0 vue-loader@^13.5.0
55-
54+
exclude:
55+
- node: '6'
56+
packages: '[email protected] ts-loader@^5.0.0 vue-loader@^15.2.4'
5657
steps:
5758
- uses: actions/checkout@v1
5859

@@ -73,10 +74,10 @@ jobs:
7374
${{ runner.os }}-node-${{ matrix.node }}-yarn-
7475
7576
- name: Install dependencies
76-
run: yarn install --frozen-lockfile
77-
77+
run: yarn install --frozen-lockfile --ignore-engines
78+
7879
- name: Replace dependencies
79-
run: yarn add ${{ matrix.packages }} -D
80+
run: yarn add ${{ matrix.packages }} -D --ignore-engines
8081

8182
- name: Download build artifact
8283
uses: actions/download-artifact@v1
@@ -104,24 +105,10 @@ jobs:
104105
with:
105106
node-version: 12
106107

107-
- name: Get yarn cache
108-
id: yarn-cache
109-
run: echo "::set-output name=dir::$(yarn cache dir)"
110-
111-
- uses: actions/cache@v1
112-
with:
113-
path: ${{ steps.yarn-cache.outputs.dir }}
114-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
115-
restore-keys: |
116-
${{ runner.os }}-yarn-
117-
118-
- name: Install dependencies
119-
run: yarn install --frozen-lockfile
120-
121108
- name: Download build artifact
122109
uses: actions/download-artifact@v1
123110
with:
124111
name: lib
125112

126113
- name: Release
127-
run: yarn exec semantic-release
114+
run: npx semantic-release@16.0.2

README.md

Lines changed: 27 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
## Installation
1717

18-
This plugin requires minimum **webpack 2.3**, **TypeScript 2.1** and optionally **ESLint 6.0.0** or **TSLint 4.0**
18+
This plugin requires minimum **Node.js 6.11.5**, **webpack 4**, **TypeScript 2.1** and optionally **ESLint 6** (which itself requires minimum **Node.js 8.10.0**)
19+
20+
If you depend on **webpack 2**, **webpack 3**, or **tslint 4**, please use [older version](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/tree/v3.1.1) of the plugin.
1921

2022
```sh
2123
# with npm
@@ -56,7 +58,7 @@ add `CheckerPlugin` and delegate checker to the separate process. The problem wi
5658
it was a lot slower than [ts-loader](https://github.com/TypeStrong/ts-loader) on an incremental build (~20s vs ~3s).
5759
Secondly, we used [tslint](https://palantir.github.io/tslint) and we wanted to run this, along with type checker, in a separate process.
5860
This is why this plugin was created. To provide better performance, the plugin reuses Abstract Syntax Trees between compilations and shares
59-
these trees with TSLint. It can be scaled with a multi-process mode to utilize maximum CPU power.
61+
these trees with TSLint.
6062

6163
## Modules resolution
6264

@@ -98,17 +100,6 @@ module.exports = {
98100

99101
There's a good explanation on setting up TypeScript ESLint support by Robert Cooper [here](https://dev.to/robertcoopercode/using-eslint-and-prettier-in-a-typescript-project-53jb).
100102

101-
## TSLint
102-
103-
*[TSLint is being replaced by ESLint](https://medium.com/palantir/tslint-in-2019-1a144c2317a9).
104-
https://eslint.org/blog/2019/01/future-typescript-eslint. As a consequence, support for TSLint in fork-ts-checker-webpack-plugin will be deprecated and removed in future versions of the plugin.*
105-
106-
If you have installed [tslint](https://palantir.github.io/tslint), you can enable it by setting `tslint: true` or
107-
`tslint: './path/to/tslint.json'`. We recommend changing `defaultSeverity` to a `"warning"` in `tslint.json` file.
108-
It helps to distinguish lints from TypeScript's diagnostics.
109-
110-
111-
112103
## Options
113104

114105
- **tsconfig** `string`:
@@ -124,37 +115,7 @@ It helps to distinguish lints from TypeScript's diagnostics.
124115
- **eslintOptions** `object`:
125116

126117
- Options that can be used to initialise ESLint. See https://eslint.org/docs/1.0.0/developer-guide/nodejs-api#cliengine
127-
128-
- **tslint** `string | true | undefined`:
129-
130-
- If `string`, path to _tslint.json_ file to check source files against.
131-
- If `true`, path to `tslint.json` file will be computed with respect to currently checked file, just like TSLint
132-
CLI would do. Suppose you have a project:
133-
134-
```
135-
./
136-
tslint.json
137-
138-
src/
139-
file.ts
140-
anotherFile.ts
141-
142-
lib/
143-
tslint.json
144-
someHelperFile.ts
145-
```
146-
147-
In such a case `src/file.ts` and `src/anotherFile.ts` would be checked against root `tslint.json`, and
148-
`src/lib/someHelperFile.ts` would be checked against `src/lib/tslint.json`.
149-
150-
Default: `undefined`.
151-
152-
- **tslintAutoFix** `boolean`:
153-
Passes on `--fix` flag while running `tslint` to auto fix linting errors. Default: false.
154-
155-
- **watch** `string | string[]`:
156-
Directories or files to watch by service. Not necessary but improves performance (reduces number of `fs.stat` calls). Not applicable when `useTypescriptIncrementalApi` is `true`, in which case watching is handled automatically.
157-
118+
158119
- **async** `boolean`:
159120
True by default - `async: false` can block webpack's emit to wait for type checker/linter and to add errors to the webpack's compilation.
160121
We recommend to set this to `false` in projects where type checking is faster than webpack's build - it's better for integration with other plugins. Another scenario where you might want to set this to `false` is if you use the `overlay` functionality of `webpack-dev-server`.
@@ -163,7 +124,7 @@ It helps to distinguish lints from TypeScript's diagnostics.
163124
List of TypeScript diagnostic codes to ignore.
164125

165126
- **ignoreLints** `string[]`:
166-
List of tslint rule names to ignore.
127+
List of eslint rule names to ignore.
167128

168129
- **ignoreLintWarnings** `boolean`:
169130
If true, will ignore all lint warnings.
@@ -178,15 +139,12 @@ new ForkTsCheckerWebpackPlugin({
178139
});
179140
```
180141

181-
- **colors** `boolean`:
182-
If `false`, disables built-in colors in logger messages. Default: `true`.
183-
184142
- **logger** `object`:
185143
Logger instance. It should be object that implements method: `error`, `warn`, `info`. Default: `console`.
186144

187-
- **formatter** `'default' | 'codeframe' | ((message: NormalizedMessage, useColors: boolean) => string)`:
188-
Formatter for diagnostics and lints. By default uses `default` formatter. You can also pass your own formatter as a function
189-
(see `src/NormalizedMessage.js` and `src/formatter/` for api reference).
145+
- **formatter** `'default' | 'codeframe' | (issue: Issue) => string)`:
146+
Formatter for issues and lints. By default uses `default` formatter. You can also pass your own formatter as a function
147+
(see `src/issue/` and `src/formatter/` for API reference).
190148

191149
- **formatterOptions** `object`:
192150
Options passed to formatters (currently only `codeframe` - see [available options](https://www.npmjs.com/package/babel-code-frame#options))
@@ -200,24 +158,17 @@ new ForkTsCheckerWebpackPlugin({
200158
- **memoryLimit** `number`:
201159
Memory limit for service process in MB. If service exits with allocation failed error, increase this number. Default: `2048`.
202160

203-
- **workers** `number`:
204-
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
205-
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 -
206-
node doesn't share memory between workers - keep in mind that memory usage will increase. Be aware that in some scenarios increasing workers
207-
number **can increase checking time**. Default: `ForkTsCheckerWebpackPlugin.ONE_CPU`.
208-
209161
- **vue** `boolean | { enabled: boolean, compiler: string }`:
210162
If `true` or `enabled: true`, the linter and compiler will process VueJs single-file-component (.vue) files. See the
211163
[Vue section](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#vue) further down for information on how to correctly setup your project.
212164

213165
- **useTypescriptIncrementalApi** `boolean`:
214-
If true, the plugin will use incremental compilation API introduced in TypeScript 2.7. In this mode you can only have 1
215-
worker, but if the changes in your code are small (like you normally have when you work in 'watch' mode), the compilation
216-
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.
166+
If true, the plugin will use incremental compilation API introduced in TypeScript 2.7. Defaults to `true` when working with TypeScript 3+ and `false` when below 3. The default can be overridden by directly specifying a value.
167+
Don't use it together with VueJs enabled - it's not supported yet.
217168

218169
- **measureCompilationTime** `boolean`:
219170
If true, the plugin will measure the time spent inside the compilation code. This may be useful to compare modes,
220-
especially if there are other loaders/plugins involved in the compilation. **requires node 8+**
171+
especially if there are other loaders/plugins involved in the compilation. **requires Node.js >= 8.5.0**
221172

222173
- **typescript** `string`:
223174
If supplied this is a custom path where `typescript` can be found. Defaults to `require.resolve('typescript')`.
@@ -266,13 +217,6 @@ new ForkTsCheckerWebpackPlugin({
266217

267218
</details>
268219

269-
### Pre-computed consts:
270-
271-
- `ForkTsCheckerWebpackPlugin.ONE_CPU` - always use one CPU
272-
- `ForkTsCheckerWebpackPlugin.ALL_CPUS` - always use all CPUs (will increase build time)
273-
- `ForkTsCheckerWebpackPlugin.ONE_CPU_FREE` - leave only one CPU for build (probably will increase build time)
274-
- `ForkTsCheckerWebpackPlugin.TWO_CPUS_FREE` - **recommended** - leave two CPUs free (one for build, one for system)
275-
276220
## Different behaviour in watch mode
277221

278222
If you turn on [webpacks watch mode](https://webpack.js.org/configuration/watch/#watch) the `fork-ts-checker-notifier-webpack-plugin` will take care of logging type errors, _not_ webpack itself. That means if you set `silent: true` you won't see type errors in your console in watch mode.
@@ -293,26 +237,21 @@ We hope this will be resolved in future; the issue can be tracked [here](https:/
293237

294238
This plugin provides some custom webpack hooks (all are sync):
295239

296-
| Event name | Hook Access Key | Description | Params |
297-
| --------------------------------------- | -------------------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
298-
| `fork-ts-checker-cancel` | `cancel` | Cancellation has been requested | `cancellationToken` |
299-
| `fork-ts-checker-waiting` | `waiting` | Waiting for results | `hasTsLint` |
300-
| `fork-ts-checker-service-before-start` | `serviceBeforeStart` | Async plugin that can be used for delaying `fork-ts-checker-service-start` | - |
301-
| `fork-ts-checker-service-start` | `serviceStart` | Service will be started | `tsconfigPath`, `tslintPath`, `watchPaths`, `workersNumber`, `memoryLimit` |
302-
| `fork-ts-checker-service-start-error` | `serviceStartError` | Cannot start service | `error` |
303-
| `fork-ts-checker-service-out-of-memory` | `serviceOutOfMemory` | Service is out of memory | - |
304-
| `fork-ts-checker-receive` | `receive` | Plugin receives diagnostics and lints from service | `diagnostics`, `lints` |
305-
| `fork-ts-checker-emit` | `emit` | Service will add errors and warnings to webpack compilation ('build' mode) | `diagnostics`, `lints`, `elapsed` |
306-
| `fork-ts-checker-done` | `done` | Service finished type checking and webpack finished compilation ('watch' mode) | `diagnostics`, `lints`, `elapsed` |
307-
308-
The **Event name** is there for backward compatibility with webpack 2/3. Regardless
309-
of the version of webpack (2, 3 or 4) you are using, we will always access plugin hooks with **Hook Access Keys** as
310-
described below.
240+
| Hook Access Key | Description | Params |
241+
| -------------------- | ------------------------------------------------------------------------------ | --------------------------------- |
242+
| `cancel` | Cancellation has been requested | `cancellationToken` |
243+
| `waiting` | Waiting for results | - |
244+
| `serviceBeforeStart` | Async plugin that can be used for delaying `fork-ts-checker-service-start` | - |
245+
| `serviceStart` | Service will be started | `tsconfigPath`, `memoryLimit` |
246+
| `serviceStartError` | Cannot start service | `error` |
247+
| `serviceOutOfMemory` | Service is out of memory | - |
248+
| `receive` | Plugin receives diagnostics and lints from service | `diagnostics`, `lints` |
249+
| `emit` | Service will add errors and warnings to webpack compilation ('build' mode) | `diagnostics`, `lints`, `elapsed` |
250+
| `done` | Service finished type checking and webpack finished compilation ('watch' mode) | `diagnostics`, `lints`, `elapsed` |
311251

312252
### Accessing plugin hooks
313253

314-
All plugin hooks are compatible with both [webpack](https://webpack.js.org) version
315-
4 and version 2. To access plugin hooks and tap into the event, we need to use
254+
To access plugin hooks and tap into the event, we need to use
316255
the `getCompilerHooks` static method. When we call this method with a [webpack compiler instance](https://webpack.js.org/api/node/),
317256
it returns the series of [tapable](https://github.com/webpack/tapable)
318257
hooks where you can pass in your callbacks.
@@ -404,14 +343,12 @@ if ('compilers' in compiler) {
404343

405344
```js
406345
new ForkTsCheckerWebpackPlugin({
407-
tslint: true,
408346
vue: true
409347
});
410348
```
411349
Optionally change default [vue-template-compiler](https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler) to [nativescript-vue-template-compiler](https://github.com/nativescript-vue/nativescript-vue/tree/master/packages/nativescript-vue-template-compiler) if you use [nativescript-vue](https://github.com/nativescript-vue/nativescript-vue)
412350
```
413351
new ForkTsCheckerWebpackPlugin({
414-
tslint: true,
415352
vue: { enabled: true, compiler: 'nativescript-vue-template-compiler' }
416353
});
417354
```
@@ -446,16 +383,7 @@ new ForkTsCheckerWebpackPlugin({
446383
},
447384
```
448385

449-
4. Add rules to your `tslint.json` and they will be applied to Vue files. For example, you could apply the Standard JS rules [tslint-config-standard](https://github.com/blakeembrey/tslint-config-standard) like this:
450-
451-
```json
452-
{
453-
"defaultSeverity": "error",
454-
"extends": ["tslint-config-standard"]
455-
}
456-
```
457-
458-
5. Ensure your `tsconfig.json` includes .vue files:
386+
4. Ensure your `tsconfig.json` includes .vue files:
459387

460388
```js
461389
// tsconfig.json
@@ -470,7 +398,7 @@ new ForkTsCheckerWebpackPlugin({
470398
}
471399
```
472400

473-
6. It accepts any wildcard in your TypeScript configuration:
401+
5. It accepts any wildcard in your TypeScript configuration:
474402

475403
```js
476404
// tsconfig.json
@@ -495,7 +423,7 @@ new ForkTsCheckerWebpackPlugin({
495423
import Hello from '@/components/hello.vue'
496424
```
497425

498-
7. If you are working in **VSCode**, you can get extensions [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur) and [TSLint Vue](https://marketplace.visualstudio.com/items?itemName=prograhammer.tslint-vue) to complete the developer workflow.
426+
6. If you are working in **VSCode**, you can get the [Vetur](https://marketplace.visualstudio.com/items?itemName=octref.vetur) extension to complete the developer workflow.
499427

500428
## Credits
501429

0 commit comments

Comments
 (0)