Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Commit c966685

Browse files
committed
refactor: update some deps
1 parent ad7cfad commit c966685

File tree

4 files changed

+522
-369
lines changed

4 files changed

+522
-369
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"homepage": "https://github.com/s-panferov/awesome-typescript-loader",
3434
"dependencies": {
35-
"colors": "^1.1.2",
35+
"chalk": "^2.3.1",
3636
"enhanced-resolve": "3.3.0",
3737
"loader-utils": "^1.1.0",
3838
"lodash": "^4.17.4",
@@ -45,12 +45,12 @@
4545
},
4646
"devDependencies": {
4747
"@types/chai": "^4.0.1",
48-
"@types/colors": "^1.1.3",
4948
"@types/lodash": "^4.14.67",
5049
"@types/micromatch": "^2.3.29",
5150
"@types/mocha": "^2.2.41",
5251
"@types/node": "^8.0.5",
5352
"@types/shelljs": "^0.7.2",
53+
"@types/chalk": "^2.2.0",
5454
"@types/sinon": "^2.3.2",
5555
"@types/webpack": "^3.0.1",
5656
"bluebird": "^3.5.0",
@@ -64,7 +64,7 @@
6464
"standard-version": "^4.2.0",
6565
"temp": "^0.8.3",
6666
"tslint": "^5.4.3",
67-
"typescript": "^2.4.1",
67+
"typescript": "^2.7.2",
6868
"webpack": "~2.7.0"
6969
}
7070
}

src/checker/runtime.ts

Lines changed: 100 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as ts from 'typescript';
2-
import * as path from 'path';
3-
import * as micromatch from 'micromatch';
4-
import * as colors from 'colors';
5-
import { findResultFor, toUnix } from '../helpers';
1+
import * as ts from "typescript";
2+
import * as path from "path";
3+
import * as micromatch from "micromatch";
4+
import chalk from "chalk";
5+
import { findResultFor, toUnix } from "../helpers";
66
import {
77
Req,
88
Res,
@@ -16,54 +16,53 @@ import {
1616
Files,
1717
MessageType,
1818
TsConfig
19-
} from './protocol';
19+
} from "./protocol";
2020

21-
import { CaseInsensitiveMap, MapLike } from './fs';
22-
import { isCaseInsensitive } from '../helpers';
21+
import { CaseInsensitiveMap, MapLike } from "./fs";
22+
import { isCaseInsensitive } from "../helpers";
2323

2424
const caseInsensitive = isCaseInsensitive();
2525

