Skip to content

Commit 438a139

Browse files
committed
Merge branch 'main' of github.com:TypeStrong/fork-ts-checker-webpack-plugin into alpha
2 parents a195dd5 + 58ef473 commit 438a139

30 files changed

+36897
-90
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ master ]
16+
branches: [ main ]
1717
pull_request:
1818
# The branches below must be a subset of the branches above
19-
branches: [ master ]
19+
branches: [ main ]
2020
schedule:
2121
- cron: '42 12 * * 1'
2222

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
8484
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
8585
needs: [build, test]
86-
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta')
86+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta')
8787
steps:
8888
- uses: actions/checkout@v1
8989

CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Here is a summary of the steps to follow:
5757
2. If you cloned a while ago, get the latest changes from upstream and update dependencies:
5858

5959
```bash
60-
$ git checkout master
61-
$ git pull upstream master
60+
$ git checkout main
61+
$ git pull upstream main
6262
$ yarn install
6363
```
6464

@@ -75,7 +75,7 @@ $ git checkout -b <topic-branch-name>
7575
$ git push origin <topic-branch-name>
7676
```
7777

78-
6. [Open a Pull Request](https://help.github.com/articles/creating-a-pull-request/#creating-the-pull-request) to the `master` branch with a clear title and description.
78+
6. [Open a Pull Request](https://help.github.com/articles/creating-a-pull-request/#creating-the-pull-request) to the `main` branch with a clear title and description.
7979

8080
**Tips**:
8181

@@ -217,5 +217,5 @@ otherwise use **rebase and merge**.
217217

218218
### Releasing a stable version
219219

220-
Fixes and tested features from the `beta` branch can be merged with the `master` branch. Please ensure your branch is
221-
up to date with the `master` and then [open a Pull Request](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/master...).
220+
Fixes and tested features from the `beta` branch can be merged with the `main` branch. Please ensure your branch is
221+
up to date with the `main` and then [open a Pull Request](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/compare/main...).

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<p>Webpack plugin that runs TypeScript type checker on a separate process.</p>
55

66
[![npm version](https://img.shields.io/npm/v/fork-ts-checker-webpack-plugin.svg)](https://www.npmjs.com/package/fork-ts-checker-webpack-plugin)
7-
[![build status](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/workflows/CI/CD/badge.svg?branch=master&event=push)](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/actions?query=branch%3Amaster+event%3Apush)
7+
[![build status](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/workflows/CI/CD/badge.svg?branch=main&event=push)](https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/actions?query=branch%3Amain+event%3Apush)
88
[![downloads](http://img.shields.io/npm/dm/fork-ts-checker-webpack-plugin.svg)](https://npmjs.org/package/fork-ts-checker-webpack-plugin)
99
[![commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
1010
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
@@ -70,7 +70,6 @@ module.exports = {
7070

7171
It's very important to be aware that **this plugin uses [TypeScript](https://github.com/Microsoft/TypeScript)'s, not
7272
[webpack](https://github.com/webpack/webpack)'s modules resolution**. It means that you have to setup `tsconfig.json` correctly.
73-
For example if you set `files: ['./src/index.ts']` in `tsconfig.json`, this plugin will check only `index.ts` for errors.
7473

7574
> It's because of the performance - with TypeScript's module resolution we don't have to wait for webpack to compile files.
7675
>
@@ -137,13 +136,13 @@ you can place your configuration in the:
137136

138137
Options passed to the plugin constructor will overwrite options from the cosmiconfig (using [deepmerge](https://github.com/TehShrike/deepmerge)).
139138

140-
| Name | Type | Default value | Description |
141-
| ----------------- | --------------------- | ------------------------------------------------------------------ | ----------- |
142-
| `async` | `boolean` | `compiler.options.mode === 'development'` | If `true`, reports issues **after** webpack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the `watch` mode. |
143-
| `typescript` | `object` or `boolean` | `true` | If a `boolean`, it enables/disables TypeScript checker. If an `object`, see [TypeScript options](#typescript-options). |
144-
| `eslint` | `object` | `undefined` | If `undefined`, it disables ESLint linter. If an `object`, see [ESLint options](#eslint-options). |
145-
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
146-
| `formatter` | `string` or `object` | `codeframe` | Available formatters are `basic` and `codeframe`. To [configure](https://babeljs.io/docs/en/babel-code-frame#options) `codeframe` formatter, pass object: `{ type: 'codeframe', options: { <coderame options> } }`. |
139+
| Name | Type | Default value | Description |
140+
| ----------------- | ---------------------------------- | ------------------------------------------------------------------ | ----------- |
141+
| `async` | `boolean` | `compiler.options.mode === 'development'` | If `true`, reports issues **after** webpack's compilation is done. Thanks to that it doesn't block the compilation. Used only in the `watch` mode. |
142+
| `typescript` | `object` or `boolean` | `true` | If a `boolean`, it enables/disables TypeScript checker. If an `object`, see [TypeScript options](#typescript-options). |
143+
| `eslint` | `object` | `undefined` | If `undefined`, it disables ESLint linter. If an `object`, see [ESLint options](#eslint-options). |
144+
| `issue` | `object` | `{}` | See [Issues options](#issues-options). |
145+
| `formatter` | `string` or `object` or `function` | `codeframe` | Available formatters are `basic`, `codeframe` and a custom `function`. To [configure](https://babeljs.io/docs/en/babel-code-frame#options) `codeframe` formatter, pass object: `{ type: 'codeframe', options: { <coderame options> } }`. |
147146
| `logger` | `object` | `{ infrastructure: 'silent', issues: 'console', devServer: true }` | Available loggers are `silent`, `console`, and `webpack-infrastructure`. Infrastructure logger prints additional information, issue logger prints `issues` in the `async` mode. If `devServer` is set to `false`, errors will not be reported to Webpack Dev Server. |
148147

149148
### TypeScript options

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"cosmiconfig": "^6.0.0",
6868
"deepmerge": "^4.2.2",
6969
"fs-extra": "^9.0.0",
70+
"glob": "^7.1.6",
7071
"memfs": "^3.1.2",
7172
"minimatch": "^3.0.4",
7273
"schema-utils": "2.7.0",

release.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
branches: [
3-
'master',
3+
'main',
44
{
55
name: 'alpha',
66
prerelease: true,

src/eslint-reporter/reporter/EsLintReporter.ts

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,108 @@ import { CLIEngine, LintReport, LintResult } from '../types/eslint';
33
import { createIssuesFromEsLintResults } from '../issue/EsLintIssueFactory';
44
import { EsLintReporterConfiguration } from '../EsLintReporterConfiguration';
55
import { Reporter } from '../../reporter';
6+
import { normalize } from 'path';
67
import minimatch from 'minimatch';
8+
import glob from 'glob';
79

810
function createEsLintReporter(configuration: EsLintReporterConfiguration): Reporter {
911
// eslint-disable-next-line @typescript-eslint/no-var-requires
1012
const { CLIEngine } = require('eslint');
1113
const engine: CLIEngine = new CLIEngine(configuration.options);
1214

1315
let isInitialRun = true;
16+
let isInitialGetFiles = true;
17+
1418
const lintResults = new Map<string, LintResult>();
15-
const includedFilesPatterns = engine.resolveFileGlobPatterns(configuration.files);
19+
const includedGlobPatterns = engine.resolveFileGlobPatterns(configuration.files);
20+
const includedFiles = new Set<string>();
21+
22+
function isFileIncluded(path: string) {
23+
return (
24+
includedGlobPatterns.some((pattern) => minimatch(path, pattern)) &&
25+
!engine.isPathIgnored(path)
26+
);
27+
}
28+
29+
async function getFiles() {
30+
if (isInitialGetFiles) {
31+
isInitialGetFiles = false;
32+
33+
const resolvedGlobs = await Promise.all(
34+
includedGlobPatterns.map(
35+
(globPattern) =>
36+
new Promise<string[]>((resolve) => {
37+
glob(globPattern, (error, resolvedFiles) => {
38+
if (error) {
39+
// fail silently
40+
resolve([]);
41+
} else {
42+
resolve(resolvedFiles || []);
43+
}
44+
});
45+
})
46+
)
47+
);
48+
49+
for (const resolvedGlob of resolvedGlobs) {
50+
for (const resolvedFile of resolvedGlob) {
51+
if (isFileIncluded(resolvedFile)) {
52+
includedFiles.add(resolvedFile);
53+
}
54+
}
55+
}
56+
}
57+
58+
return Array.from(includedFiles);
59+
}
60+
61+
function getDirs() {
62+
return includedGlobPatterns || [];
63+
}
64+
65+
function getExtensions() {
66+
return configuration.options.extensions || [];
67+
}
1668

1769
return {
1870
getReport: async ({ changedFiles = [], deletedFiles = [] }) => {
1971
return {
2072
async getDependencies() {
73+
for (const changedFile of changedFiles) {
74+
if (isFileIncluded(changedFile)) {
75+
includedFiles.add(changedFile);
76+
}
77+
}
78+
for (const deletedFile of deletedFiles) {
79+
includedFiles.delete(deletedFile);
80+
}
81+
2182
return {
22-
files: [],
23-
dirs: [],
24-
extensions: [],
83+
files: (await getFiles()).map((file) => normalize(file)),
84+
dirs: getDirs().map((dir) => normalize(dir)),
85+
extensions: getExtensions(),
2586
};
2687
},
2788
async getIssues() {
2889
// cleanup old results
29-
changedFiles.forEach((changedFile) => {
90+
for (const changedFile of changedFiles) {
3091
lintResults.delete(changedFile);
31-
});
32-
deletedFiles.forEach((removedFile) => {
33-
lintResults.delete(removedFile);
34-
});
92+
}
93+
for (const deletedFile of deletedFiles) {
94+
lintResults.delete(deletedFile);
95+
}
3596

3697
// get reports
3798
const lintReports: LintReport[] = [];
3899

39100
if (isInitialRun) {
40-
lintReports.push(engine.executeOnFiles(includedFilesPatterns));
101+
lintReports.push(engine.executeOnFiles(includedGlobPatterns));
41102
isInitialRun = false;
42103
} else {
43104
// we need to take care to not lint files that are not included by the configuration.
44105
// the eslint engine will not exclude them automatically
45-
const changedAndIncludedFiles = changedFiles.filter(
46-
(changedFile) =>
47-
includedFilesPatterns.some((includedFilesPattern) =>
48-
minimatch(changedFile, includedFilesPattern)
49-
) &&
50-
(configuration.options.extensions || []).some((extension) =>
51-
changedFile.endsWith(extension)
52-
) &&
53-
!engine.isPathIgnored(changedFile)
106+
const changedAndIncludedFiles = changedFiles.filter((changedFile) =>
107+
isFileIncluded(changedFile)
54108
);
55109

56110
if (changedAndIncludedFiles.length) {
@@ -64,11 +118,11 @@ function createEsLintReporter(configuration: EsLintReporterConfiguration): Repor
64118
}
65119

66120
// store results
67-
lintReports.forEach((lintReport) => {
68-
lintReport.results.forEach((lintResult) => {
121+
for (const lintReport of lintReports) {
122+
for (const lintResult of lintReport.results) {
69123
lintResults.set(lintResult.filePath, lintResult);
70-
});
71-
});
124+
}
125+
}
72126

73127
// get actual list of previous and current reports
74128
const results = Array.from(lintResults.values());

src/formatter/FormatterConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type FormatterConfiguration = Formatter;
66

77
function createFormatterConfiguration(options: FormatterOptions | undefined) {
88
return createFormatter(
9-
options ? (typeof options === 'string' ? options : options.type || 'codeframe') : 'codeframe',
9+
options ? (typeof options === 'object' ? options.type || 'codeframe' : options) : 'codeframe',
1010
options && typeof options === 'object' ? options.options || {} : {}
1111
);
1212
}

src/formatter/FormatterFactory.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Formatter } from './Formatter';
22
import { BabelCodeFrameOptions, createCodeFrameFormatter } from './CodeFrameFormatter';
33
import { createBasicFormatter } from './BasicFormatter';
44

5-
type NotConfigurableFormatterType = undefined | 'basic';
5+
type NotConfigurableFormatterType = undefined | 'basic' | Formatter;
66
type ConfigurableFormatterType = 'codeframe';
77
type FormatterType = NotConfigurableFormatterType | ConfigurableFormatterType;
88

@@ -25,17 +25,21 @@ function createFormatter<T extends ConfigurableFormatterType>(
2525
function createFormatter<T extends FormatterType>(type: T, options?: object): Formatter;
2626
// declare function implementation
2727
function createFormatter(type?: FormatterType, options?: object): Formatter {
28-
switch (type) {
29-
case 'basic':
30-
case undefined:
31-
return createBasicFormatter();
28+
if (typeof type === 'function') {
29+
return type;
30+
}
3231

33-
case 'codeframe':
34-
return createCodeFrameFormatter(options);
32+
if (typeof type === 'undefined' || type === 'basic') {
33+
return createBasicFormatter();
34+
}
3535

36-
default:
37-
throw new Error(`Unknown "${type}" formatter. Available types are: basic, codeframe.`);
36+
if (type === 'codeframe') {
37+
return createCodeFrameFormatter(options);
3838
}
39+
40+
throw new Error(
41+
`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`
42+
);
3943
}
4044

4145
export {

src/formatter/types/babel__code-frame.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Base on the type definitions for @babel/code-frame 7.0
2-
// Project: https://github.com/babel/babel/tree/master/packages/babel-code-frame, https://babeljs.io
2+
// Project: https://github.com/babel/babel/tree/main/packages/babel-code-frame, https://babeljs.io
33
// Definitions by: Mohsen Azimi <https://github.com/mohsen1>
44
// Forbes Lindesay <https://github.com/ForbesLindesay>
55
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

0 commit comments

Comments
 (0)