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/lib/VueProgram.js CHANGED
@@ -1,52 +1,39 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- var fs = require("fs");
15
- var path = require("path");
16
- var ts = require("typescript");
17
- var VueProgram = /** @class */ (function () {
18
- function VueProgram() {
19
- }
20
- VueProgram.loadProgramConfig = function (configFile, compilerOptions) {
21
- var extraExtensions = ['vue'];
22
- var parseConfigHost = {
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const ts = require("typescript");
6
+ class VueProgram {
7
+ static loadProgramConfig(configFile, compilerOptions) {
8
+ const extraExtensions = ['vue'];
9
+ const parseConfigHost = {
23
10
  fileExists: ts.sys.fileExists,
24
11
  readFile: ts.sys.readFile,
25
12
  useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
26
- readDirectory: function (rootDir, extensions, excludes, includes, depth) {
13
+ readDirectory: (rootDir, extensions, excludes, includes, depth) => {
27
14
  return ts.sys.readDirectory(rootDir, extensions.concat(extraExtensions), excludes, includes, depth);
28
15
  }
29
16
  };
30
- var tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
17
+ const tsconfig = ts.readConfigFile(configFile, ts.sys.readFile).config;
31
18
  tsconfig.compilerOptions = tsconfig.compilerOptions || {};
32
- tsconfig.compilerOptions = __assign({}, tsconfig.compilerOptions, compilerOptions);
33
- var parsed = ts.parseJsonConfigFileContent(tsconfig, parseConfigHost, path.dirname(configFile));
19
+ tsconfig.compilerOptions = Object.assign({}, tsconfig.compilerOptions, compilerOptions);
20
+ const parsed = ts.parseJsonConfigFileContent(tsconfig, parseConfigHost, path.dirname(configFile));
34
21
  parsed.options.allowNonTsExtensions = true;
35
22
  return parsed;
36
- };
23
+ }
37
24
  /**
38
25
  * Search for default wildcard or wildcard from options, we only search for that in tsconfig CompilerOptions.paths.
39
26
  * The path is resolved with thie given substitution and includes the CompilerOptions.baseUrl (if given).
40
27
  * If no paths given in tsconfig, then the default substitution is '[tsconfig directory]/src'.
41
28
  * (This is a fast, simplified inspiration of what's described here: https://github.com/Microsoft/TypeScript/issues/5039)
42
29
  */
43
- VueProgram.resolveNonTsModuleName = function (moduleName, containingFile, basedir, options) {
44
- var baseUrl = options.baseUrl ? options.baseUrl : basedir;
45
- var discardedSymbols = ['.', '..', '/'];
46
- var wildcards = [];
30
+ static resolveNonTsModuleName(moduleName, containingFile, basedir, options) {
31
+ const baseUrl = options.baseUrl ? options.baseUrl : basedir;
32
+ const discardedSymbols = ['.', '..', '/'];
33
+ const wildcards = [];
47
34
  if (options.paths) {
48
- Object.keys(options.paths).forEach(function (key) {
49
- var pathSymbol = key[0];
35
+ Object.keys(options.paths).forEach(key => {
36
+ const pathSymbol = key[0];
50
37
  if (discardedSymbols.indexOf(pathSymbol) < 0 &&
51
38
  wildcards.indexOf(pathSymbol) < 0) {
52
39
  wildcards.push(pathSymbol);
@@ -56,19 +43,19 @@ var VueProgram = /** @class */ (function () {
56
43
  else {
57
44
  wildcards.push('@');
58
45
  }
59
- var isRelative = !path.isAbsolute(moduleName);
60
- var correctWildcard;
61
- wildcards.forEach(function (wildcard) {
62
- if (moduleName.substr(0, 2) === wildcard + "/") {
46
+ const isRelative = !path.isAbsolute(moduleName);
47
+ let correctWildcard;
48
+ wildcards.forEach(wildcard => {
49
+ if (moduleName.substr(0, 2) === `${wildcard}/`) {
63
50
  correctWildcard = wildcard;
64
51
  }
65
52
  });
66
53
  if (correctWildcard) {
67
- var pattern = options.paths
68
- ? options.paths[correctWildcard + "/*"]
54
+ const pattern = options.paths
55
+ ? options.paths[`${correctWildcard}/*`]
69
56
  : undefined;
70
- var substitution = pattern
71
- ? options.paths[correctWildcard + "/*"][0].replace('*', '')
57
+ const substitution = pattern
58
+ ? options.paths[`${correctWildcard}/*`][0].replace('*', '')
72
59
  : 'src';
73
60
  moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
74
61
  }
@@ -76,19 +63,19 @@ var VueProgram = /** @class */ (function () {
76
63
  moduleName = path.resolve(path.dirname(containingFile), moduleName);
77
64
  }
78
65
  return moduleName;
79
- };
80
- VueProgram.isVue = function (filePath) {
66
+ }
67
+ static isVue(filePath) {
81
68
  return path.extname(filePath) === '.vue';
82
- };
83
- VueProgram.createProgram = function (programConfig, basedir, files, watcher, oldProgram) {
84
- var host = ts.createCompilerHost(programConfig.options);
85
- var realGetSourceFile = host.getSourceFile;
69
+ }
70
+ static createProgram(programConfig, basedir, files, watcher, oldProgram) {
71
+ const host = ts.createCompilerHost(programConfig.options);
72
+ const realGetSourceFile = host.getSourceFile;
86
73
  // We need a host that can parse Vue SFCs (single file components).
87
- host.getSourceFile = function (filePath, languageVersion, onError) {
74
+ host.getSourceFile = (filePath, languageVersion, onError) => {
88
75
  // first check if watcher is watching file - if not - check it's mtime
89
76
  if (!watcher.isWatchingFile(filePath)) {
90
77
  try {
91
- var stats = fs.statSync(filePath);
78
+ const stats = fs.statSync(filePath);
92
79
  files.setMtime(filePath, stats.mtime.valueOf());
93
80
  }
94
81
  catch (e) {
@@ -98,26 +85,25 @@ var VueProgram = /** @class */ (function () {
98
85
  }
99
86
  // get source file only if there is no source in files register
100
87
  if (!files.has(filePath) || !files.getData(filePath).source) {
101
- files.mutateData(filePath, function (data) {
88
+ files.mutateData(filePath, data => {
102
89
  data.source = realGetSourceFile(filePath, languageVersion, onError);
103
90
  });
104
91
  }
105
- var source = files.getData(filePath).source;
92
+ let source = files.getData(filePath).source;
106
93
  // get typescript contents from Vue file
107
94
  if (source && VueProgram.isVue(filePath)) {
108
- var resolved = VueProgram.resolveScriptBlock(source.text);
95
+ const resolved = VueProgram.resolveScriptBlock(source.text);
109
96
  source = ts.createSourceFile(filePath, resolved.content, languageVersion, true, resolved.scriptKind);
110
97
  }
111
98
  return source;
112
99
  };
113
100
  // We need a host with special module resolution for Vue files.
114
- host.resolveModuleNames = function (moduleNames, containingFile) {
115
- var resolvedModules = [];
116
- for (var _i = 0, moduleNames_1 = moduleNames; _i < moduleNames_1.length; _i++) {
117
- var moduleName = moduleNames_1[_i];
101
+ host.resolveModuleNames = (moduleNames, containingFile) => {
102
+ const resolvedModules = [];
103
+ for (const moduleName of moduleNames) {
118
104
  // Try to use standard resolution.
119
- var resolvedModule = ts.resolveModuleName(moduleName, containingFile, programConfig.options, {
120
- fileExists: function (fileName) {
105
+ const { resolvedModule } = ts.resolveModuleName(moduleName, containingFile, programConfig.options, {
106
+ fileExists(fileName) {
121
107
  if (fileName.endsWith('.vue.ts')) {
122
108
  return (host.fileExists(fileName.slice(0, -3)) ||
123
109
  host.fileExists(fileName));
@@ -126,7 +112,7 @@ var VueProgram = /** @class */ (function () {
126
112
  return host.fileExists(fileName);
127
113
  }
128
114
  },
129
- readFile: function (fileName) {
115
+ readFile(fileName) {
130
116
  // This implementation is not necessary. Just for consistent behavior.
131
117
  if (fileName.endsWith('.vue.ts') && !host.fileExists(fileName)) {
132
118
  return host.readFile(fileName.slice(0, -3));
@@ -135,7 +121,7 @@ var VueProgram = /** @class */ (function () {
135
121
  return host.readFile(fileName);
136
122
  }
137
123
  }
138
- }).resolvedModule;
124
+ });
139
125
  if (resolvedModule) {
140
126
  if (resolvedModule.resolvedFileName.endsWith('.vue.ts') &&
141
127
  !host.fileExists(resolvedModule.resolvedFileName)) {
@@ -145,7 +131,7 @@ var VueProgram = /** @class */ (function () {
145
131
  }
146
132
  else {
147
133
  // For non-ts extensions.
148
- var absolutePath = VueProgram.resolveNonTsModuleName(moduleName, containingFile, basedir, programConfig.options);
134
+ const absolutePath = VueProgram.resolveNonTsModuleName(moduleName, containingFile, basedir, programConfig.options);
149
135
  if (VueProgram.isVue(moduleName)) {
150
136
  resolvedModules.push({
151
137
  resolvedFileName: absolutePath,
@@ -167,8 +153,8 @@ var VueProgram = /** @class */ (function () {
167
153
  };
168
154
  return ts.createProgram(programConfig.fileNames, programConfig.options, host, oldProgram // re-use old program
169
155
  );
170
- };
171
- VueProgram.getScriptKindByLang = function (lang) {
156
+ }
157
+ static getScriptKindByLang(lang) {
172
158
  if (lang === 'ts') {
173
159
  return ts.ScriptKind.TS;
174
160
  }
@@ -182,13 +168,13 @@ var VueProgram = /** @class */ (function () {
182
168
  // when lang is "js" or no lang specified
183
169
  return ts.ScriptKind.JS;
184
170
  }
185
- };
186
- VueProgram.resolveScriptBlock = function (content) {
171
+ }
172
+ static resolveScriptBlock(content) {
187
173
  // We need to import vue-template-compiler lazily because it cannot be included it
188
174
  // as direct dependency because it is an optional dependency of fork-ts-checker-webpack-plugin.
189
175
  // Since its version must not mismatch with user-installed Vue.js,
190
176
  // we should let the users install vue-template-compiler by themselves.
191
- var parser;
177
+ let parser;
192
178
  try {
193
179
  // tslint:disable-next-line
194
180
  parser = require('vue-template-compiler');
@@ -196,9 +182,9 @@ var VueProgram = /** @class */ (function () {
196
182
  catch (err) {
197
183
  throw new Error('When you use `vue` option, make sure to install `vue-template-compiler`.');
198
184
  }
199
- var script = parser.parseComponent(content, {
185
+ const { script } = parser.parseComponent(content, {
200
186
  pad: 'space'
201
- }).script;
187
+ });
202
188
  // No <script> block
203
189
  if (!script) {
204
190
  return {
@@ -206,33 +192,32 @@ var VueProgram = /** @class */ (function () {
206
192
  content: '/* tslint:disable */\nexport default {};\n'
207
193
  };
208
194
  }
209
- var scriptKind = VueProgram.getScriptKindByLang(script.lang);
195
+ const scriptKind = VueProgram.getScriptKindByLang(script.lang);
210
196
  // There is src attribute
211
197
  if (script.attrs.src) {
212
198
  // import path cannot be end with '.ts[x]'
213
- var src = script.attrs.src.replace(/\.tsx?$/i, '');
199
+ const src = script.attrs.src.replace(/\.tsx?$/i, '');
214
200
  return {
215
- scriptKind: scriptKind,
201
+ scriptKind,
216
202
  // For now, ignore the error when the src file is not found
217
203
  // since it will produce incorrect code location.
218
204
  // It's not a large problem since it's handled on webpack side.
219
205
  content: '/* tslint:disable */\n' +
220
206
  '// @ts-ignore\n' +
221
- ("export { default } from '" + src + "';\n") +
207
+ `export { default } from '${src}';\n` +
222
208
  '// @ts-ignore\n' +
223
- ("export * from '" + src + "';\n")
209
+ `export * from '${src}';\n`
224
210
  };
225
211
  }
226
212
  // Pad blank lines to retain diagnostics location
227
213
  // We need to prepend `//` for each line to avoid
228
214
  // false positive of no-consecutive-blank-lines TSLint rule
229
- var offset = content.slice(0, script.start).split(/\r?\n/g).length;
230
- var paddedContent = Array(offset).join('//\n') + script.content.slice(script.start);
215
+ const offset = content.slice(0, script.start).split(/\r?\n/g).length;
216
+ const paddedContent = Array(offset).join('//\n') + script.content.slice(script.start);
231
217
  return {
232
- scriptKind: scriptKind,
218
+ scriptKind,
233
219
  content: paddedContent
234
220
  };
235
- };
236
- return VueProgram;
237
- }());
221
+ }
222
+ }
238
223
  exports.VueProgram = VueProgram;
@@ -1,13 +1,13 @@
1
1
  import { Message } from './Message';
2
2
  export declare class WorkResult {
3
- workResult: {};
4
- workDomain: any[];
5
- constructor(workDomain: any[]);
3
+ private workDomain;
4
+ private workResult;
5
+ constructor(workDomain: number[]);
6
6
  supports(workName: number): boolean;
7
- set(workName: number, result: any): void;
7
+ set(workName: number, result: Message): void;
8
8
  has(workName: number): boolean;
9
- get(workName: number): any;
9
+ get(workName: number): Message;
10
10
  hasAll(): boolean;
11
11
  clear(): void;
12
- reduce(reducer: (m1: Message, m2: Message) => Message, initial: Message): any;
12
+ reduce(reducer: (m1: Message, m2: Message) => Message, initial: Message): Message;
13
13
  }
package/lib/WorkResult.js CHANGED
@@ -1,41 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var WorkResult = /** @class */ (function () {
4
- function WorkResult(workDomain) {
5
- this.workResult = {};
3
+ class WorkResult {
4
+ constructor(workDomain) {
6
5
  this.workDomain = workDomain;
6
+ this.workResult = {};
7
+ }
8
+ supports(workName) {
9
+ return this.workDomain.includes(workName);
7
10
  }
8
- WorkResult.prototype.supports = function (workName) {
9
- return -1 !== this.workDomain.indexOf(workName);
10
- };
11
- WorkResult.prototype.set = function (workName, result) {
11
+ set(workName, result) {
12
12
  if (!this.supports(workName)) {
13
13
  throw new Error('Cannot set result - work "' + workName + '" is not supported.');
14
14
  }
15
15
  this.workResult[workName] = result;
16
- };
17
- WorkResult.prototype.has = function (workName) {
16
+ }
17
+ has(workName) {
18
18
  return this.supports(workName) && undefined !== this.workResult[workName];
19
- };
20
- WorkResult.prototype.get = function (workName) {
19
+ }
20
+ get(workName) {
21
21
  if (!this.supports(workName)) {
22
22
  throw new Error('Cannot get result - work "' + workName + '" is not supported.');
23
23
  }
24
24
  return this.workResult[workName];
25
- };
26
- WorkResult.prototype.hasAll = function () {
27
- var _this = this;
28
- return this.workDomain.every(function (key) { return _this.has(key); });
29
- };
30
- WorkResult.prototype.clear = function () {
25
+ }
26
+ hasAll() {
27
+ return this.workDomain.every(key => this.has(key));
28
+ }
29
+ clear() {
31
30
  this.workResult = {};
32
- };
33
- WorkResult.prototype.reduce = function (reducer, initial) {
34
- var _this = this;
35
- return this.workDomain.reduce(function (reduced, workName) {
36
- return reducer(reduced, _this.workResult[workName]);
31
+ }
32
+ reduce(reducer, initial) {
33
+ return this.workDomain.reduce((reduced, workName) => {
34
+ return reducer(reduced, this.workResult[workName]);
37
35
  }, initial);
38
- };
39
- return WorkResult;
40
- }());
36
+ }
37
+ }
41
38
  exports.WorkResult = WorkResult;
@@ -1,11 +1,11 @@
1
1
  import * as ts from 'typescript';
2
2
  export declare class WorkSet {
3
- workDomain: ReadonlyArray<ts.SourceFile> | string[];
4
- workNumber: number;
5
- workDivision: number;
6
- workSize: number;
7
- workBegin: number;
8
- workEnd: number;
3
+ private workDomain;
4
+ private workNumber;
5
+ private workDivision;
6
+ private workSize;
7
+ private workBegin;
8
+ private workEnd;
9
9
  constructor(workDomain: ReadonlyArray<ts.SourceFile> | string[], workNumber: number, workDivision: number);
10
10
  forEach(callback: (workDomainItem: any, index: number) => void): void;
11
11
  }
package/lib/WorkSet.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var WorkSet = /** @class */ (function () {
4
- function WorkSet(workDomain, workNumber, workDivision) {
3
+ class WorkSet {
4
+ constructor(workDomain, workNumber, workDivision) {
5
5
  this.workDomain = workDomain;
6
6
  this.workNumber = workNumber;
7
7
  this.workDivision = workDivision;
@@ -13,11 +13,10 @@ var WorkSet = /** @class */ (function () {
13
13
  this.workEnd = this.workDomain.length;
14
14
  }
15
15
  }
16
- WorkSet.prototype.forEach = function (callback) {
17
- for (var i = this.workBegin; i < this.workEnd; ++i) {
16
+ forEach(callback) {
17
+ for (let i = this.workBegin; i < this.workEnd; ++i) {
18
18
  callback(this.workDomain[i], i);
19
19
  }
20
- };
21
- return WorkSet;
22
- }());
20
+ }
21
+ }
23
22
  exports.WorkSet = WorkSet;
File without changes
package/lib/cluster.js CHANGED
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var childProcess = require("child_process");
4
- var path = require("path");
5
- var process = require("process");
6
- var WorkResult_1 = require("./WorkResult");
7
- var NormalizedMessage_1 = require("./NormalizedMessage");
3
+ const childProcess = require("child_process");
4
+ const path = require("path");
5
+ const process = require("process");
6
+ const WorkResult_1 = require("./WorkResult");
7
+ const NormalizedMessage_1 = require("./NormalizedMessage");
8
8
  // fork workers...
9
- var division = parseInt(process.env.WORK_DIVISION, 10);
10
- var workers = [];
11
- for (var num = 0; num < division; num++) {
9
+ const division = parseInt(process.env.WORK_DIVISION || '', 10);
10
+ const workers = [];
11
+ for (let num = 0; num < division; num++) {
12
12
  workers.push(childProcess.fork(path.resolve(__dirname, './service.js'), [], {
13
13
  execArgv: ['--max-old-space-size=' + process.env.MEMORY_LIMIT],
14
14
  env: Object.assign({}, process.env, { WORK_NUMBER: num }),
15
15
  stdio: ['inherit', 'inherit', 'inherit', 'ipc']
16
16
  }));
17
17
  }
18
- var pids = workers.map(function (worker) { return worker.pid; });
19
- var result = new WorkResult_1.WorkResult(pids);
20
- process.on('message', function (message) {
18
+ const pids = workers.map(worker => worker.pid);
19
+ const result = new WorkResult_1.WorkResult(pids);
20
+ process.on('message', (message) => {
21
21
  // broadcast message to all workers
22
- workers.forEach(function (worker) {
22
+ workers.forEach(worker => {
23
23
  try {
24
24
  worker.send(message);
25
25
  }
@@ -32,8 +32,8 @@ process.on('message', function (message) {
32
32
  result.clear();
33
33
  });
34
34
  // listen to all workers
35
- workers.forEach(function (worker) {
36
- worker.on('message', function (message) {
35
+ workers.forEach(worker => {
36
+ worker.on('message', (message) => {
37
37
  // set result from worker
38
38
  result.set(worker.pid, {
39
39
  diagnostics: message.diagnostics.map(NormalizedMessage_1.NormalizedMessage.createFromJSON),
@@ -41,10 +41,10 @@ workers.forEach(function (worker) {
41
41
  });
42
42
  // if we have result from all workers, send merged
43
43
  if (result.hasAll()) {
44
- var merged = result.reduce(function (innerMerged, innerResult) { return ({
44
+ const merged = result.reduce((innerMerged, innerResult) => ({
45
45
  diagnostics: innerMerged.diagnostics.concat(innerResult.diagnostics),
46
46
  lints: innerMerged.lints.concat(innerResult.lints)
47
- }); }, { diagnostics: [], lints: [] });
47
+ }), { diagnostics: [], lints: [] });
48
48
  merged.diagnostics = NormalizedMessage_1.NormalizedMessage.deduplicate(merged.diagnostics);
49
49
  merged.lints = NormalizedMessage_1.NormalizedMessage.deduplicate(merged.lints);
50
50
  try {
@@ -57,11 +57,11 @@ workers.forEach(function (worker) {
57
57
  }
58
58
  });
59
59
  });
60
- process.on('SIGINT', function () {
60
+ process.on('SIGINT', () => {
61
61
  process.exit();
62
62
  });
63
- process.on('exit', function () {
64
- workers.forEach(function (worker) {
63
+ process.on('exit', () => {
64
+ workers.forEach(worker => {
65
65
  try {
66
66
  worker.kill();
67
67
  }
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var os = require("os");
4
- var codeFrame = require("babel-code-frame");
5
- var chalk_1 = require("chalk");
6
- var fs = require("fs");
3
+ const os = require("os");
4
+ const codeFrame = require("babel-code-frame");
5
+ const chalk_1 = require("chalk");
6
+ const fs = require("fs");
7
+ const FsHelper_1 = require("../FsHelper");
7
8
  /**
8
9
  * Create new code frame formatter.
9
10
  *
@@ -12,26 +13,26 @@ var fs = require("fs");
12
13
  */
13
14
  function createCodeframeFormatter(options) {
14
15
  return function codeframeFormatter(message, useColors) {
15
- var colors = new chalk_1.default.constructor({ enabled: useColors });
16
- var messageColor = message.isWarningSeverity()
16
+ const colors = new chalk_1.default.constructor({ enabled: useColors });
17
+ const messageColor = message.isWarningSeverity()
17
18
  ? colors.bold.yellow
18
19
  : colors.bold.red;
19
- var positionColor = colors.dim;
20
- var source = message.getFile() &&
21
- fs.existsSync(message.getFile()) &&
22
- fs.readFileSync(message.getFile(), 'utf-8');
23
- var frame = '';
20
+ const positionColor = colors.dim;
21
+ const file = message.file;
22
+ const source = file && FsHelper_1.FsHelper.existsSync(file) && fs.readFileSync(file, 'utf-8');
23
+ let frame = '';
24
24
  if (source) {
25
- frame = codeFrame(source, message.line, message.character, Object.assign({}, options || {}, { highlightCode: useColors }))
25
+ frame = codeFrame(source, message.line, // Assertion: `codeFrame` allows passing undefined, typings are incorrect
26
+ message.character, Object.assign({}, options || {}, { highlightCode: useColors }))
26
27
  .split('\n')
27
- .map(function (str) { return ' ' + str; })
28
+ .map(str => ' ' + str)
28
29
  .join(os.EOL);
29
30
  }
30
- return (messageColor(message.getSeverity().toUpperCase() + ' in ' + message.getFile()) +
31
+ return (messageColor(message.severity.toUpperCase() + ' in ' + message.file) +
31
32
  os.EOL +
32
- positionColor(message.getLine() + ':' + message.getCharacter()) +
33
+ positionColor(message.line + ':' + message.character) +
33
34
  ' ' +
34
- message.getContent() +
35
+ message.content +
35
36
  (frame ? os.EOL + frame : ''));
36
37
  };
37
38
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var chalk_1 = require("chalk");
4
- var os = require("os");
3
+ const chalk_1 = require("chalk");
4
+ const os = require("os");
5
5
  /**
6
6
  * Creates new default formatter.
7
7
  *
@@ -9,17 +9,17 @@ var os = require("os");
9
9
  */
10
10
  function createDefaultFormatter() {
11
11
  return function defaultFormatter(message, useColors) {
12
- var colors = new chalk_1.default.constructor({ enabled: useColors });
13
- var messageColor = message.isWarningSeverity()
12
+ const colors = new chalk_1.default.constructor({ enabled: useColors });
13
+ const messageColor = message.isWarningSeverity()
14
14
  ? colors.bold.yellow
15
15
  : colors.bold.red;
16
- var fileAndNumberColor = colors.bold.cyan;
17
- var codeColor = colors.grey;
16
+ const fileAndNumberColor = colors.bold.cyan;
17
+ const codeColor = colors.grey;
18
18
  return [
19
- messageColor(message.getSeverity().toUpperCase() + " in ") +
20
- fileAndNumberColor(message.getFile() + "(" + message.getLine() + "," + message.getCharacter() + ")") +
19
+ messageColor(`${message.severity.toUpperCase()} in `) +
20
+ fileAndNumberColor(`${message.file}(${message.line},${message.character})`) +
21
21
  messageColor(':'),
22
- codeColor(message.getFormattedCode() + ': ') + message.getContent()
22
+ codeColor(message.getFormattedCode() + ': ') + message.content
23
23
  ].join(os.EOL);
24
24
  };
25
25
  }