fork-ts-checker-webpack-plugin 0.4.14 → 0.5.2

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +3 -0
  3. package/lib/{types/CancellationToken.d.ts → CancellationToken.d.ts} +4 -4
  4. package/lib/CancellationToken.js +28 -27
  5. package/lib/{types/FilesRegister.d.ts → FilesRegister.d.ts} +9 -14
  6. package/lib/FilesRegister.js +24 -24
  7. package/lib/{types/FilesWatcher.d.ts → FilesWatcher.d.ts} +4 -7
  8. package/lib/FilesWatcher.js +27 -29
  9. package/lib/FsHelper.d.ts +5 -0
  10. package/lib/FsHelper.js +20 -0
  11. package/lib/IncrementalChecker.d.ts +34 -0
  12. package/lib/IncrementalChecker.js +97 -109
  13. package/lib/{types/Message.d.ts → Message.d.ts} +0 -0
  14. package/lib/{types/NormalizedMessage.d.ts → NormalizedMessage.d.ts} +16 -23
  15. package/lib/NormalizedMessage.js +76 -86
  16. package/lib/{types/VueProgram.d.ts → VueProgram.d.ts} +0 -0
  17. package/lib/VueProgram.js +62 -77
  18. package/lib/{types/WorkResult.d.ts → WorkResult.d.ts} +6 -6
  19. package/lib/WorkResult.js +22 -25
  20. package/lib/{types/WorkSet.d.ts → WorkSet.d.ts} +6 -6
  21. package/lib/WorkSet.js +6 -7
  22. package/lib/{types/cluster.d.ts → cluster.d.ts} +0 -0
  23. package/lib/cluster.js +19 -19
  24. package/lib/{types/formatter → formatter}/codeframeFormatter.d.ts +0 -0
  25. package/lib/formatter/codeframeFormatter.js +17 -16
  26. package/lib/{types/formatter → formatter}/defaultFormatter.d.ts +0 -0
  27. package/lib/formatter/defaultFormatter.js +9 -9
  28. package/lib/index.d.ts +98 -0
  29. package/lib/index.js +183 -192
  30. package/lib/{types/service.d.ts → service.d.ts} +0 -0
  31. package/lib/service.js +11 -11
  32. package/package.json +14 -18
  33. package/lib/types/IncrementalChecker.d.ts +0 -43
  34. package/lib/types/index.d.ts +0 -101