2626
if (!module.parent) {
27-
process.on('uncaughtException', function (err) {
27+
process.on("uncaughtException", function(err) {
2828
console.log("UNCAUGHT EXCEPTION in awesome-typescript-loader");
2929
console.log("[Inside 'uncaughtException' event] ", err.message, err.stack);
3030
});
3131

32-
process.on('disconnect', function () {
32+
process.on("disconnect", function() {
3333
process.exit();
3434
});
3535

36-
process.on('exit', () => {
36+
process.on("exit", () => {
3737
// console.log('EXIT RUNTIME');
3838
});
3939

40-
createChecker(
41-
process.on.bind(process, 'message'),
42-
process.send.bind(process)
43-
);
40+
createChecker(process.on.bind(process, "message"), process.send.bind(process));
4441
} else {
4542
module.exports.run = function run() {
4643
let send: (msg: Req, cb: (err?: Error) => void) => void;
47-
let receive = (msg) => { };
44+
let receive = msg => {};
4845

4946
createChecker(
5047
(receive: (msg: Req) => void) => {
5148
send = (msg: Req, cb: (err?: Error) => void) => {
5249
receive(msg);
53-
if (cb) { cb(); }
50+
if (cb) {
51+
cb();
52+
}
5453
};
5554
},
56-
(msg) => receive(msg)
55+
msg => receive(msg)
5756
);
5857

5958
return {
6059
on: (type: string, cb) => {
61-
if (type === 'message') {
60+
if (type === "message") {
6261
receive = cb;
6362
}
6463
},
6564
send,
66-
kill: () => { }
65+
kill: () => {}
6766
};
6867
};
6968
}
@@ -96,7 +95,9 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
9695
const file = files.get(fileName);
9796
if (!file) {
9897
const text = compiler.sys.readFile(fileName);
99-
if (text == null) { return; }
98+
if (text == null) {
99+
return;
100+
}
100101
files.set(fileName, {
101102
fileName: fileName,
102103
text,
@@ -169,30 +170,37 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
169170
constructor(filesRegex: RegExp) {
170171
this.filesRegex = filesRegex;
171172

172-
let {getCustomTransformers} = loaderConfig;
173+
let { getCustomTransformers } = loaderConfig;
173174

174175
if (typeof getCustomTransformers === "function") {
175176
this.getCustomTransformers = getCustomTransformers;
176177
} else if (typeof getCustomTransformers === "string") {
177178
try {
178179
getCustomTransformers = require(getCustomTransformers);
179180
} catch (err) {
180-
throw new Error(`Failed to load customTransformers from "${loaderConfig.getCustomTransformers}": ${err.message}`)
181-
};
181+
throw new Error(
182+
`Failed to load customTransformers from "${loaderConfig.getCustomTransformers}": ${err.message}`
183+
);
184+
}
182185

183186
if (typeof getCustomTransformers !== "function") {
184-
throw new Error(`Custom transformers in "${loaderConfig.getCustomTransformers}" should export a function, got ${typeof getCustomTransformers}`)
185-
};
187+
throw new Error(
188+
`Custom transformers in "${
189+
loaderConfig.getCustomTransformers
190+
}" should export a function, got ${typeof getCustomTransformers}`
191+
);
192+
}
186193

187194
this.getCustomTransformers = getCustomTransformers;
188-
};
195+
}
189196
}
190197

191-
getProjectVersion() { return projectVersion.toString(); }
198+
getProjectVersion() {
199+
return projectVersion.toString();
200+
}
192201

193202
getScriptFileNames() {
194-
const names = files.map(file => file.fileName)
195-
.filter(fileName => this.filesRegex.test(fileName));
203+
const names = files.map(file => file.fileName).filter(fileName => this.filesRegex.test(fileName));
196204
return names;
197205
}
198206

@@ -225,9 +233,11 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
225233
}
226234

227235
resolveTypeReferenceDirectives(typeDirectiveNames: string[], containingFile: string) {
228-
const resolved = typeDirectiveNames.map(directive =>
229-
compiler.resolveTypeReferenceDirective(directive, containingFile, compilerOptions, compiler.sys)
230-
.resolvedTypeReferenceDirective);
236+
const resolved = typeDirectiveNames.map(
237+
directive =>
238+
compiler.resolveTypeReferenceDirective(directive, containingFile, compilerOptions, compiler.sys)
239+
.resolvedTypeReferenceDirective
240+
);
231241

232242
resolved.forEach(res => {
233243
if (res && res.resolvedFileName) {
@@ -239,8 +249,11 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
239249
}
240250

241251
resolveModuleNames(moduleNames: string[], containingFile: string) {
242-
const resolved = moduleNames.map(module =>
243-
compiler.resolveModuleName(module, containingFile, compilerOptions, compiler.sys, cache).resolvedModule);
252+
const resolved = moduleNames.map(
253+
module =>
254+
compiler.resolveModuleName(module, containingFile, compilerOptions, compiler.sys, cache)
255+
.resolvedModule
256+
);
244257

245258
resolved.forEach(res => {
246259
if (res && res.resolvedFileName) {
@@ -282,7 +295,6 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
282295
directoryExists(path: string) {
283296
return compiler.sys.directoryExists(path);
284297
}
285-
286298
}
287299

288300
let normalize: (f: string) => string;
@@ -301,24 +313,20 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
301313
files = new CaseInsensitiveMap();
302314

303315
if (compiler.createModuleResolutionCache) {
304-
cache = compiler.createModuleResolutionCache(
305-
context,
306-
normalize
307-
);
316+
cache = compiler.createModuleResolutionCache(context, normalize);
308317
}
309318

310-
instanceName = loaderConfig.instance || 'at-loader';
319+
instanceName = loaderConfig.instance || "at-loader";
311320

312-
host = new Host(compilerOptions.allowJs
313-
? TS_AND_JS_FILES
314-
: TS_FILES
315-
);
321+
host = new Host(compilerOptions.allowJs ? TS_AND_JS_FILES : TS_FILES);
316322

317323
service = compiler.createLanguageService(host);
318324

319325
compilerConfig.fileNames.forEach(fileName => {
320326
const text = compiler.sys.readFile(fileName);
321-
if (text == null) { return; }
327+
if (text == null) {
328+
return;
329+
}
322330
files.set(fileName, {
323331
fileName,
324332
text,
@@ -369,7 +377,9 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
369377
return;
370378
}
371379
}
372-
if (file.text !== text) { updated = updated || true; }
380+
if (file.text !== text) {
381+
updated = updated || true;
382+
}
373383
if (!updated) {
374384
return false;
375385
}
@@ -419,7 +429,7 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
419429
compilerOptions: compilerOptions,
420430
fileName,
421431
reportDiagnostics: false,
422-
transformers: host.getCustomTransformers ? host.getCustomTransformers() : undefined,
432+
transformers: host.getCustomTransformers ? host.getCustomTransformers() : undefined
423433
});
424434

425435
return {
@@ -447,22 +457,23 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
447457

448458
function processFiles({ seq }: Files.Request) {
449459
replyOk(seq, {
450-
files: service.getProgram().getSourceFiles().map(f => f.fileName)
460+
files: service
461+
.getProgram()
462+
.getSourceFiles()
463+
.map(f => f.fileName)
451464
});
452465
}
453466

454467
function processDiagnostics({ seq }: Diagnostics.Request) {
455468
let silent = !!loaderConfig.silent;
456469

457470
if (!silent) {
458-
console.log(colors.cyan(`\n[${instanceName}] Checking started in a separate process...`));
471+
console.log(chalk.cyan(`\n[${instanceName}] Checking started in a separate process...`));
459472
}
460473

461474
const program = service.getProgram();
462475

463-
const allDiagnostics = program
464-
.getOptionsDiagnostics()
465-
.concat(program.getGlobalDiagnostics());
476+
const allDiagnostics = program.getOptionsDiagnostics().concat(program.getGlobalDiagnostics());
466477

467478
const filters: Filter[] = [];
468479

@@ -482,9 +493,10 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
482493
let nativeGetter: typeof program.getSourceFiles;
483494
if (filters.length > 0) {
484495
nativeGetter = program.getSourceFiles;
485-
program.getSourceFiles = () => nativeGetter().filter(file => {
486-
return filters.every(f => f(file));
487-
});
496+
program.getSourceFiles = () =>
497+
nativeGetter().filter(file => {
498+
return filters.every(f => f(file));
499+
});
488500
}
489501

490502
allDiagnostics.push(...program.getSyntacticDiagnostics());
@@ -498,41 +510,40 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
498510
program.getSourceFiles = nativeGetter;
499511
}
500512

501-
const processedDiagnostics = allDiagnostics
502-
.filter(diag => !ignoreDiagnostics[diag.code])
503-
.map(diagnostic => {
504-
const message = compiler.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
505-
let fileName = diagnostic.file && path.relative(context, diagnostic.file.fileName);
506-
507-
if (fileName && fileName[0] !== '.') {
508-
fileName = './' + toUnix(fileName);
509-
}
513+
const processedDiagnostics = allDiagnostics.filter(diag => !ignoreDiagnostics[diag.code]).map(diagnostic => {
514+
const message = compiler.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
515+
let fileName = diagnostic.file && path.relative(context, diagnostic.file.fileName);
510516

511-
let pretty = '';
512-
let line = 0;
513-
let character = 0;
514-
let code = diagnostic.code;
517+
if (fileName && fileName[0] !== ".") {
518+
fileName = "./" + toUnix(fileName);
519+
}
515520

516-
if (diagnostic.file) {
517-
const pos = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
518-
line = pos.line;
519-
character = pos.character;
520-
pretty = (`[${instanceName}] ${colors.red(fileName)}:${line + 1}:${character + 1} \n TS${code}: ${colors.red(message)}`);
521-
} else {
522-
pretty = (colors.red(`[${instanceName}] TS${code}: ${message}`));
523-
}
521+
let pretty = "";
522+
let line = 0;
523+
let character = 0;
524+
let code = diagnostic.code;
525+
526+
if (diagnostic.file) {
527+
const pos = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
528+
line = pos.line;
529+
character = pos.character;
530+
pretty = `[${instanceName}] ${chalk.red(fileName)}:${line + 1}:${character +
531+
1} \n TS${code}: ${chalk.red(message)}`;
532+
} else {
533+
pretty = chalk.red(`[${instanceName}] TS${code}: ${message}`);
534+
}
524535

525-
return {
526-
category: diagnostic.category,
527-
code: diagnostic.code,
528-
fileName,
529-
start: diagnostic.start,
530-
message,
531-
pretty,
532-
line,
533-
character
534-
};
535-
});
536+
return {
537+
category: diagnostic.category,
538+
code: diagnostic.code,
539+
fileName,
540+
start: diagnostic.start,
541+
message,
542+
pretty,
543+
line,
544+
character
545+
};
546+
});
536547

537548
replyOk(seq, processedDiagnostics);
538549
}
@@ -553,7 +564,7 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
553564
} as Res);
554565
}
555566

556-
receive(function (req: Req) {
567+
receive(function(req: Req) {
557568
try {
558569
switch (req.type) {
559570
case MessageType.Init:
@@ -574,7 +585,6 @@ function createChecker(receive: (cb: (msg: Req) => void) => void, send: (msg: Re
574585
case MessageType.Files:
575586
processFiles(req);
576587
break;
577-
578588
}
579589
} catch (e) {
580590
console.error(`[${instanceName}]: Child process failed to process the request: `, e);

0 commit comments

Comments
 (0)