fork-ts-checker-webpack-plugin 6.3.6 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -157,7 +157,7 @@ Options for the TypeScript checker (`typescript` option object).
157
157
  | `configOverwrite` | `object` | `{ compilerOptions: { skipLibCheck: true, sourceMap: false, inlineSourceMap: false, declarationMap: false } }` | This configuration will overwrite configuration from the `tsconfig.json` file. Supported fields are: `extends`, `compilerOptions`, `include`, `exclude`, `files`, and `references`. |
158
158
  | `context` | `string` | `dirname(configuration.configFile)` | The base path for finding files specified in the `tsconfig.json`. Same as the `context` option from the [ts-loader](https://github.com/TypeStrong/ts-loader#context). Useful if you want to keep your `tsconfig.json` in an external package. Keep in mind that **not** having a `tsconfig.json` in your project root can cause different behaviour between `fork-ts-checker-webpack-plugin` and `tsc`. When using editors like `VS Code` it is advised to add a `tsconfig.json` file to the root of the project and extend the config file referenced in option `configFile`. |
159
159
  | `build` | `boolean` | `false` | The equivalent of the `--build` flag for the `tsc` command. |
160
- | `mode` | `'readonly'` or `'write-tsbuildinfo'` or `'write-references'` | `'write-tsbuildinfo'` | If you use the `babel-loader`, it's recommended to use `write-references` mode to improve initial compilation time. If you use `ts-loader`, it's recommended to use `write-tsbuildinfo` mode to not overwrite files emitted by the `ts-loader`. |
160
+ | `mode` | `'readonly'` or `'write-tsbuildinfo'` or `'write-dts'` or `'write-references'` | `'write-tsbuildinfo'` | If you use the `babel-loader`, it's recommended to use `write-references` mode to improve initial compilation time. If you use `ts-loader`, it's recommended to use `write-tsbuildinfo` mode to not overwrite files emitted by the `ts-loader`. If you use `ts-loader` with `transpileOnly` flag set to `true`, use `'write-dts` to emit the type definition files. |
161
161
  | `diagnosticOptions` | `object` | `{ syntactic: false, semantic: true, declaration: false, global: false }` | Settings to select which diagnostics do we want to perform. |
162
162
  | `extensions` | `object` | `{}` | See [TypeScript extensions options](#typescript-extensions-options). |
163
163
  | `profile` | `boolean` | `false` | Measures and prints timings related to the TypeScript performance. |
@@ -76,7 +76,7 @@ exports.ForkTsCheckerWebpackPlugin = ForkTsCheckerWebpackPlugin;
76
76
  /**
77
77
  * Current version of the plugin
78
78
  */
79
- ForkTsCheckerWebpackPlugin.version = '6.3.6'; // will be replaced by the @semantic-release/exec
79
+ ForkTsCheckerWebpackPlugin.version = '6.5.0'; // will be replaced by the @semantic-release/exec
80
80
  /**
81
81
  * Default pools for the plugin concurrency limit
82
82
  */
@@ -138,8 +138,8 @@
138
138
  },
139
139
  "mode": {
140
140
  "type": "string",
141
- "enum": ["readonly", "write-tsbuildinfo", "write-references"],
142
- "description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files and `write-references` which writes both .tsbuildinfo and referenced projects output"
141
+ "enum": ["readonly", "write-tsbuildinfo", "write-dts", "write-references"],
142
+ "description": "`readonly` keeps all emitted files in memory, `write-tsbuildinfo` which writes only .tsbuildinfo files, `write-dts` writes .tsbuildinfo and type definition files, and `write-references` which writes both .tsbuildinfo and referenced projects output"
143
143
  },
144
144
  "compilerOptions": {
145
145
  "type": "object",
@@ -13,22 +13,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const EsLintIssueFactory_1 = require("../issue/EsLintIssueFactory");
16
- const path_1 = require("path");
16
+ const path_1 = __importDefault(require("path"));
17
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
18
  const minimatch_1 = __importDefault(require("minimatch"));
18
19
  const glob_1 = __importDefault(require("glob"));
20
+ const isOldCLIEngine = (eslint) => eslint.resolveFileGlobPatterns !== undefined;
19
21
  function createEsLintReporter(configuration) {
20
22
  // eslint-disable-next-line @typescript-eslint/no-var-requires
21
- const { CLIEngine } = require('eslint');
22
- const engine = new CLIEngine(configuration.options);
23
+ const { CLIEngine, ESLint } = require('eslint');
24
+ const eslint = ESLint
25
+ ? new ESLint(configuration.options)
26
+ : new CLIEngine(configuration.options);
23
27
  let isInitialRun = true;
24
28
  let isInitialGetFiles = true;
25
29
  const lintResults = new Map();
26
- const includedGlobPatterns = engine.resolveFileGlobPatterns(configuration.files);
30
+ const includedGlobPatterns = resolveFileGlobPatterns(configuration.files);
27
31
  const includedFiles = new Set();
28
32
  function isFileIncluded(path) {
29
- return (!path.includes('node_modules') &&
30
- includedGlobPatterns.some((pattern) => minimatch_1.default(path, pattern)) &&
31
- !engine.isPathIgnored(path));
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ return (!path.includes('node_modules') &&
35
+ includedGlobPatterns.some((pattern) => minimatch_1.default(path, pattern)) &&
36
+ !(yield eslint.isPathIgnored(path)));
37
+ });
32
38
  }
33
39
  function getFiles() {
34
40
  return __awaiter(this, void 0, void 0, function* () {
@@ -47,7 +53,7 @@ function createEsLintReporter(configuration) {
47
53
  })));
48
54
  for (const resolvedGlob of resolvedGlobs) {
49
55
  for (const resolvedFile of resolvedGlob) {
50
- if (isFileIncluded(resolvedFile)) {
56
+ if (yield isFileIncluded(resolvedFile)) {
51
57
  includedFiles.add(resolvedFile);
52
58
  }
53
59
  }
@@ -62,13 +68,40 @@ function createEsLintReporter(configuration) {
62
68
  function getExtensions() {
63
69
  return configuration.options.extensions || [];
64
70
  }
71
+ // Copied from the eslint 6 implementation, as it's not available in eslint 8
72
+ function resolveFileGlobPatterns(globPatterns) {
73
+ if (configuration.options.globInputPaths === false) {
74
+ return globPatterns.filter(Boolean);
75
+ }
76
+ const extensions = getExtensions().map((ext) => ext.replace(/^\./u, ''));
77
+ const dirSuffix = `/**/*.{${extensions.join(',')}}`;
78
+ return globPatterns.filter(Boolean).map((globPattern) => {
79
+ const resolvedPath = path_1.default.resolve(configuration.options.cwd || '', globPattern);
80
+ const newPath = directoryExists(resolvedPath)
81
+ ? globPattern.replace(/[/\\]$/u, '') + dirSuffix
82
+ : globPattern;
83
+ return path_1.default.normalize(newPath).replace(/\\/gu, '/');
84
+ });
85
+ }
86
+ // Copied from the eslint 6 implementation, as it's not available in eslint 8
87
+ function directoryExists(resolvedPath) {
88
+ try {
89
+ return fs_extra_1.default.statSync(resolvedPath).isDirectory();
90
+ }
91
+ catch (error) {
92
+ if (error && error.code === 'ENOENT') {
93
+ return false;
94
+ }
95
+ throw error;
96
+ }
97
+ }
65
98
  return {
66
99
  getReport: ({ changedFiles = [], deletedFiles = [] }) => __awaiter(this, void 0, void 0, function* () {
67
100
  return {
68
101
  getDependencies() {
69
102
  return __awaiter(this, void 0, void 0, function* () {
70
103
  for (const changedFile of changedFiles) {
71
- if (isFileIncluded(changedFile)) {
104
+ if (yield isFileIncluded(changedFile)) {
72
105
  includedFiles.add(changedFile);
73
106
  }
74
107
  }
@@ -76,8 +109,8 @@ function createEsLintReporter(configuration) {
76
109
  includedFiles.delete(deletedFile);
77
110
  }
78
111
  return {
79
- files: (yield getFiles()).map((file) => path_1.normalize(file)),
80
- dirs: getDirs().map((dir) => path_1.normalize(dir)),
112
+ files: (yield getFiles()).map((file) => path_1.default.normalize(file)),
113
+ dirs: getDirs().map((dir) => path_1.default.normalize(dir)),
81
114
  excluded: [],
82
115
  extensions: getExtensions(),
83
116
  };
@@ -95,20 +128,33 @@ function createEsLintReporter(configuration) {
95
128
  // get reports
96
129
  const lintReports = [];
97
130
  if (isInitialRun) {
98
- lintReports.push(engine.executeOnFiles(includedGlobPatterns));
131
+ const lintReport = yield (isOldCLIEngine(eslint)
132
+ ? Promise.resolve(eslint.executeOnFiles(includedGlobPatterns))
133
+ : eslint.lintFiles(includedGlobPatterns).then((results) => ({ results })));
134
+ lintReports.push(lintReport);
99
135
  isInitialRun = false;
100
136
  }
101
137
  else {
102
138
  // we need to take care to not lint files that are not included by the configuration.
103
139
  // the eslint engine will not exclude them automatically
104
- const changedAndIncludedFiles = changedFiles.filter((changedFile) => isFileIncluded(changedFile));
140
+ const changedAndIncludedFiles = [];
141
+ for (const changedFile of changedFiles) {
142
+ if (yield isFileIncluded(changedFile)) {
143
+ changedAndIncludedFiles.push(changedFile);
144
+ }
145
+ }
105
146
  if (changedAndIncludedFiles.length) {
106
- lintReports.push(engine.executeOnFiles(changedAndIncludedFiles));
147
+ const lintReport = yield (isOldCLIEngine(eslint)
148
+ ? Promise.resolve(eslint.executeOnFiles(changedAndIncludedFiles))
149
+ : eslint.lintFiles(changedAndIncludedFiles).then((results) => ({ results })));
150
+ lintReports.push(lintReport);
107
151
  }
108
152
  }
109
153
  // output fixes if `fix` option is provided
110
154
  if (configuration.options.fix) {
111
- yield Promise.all(lintReports.map((lintReport) => CLIEngine.outputFixes(lintReport)));
155
+ yield Promise.all(lintReports.map((lintReport) => isOldCLIEngine(eslint)
156
+ ? CLIEngine.outputFixes(lintReport)
157
+ : ESLint.outputFixes(lintReport.results)));
112
158
  }
113
159
  // store results
114
160
  for (const lintReport of lintReports) {
@@ -23,6 +23,12 @@ export interface CLIEngine {
23
23
  resolveFileGlobPatterns(filesPatterns: string[]): string[];
24
24
  isPathIgnored(filePath: string): boolean;
25
25
  }
26
+ export interface ESLint {
27
+ version: string;
28
+ lintFiles(filesPatterns: string[]): Promise<LintResult[]>;
29
+ isPathIgnored(filePath: string): Promise<boolean>;
30
+ }
31
+ export declare type ESLintOrCLIEngine = CLIEngine | ESLint;
26
32
  export interface CLIEngineOptions {
27
33
  cwd?: string;
28
34
  extensions?: string[];
@@ -10,7 +10,7 @@ interface TypeScriptReporterConfiguration {
10
10
  configOverwrite: TypeScriptConfigurationOverwrite;
11
11
  build: boolean;
12
12
  context: string;
13
- mode: 'readonly' | 'write-tsbuildinfo' | 'write-references';
13
+ mode: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
14
14
  diagnosticOptions: TypeScriptDiagnosticsOptions;
15
15
  extensions: {
16
16
  vue: TypeScriptVueExtensionConfiguration;
@@ -8,7 +8,7 @@ declare type TypeScriptReporterOptions = boolean | {
8
8
  configOverwrite?: TypeScriptConfigurationOverwrite;
9
9
  context?: string;
10
10
  build?: boolean;
11
- mode?: 'readonly' | 'write-tsbuildinfo' | 'write-references';
11
+ mode?: 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
12
12
  diagnosticOptions?: Partial<TypeScriptDiagnosticsOptions>;
13
13
  extensions?: {
14
14
  vue?: TypeScriptVueExtensionOptions;
@@ -16,6 +16,6 @@ interface ControlledTypeScriptSystem extends ts.System {
16
16
  waitForQueued(): Promise<void>;
17
17
  setArtifacts(artifacts: FilesMatch): void;
18
18
  }
19
- declare type FileSystemMode = 'readonly' | 'write-tsbuildinfo' | 'write-references';
19
+ declare type FileSystemMode = 'readonly' | 'write-tsbuildinfo' | 'write-dts' | 'write-references';
20
20
  declare function createControlledTypeScriptSystem(typescript: typeof ts, mode?: FileSystemMode): ControlledTypeScriptSystem;
21
21
  export { createControlledTypeScriptSystem, ControlledTypeScriptSystem };
@@ -113,7 +113,9 @@ function createControlledTypeScriptSystem(typescript, mode = 'readonly') {
113
113
  }
114
114
  function getWriteFileSystem(path) {
115
115
  if (mode === 'write-references' ||
116
- (mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo'))) {
116
+ (mode === 'write-tsbuildinfo' && path.endsWith('.tsbuildinfo')) ||
117
+ (mode === 'write-dts' &&
118
+ ['.tsbuildinfo', '.d.ts', '.d.ts.map'].some((prefix) => path.endsWith(prefix)))) {
117
119
  return realFileSystem;
118
120
  }
119
121
  return passiveFileSystem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fork-ts-checker-webpack-plugin",
3
- "version": "6.3.6",
3
+ "version": "6.5.0",
4
4
  "description": "Runs typescript type checker and linter on separate process.",
5
5
  "keywords": [
6
6
  "fast",