package/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## v0.5.2
2
+
3
+ * [Fix erroneous error on diagnostics at 0 line; remove deprecated fs.existsSync](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/190) (#190)
4
+
5
+ ## v0.5.1
6
+
7
+ * [Make the checker compile with TypeScript 3.2](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/189)
8
+
9
+ ## 0.5.0
10
+
11
+ * Removed unused dependency `resolve`.
12
+ * Replace `lodash` usage with native calls.
13
+ * ** Breaking Changes**:
14
+ * Removed all getters from `NormalizedMessage`, use direct property access instead.
15
+ * **Internal**:
16
+ * Test against ts-loader v5
17
+ * Enable all strict type checks
18
+ * Update dev dependencies
19
+
20
+ ## v0.4.15
21
+
22
+ * [Add `tslintAutoFix` option to be passed on to tslint to auto format typescript files](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/174) (#174)
23
+
1
24
  ## v0.4.14
2
25
 
3
26
  * [Add support for `reportFiles` option](https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/179) (#179)
package/README.md CHANGED
@@ -66,6 +66,9 @@ Allows overriding TypeScript options. Should be specified in the same format as
66
66
  * **tslint** `string | true`:
67
67
  Path to *tslint.json* file or `true`. If `true`, uses `path.resolve(compiler.options.context, './tslint.json')`. Default: `undefined`.
68
68
 
69
+ * **tslintAutoFix** `boolean `:
70
+ Passes on `--fix` flag while running `tslint` to auto fix linting errors. Default: false.
71
+
69
72
  * **watch** `string | string[]`:
70
73
  Directories or files to watch by service. Not necessary but improves performance (reduces number of `fs.stat` calls).
71
74
 
@@ -3,10 +3,10 @@ interface CancellationTokenData {
3
3
  cancellationFileName: string;
4
4
  }
5
5
  export declare class CancellationToken {
6
- isCancelled: boolean;
7
- cancellationFileName: string;
8
- lastCancellationCheckTime: number;
9
- constructor(cancellationFileName: string, isCancelled: boolean);
6
+ private isCancelled;
7
+ private cancellationFileName;
8
+ private lastCancellationCheckTime;
9
+ constructor(cancellationFileName?: string, isCancelled?: boolean);
10
10
  static createFromJSON(json: CancellationTokenData): CancellationToken;
11
11
  toJSON(): {
12
12
  cancellationFileName: string;
@@ -1,57 +1,58 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var crypto = require("crypto");
4
- var fs = require("fs");
5
- var os = require("os");
6
- var path = require("path");
7
- var ts = require("typescript");
8
- var CancellationToken = /** @class */ (function () {
9
- function CancellationToken(cancellationFileName, isCancelled) {
3
+ const crypto = require("crypto");
4
+ const fs = require("fs");
5
+ const os = require("os");
6
+ const path = require("path");
7
+ const ts = require("typescript");
8
+ const FsHelper_1 = require("./FsHelper");
9
+ class CancellationToken {
10
+ constructor(cancellationFileName, isCancelled) {
10
11
  this.isCancelled = !!isCancelled;
11
12
  this.cancellationFileName =
12
13
  cancellationFileName || crypto.randomBytes(64).toString('hex');
13
14
  this.lastCancellationCheckTime = 0;
14
15
  }
15
- CancellationToken.createFromJSON = function (json) {
16
+ static createFromJSON(json) {
16
17
  return new CancellationToken(json.cancellationFileName, json.isCancelled);
17
- };
18
- CancellationToken.prototype.toJSON = function () {
18
+ }
19
+ toJSON() {
19
20
  return {
20
21
  cancellationFileName: this.cancellationFileName,
21
22
  isCancelled: this.isCancelled
22
23
  };
23
- };
24
- CancellationToken.prototype.getCancellationFilePath = function () {
24
+ }
25
+ getCancellationFilePath() {
25
26
  return path.join(os.tmpdir(), this.cancellationFileName);
26
- };
27
- CancellationToken.prototype.isCancellationRequested = function () {
27
+ }
28
+ isCancellationRequested() {
28
29
  if (this.isCancelled) {
29
30
  return true;
30
31
  }
31
- var time = Date.now();
32
- var duration = Math.abs(time - this.lastCancellationCheckTime);
32
+ const time = Date.now();
33
+ const duration = Math.abs(time - this.lastCancellationCheckTime);
33
34
  if (duration > 10) {
34
35
  // check no more than once every 10ms
35
36
  this.lastCancellationCheckTime = time;
36
- this.isCancelled = fs.existsSync(this.getCancellationFilePath());
37
+ this.isCancelled = FsHelper_1.FsHelper.existsSync(this.getCancellationFilePath());
37
38
  }
38
39
  return this.isCancelled;
39
- };
40
- CancellationToken.prototype.throwIfCancellationRequested = function () {
40
+ }
41
+ throwIfCancellationRequested() {
41
42
  if (this.isCancellationRequested()) {
42
43
  throw new ts.OperationCanceledException();
43
44
  }
44
- };
45
- CancellationToken.prototype.requestCancellation = function () {
45
+ }
46
+ requestCancellation() {
46
47
  fs.writeFileSync(this.getCancellationFilePath(), '');
47
48
  this.isCancelled = true;
48
- };
49
- CancellationToken.prototype.cleanupCancellation = function () {
50
- if (this.isCancelled && fs.existsSync(this.getCancellationFilePath())) {
49
+ }
50
+ cleanupCancellation() {
51
+ if (this.isCancelled &&
52
+ FsHelper_1.FsHelper.existsSync(this.getCancellationFilePath())) {
51
53
  fs.unlinkSync(this.getCancellationFilePath());
52
54
  this.isCancelled = false;
53
55
  }
54
- };
55
- return CancellationToken;
56
- }());
56
+ }
57
+ }
57
58
  exports.CancellationToken = CancellationToken;
@@ -1,30 +1,25 @@
1
1
  import * as ts from 'typescript';
2
- interface DataShape {
3
- source: ts.SourceFile;
2
+ import { RuleFailure } from 'tslint';
3
+ export interface DataShape {
4
+ source?: ts.SourceFile;
4
5
  linted: boolean;
5
- lints: any[];
6
+ lints: RuleFailure[];
6
7
  }
7
8
  export declare class FilesRegister {
8
- files: {
9
- [filePath: string]: {
10
- mtime: number;
11
- data: DataShape;
12
- };
13
- };
14
- dataFactory: (_data?: any) => DataShape;
15
- constructor(dataFactory: (_data?: any) => DataShape);
9
+ private dataFactory;
10
+ private files;
11
+ constructor(dataFactory: (_data?: DataShape) => DataShape);
16
12
  keys(): string[];
17
13
  add(filePath: string): void;
18
14
  remove(filePath: string): void;
19
15
  has(filePath: string): boolean;
20
16
  get(filePath: string): {
21
- mtime: number;
17
+ mtime?: number | undefined;
22
18
  data: DataShape;
23
19
  };
24
20
  ensure(filePath: string): void;
25
21
  getData(filePath: string): DataShape;
26
22
  mutateData(filePath: string, mutator: (data: DataShape) => void): void;
27
- getMtime(filePath: string): number;
23
+ getMtime(filePath: string): number | undefined;
28
24
  setMtime(filePath: string, mtime: number): void;
29
25
  }
30
- export {};
@@ -1,56 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var FilesRegister = /** @class */ (function () {
4
- function FilesRegister(dataFactory) {
3
+ class FilesRegister {
4
+ constructor(dataFactory) {
5
+ this.dataFactory = dataFactory;
5
6
  this.files = {};
6
7
  this.dataFactory = dataFactory;
7
8
  }
8
- FilesRegister.prototype.keys = function () {
9
+ keys() {
9
10
  return Object.keys(this.files);
10
- };
11
- FilesRegister.prototype.add = function (filePath) {
11
+ }
12
+ add(filePath) {
12
13
  this.files[filePath] = {
13
14
  mtime: undefined,
14
15
  data: this.dataFactory(undefined)
15
16
  };
16
- };
17
- FilesRegister.prototype.remove = function (filePath) {
17
+ }
18
+ remove(filePath) {
18
19
  if (this.has(filePath)) {
19
20
  delete this.files[filePath];
20
21
  }
21
- };
22
- FilesRegister.prototype.has = function (filePath) {
22
+ }
23
+ has(filePath) {
23
24
  return this.files.hasOwnProperty(filePath);
24
- };
25
- FilesRegister.prototype.get = function (filePath) {
25
+ }
26
+ get(filePath) {
26
27
  if (!this.has(filePath)) {
27
28
  throw new Error('File "' + filePath + '" not found in register.');
28
29
  }
29
30
  return this.files[filePath];
30
- };
31
- FilesRegister.prototype.ensure = function (filePath) {
31
+ }
32
+ ensure(filePath) {
32
33
  if (!this.has(filePath)) {
33
34
  this.add(filePath);
34
35
  }
35
- };
36
- FilesRegister.prototype.getData = function (filePath) {
36
+ }
37
+ getData(filePath) {
37
38
  return this.get(filePath).data;
38
- };
39
- FilesRegister.prototype.mutateData = function (filePath, mutator) {
39
+ }
40
+ mutateData(filePath, mutator) {
40
41
  this.ensure(filePath);
41
42
  mutator(this.files[filePath].data);
42
- };
43
- FilesRegister.prototype.getMtime = function (filePath) {
43
+ }
44
+ getMtime(filePath) {
44
45
  return this.get(filePath).mtime;
45
- };
46
- FilesRegister.prototype.setMtime = function (filePath, mtime) {
46
+ }
47
+ setMtime(filePath, mtime) {
47
48
  this.ensure(filePath);
48
49
  if (this.files[filePath].mtime !== mtime) {
49
50
  this.files[filePath].mtime = mtime;
50
51
  // file has been changed - we have to reset data
51
52
  this.files[filePath].data = this.dataFactory(this.files[filePath].data);
52
53
  }
53
- };
54
- return FilesRegister;
55
- }());
54
+ }
55
+ }
56
56
  exports.FilesRegister = FilesRegister;
@@ -1,11 +1,8 @@
1
- import * as chokidar from 'chokidar';
2
1
  export declare class FilesWatcher {
3
- watchPaths: string[];
4
- watchExtensions: string[];
5
- watchers: chokidar.FSWatcher[];
6
- listeners: {
7
- [eventName: string]: Function[];
8
- };
2
+ private watchPaths;
3
+ private watchExtensions;
4
+ private watchers;
5
+ private listeners;
9
6
  constructor(watchPaths: string[], watchExtensions: string[]);
10
7
  isFileSupported(filePath: string): boolean;
11
8
  watch(): void;
@@ -1,61 +1,59 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var chokidar = require("chokidar");
4
- var path = require("path");
5
- var startsWith = require("lodash/startsWith");
6
- var FilesWatcher = /** @class */ (function () {
7
- function FilesWatcher(watchPaths, watchExtensions) {
3
+ const chokidar = require("chokidar");
4
+ const path = require("path");
5
+ class FilesWatcher {
6
+ constructor(watchPaths, watchExtensions) {
8
7
  this.watchPaths = watchPaths;
9
8
  this.watchExtensions = watchExtensions;
9
+ this.watchExtensions = watchExtensions;
10
10
  this.watchers = [];
11
11
  this.listeners = {};
12
12
  }
13
- FilesWatcher.prototype.isFileSupported = function (filePath) {
13
+ isFileSupported(filePath) {
14
14
  return this.watchExtensions.indexOf(path.extname(filePath)) !== -1;
15
- };
16
- FilesWatcher.prototype.watch = function () {
17
- var _this = this;
15
+ }
16
+ watch() {
18
17
  if (this.isWatching()) {
19
18
  throw new Error('Cannot watch again - already watching.');
20
19
  }
21
- this.watchers = this.watchPaths.map(function (watchPath) {
20
+ this.watchers = this.watchPaths.map((watchPath) => {
22
21
  return chokidar
23
22
  .watch(watchPath, { persistent: true, alwaysStat: true })
24
- .on('change', function (filePath, stats) {
25
- if (_this.isFileSupported(filePath)) {
26
- (_this.listeners['change'] || []).forEach(function (changeListener) {
23
+ .on('change', (filePath, stats) => {
24
+ if (this.isFileSupported(filePath)) {
25
+ (this.listeners['change'] || []).forEach(changeListener => {
27
26
  changeListener(filePath, stats);
28
27
  });
29
28
  }
30
29
  })
31
- .on('unlink', function (filePath) {
32
- if (_this.isFileSupported(filePath)) {
33
- (_this.listeners['unlink'] || []).forEach(function (unlinkListener) {
30
+ .on('unlink', (filePath) => {
31
+ if (this.isFileSupported(filePath)) {
32
+ (this.listeners['unlink'] || []).forEach(unlinkListener => {
34
33
  unlinkListener(filePath);
35
34
  });
36
35
  }
37
36
  });
38
37
  });
39
- };
40
- FilesWatcher.prototype.isWatchingFile = function (filePath) {
38
+ }
39
+ isWatchingFile(filePath) {
41
40
  return (this.isWatching() &&
42
41
  this.isFileSupported(filePath) &&
43
- this.watchPaths.some(function (watchPath) { return startsWith(filePath, watchPath); }));
44
- };
45
- FilesWatcher.prototype.isWatching = function () {
42
+ this.watchPaths.some(watchPath => filePath.startsWith(watchPath)));
43
+ }
44
+ isWatching() {
46
45
  return this.watchers.length > 0;
47
- };
48
- FilesWatcher.prototype.on = function (event, listener) {
46
+ }
47
+ on(event, listener) {
49
48
  if (!this.listeners[event]) {
50
49
  this.listeners[event] = [];
51
50
  }
52
51
  this.listeners[event].push(listener);
53
- };
54
- FilesWatcher.prototype.off = function (event, listener) {
52
+ }
53
+ off(event, listener) {
55
54
  if (this.listeners[event]) {
56
- this.listeners[event] = this.listeners[event].filter(function (oldListener) { return oldListener !== listener; });
55
+ this.listeners[event] = this.listeners[event].filter(oldListener => oldListener !== listener);
57
56
  }
58
- };
59
- return FilesWatcher;
60
- }());
57
+ }
58
+ }
61
59
  exports.FilesWatcher = FilesWatcher;
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import * as fs from 'fs';
3
+ export declare class FsHelper {
4
+ static existsSync(filePath: fs.PathLike): boolean;
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ class FsHelper {
5
+ static existsSync(filePath) {
6
+ try {
7
+ fs.statSync(filePath);
8
+ }
9
+ catch (err) {
10
+ if (err.code === 'ENOENT') {
11
+ return false;
12
+ }
13
+ else {
14
+ throw err;
15
+ }
16
+ }
17
+ return true;
18
+ }
19
+ }
20
+ exports.FsHelper = FsHelper;
@@ -0,0 +1,34 @@
1
+ import * as ts from 'typescript';
2
+ import { NormalizedMessage } from './NormalizedMessage';
3
+ import { CancellationToken } from './CancellationToken';
4
+ import * as minimatch from 'minimatch';
5
+ export declare class IncrementalChecker {
6
+ private programConfigFile;
7
+ private compilerOptions;
8
+ private linterConfigFile;
9
+ private linterAutoFix;
10
+ private watchPaths;
11
+ private workNumber;
12
+ private workDivision;
13
+ private checkSyntacticErrors;
14
+ private vue;
15
+ private files;
16
+ private linter?;
17
+ private linterConfig?;
18
+ private linterExclusions;
19
+ private program?;
20
+ private programConfig?;
21
+ private watcher?;
22
+ constructor(programConfigFile: string, compilerOptions: object, linterConfigFile: string | false, linterAutoFix: boolean, watchPaths: string[], workNumber?: number, workDivision?: number, checkSyntacticErrors?: boolean, vue?: boolean);
23
+ static loadProgramConfig(configFile: string, compilerOptions: object): ts.ParsedCommandLine;
24
+ private static loadLinterConfig;
25
+ private static createProgram;
26
+ private createLinter;
27
+ hasLinter(): boolean;
28
+ static isFileExcluded(filePath: string, linterExclusions: minimatch.IMinimatch[]): boolean;
29
+ nextIteration(): void;
30
+ private loadVueProgram;
31
+ private loadDefaultProgram;
32
+ getDiagnostics(cancellationToken: CancellationToken): NormalizedMessage[];
33
+ getLints(cancellationToken: CancellationToken): NormalizedMessage[];
34
+ }