Skip to content

Commit d77e8ec

Browse files
committed
Use template strings for diagnostic
1 parent c0580df commit d77e8ec

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@angular/platform-browser-dynamic": "^2.3.0",
4242
"@angular/platform-server": "^2.3.0",
4343
"@angular/router": "^3.3.0",
44+
"@types/chalk": "^0.4.31",
4445
"@types/fs-extra": "0.0.37",
4546
"@types/glob": "^5.0.30",
4647
"@types/gulp": "^3.8.32",
@@ -54,6 +55,7 @@
5455
"autoprefixer": "^6.7.6",
5556
"axe-core": "^2.1.7",
5657
"axe-webdriverjs": "^0.5.0",
58+
"chalk": "^1.1.3",
5759
"conventional-changelog": "^1.1.0",
5860
"dgeni": "^0.4.7",
5961
"dgeni-packages": "^0.16.5",

tools/gulp/util/ts-compiler.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ts from 'typescript';
22
import * as path from 'path';
3+
import * as chalk from 'chalk';
34

45
/** Compiles a TypeScript project with possible extra options. */
56
export function compileProject(project: string, options: ts.CompilerOptions) {
@@ -10,9 +11,8 @@ export function compileProject(project: string, options: ts.CompilerOptions) {
1011
checkDiagnostics(program.getOptionsDiagnostics());
1112

1213
let emitResult = program.emit();
13-
let emitDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
1414

15-
checkDiagnostics(emitDiagnostics);
15+
checkDiagnostics(emitResult.diagnostics);
1616
}
1717

1818
/** Parses a TypeScript project configuration. */
@@ -38,11 +38,9 @@ export function formatDiagnostics(diagnostics: ts.Diagnostic[]): string {
3838
if (diagnostic.file) {
3939
let {line, character} = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
4040

41-
res += ' at ' + diagnostic.file.fileName + ':';
42-
res += (line + 1) + ':' + (character + 1) + ':';
41+
res += ` at ${diagnostic.file.fileName}(${line + 1},${character + 1}):`;
4342
}
44-
45-
res += ' ' + ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
43+
res += ` ${ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')}`;
4644

4745
return res;
4846
}).join('\n');
@@ -51,6 +49,8 @@ export function formatDiagnostics(diagnostics: ts.Diagnostic[]): string {
5149
/** Checks diagnostics and throws errors if present. */
5250
export function checkDiagnostics(diagnostics: ts.Diagnostic[]) {
5351
if (diagnostics && diagnostics.length && diagnostics[0]) {
54-
throw new Error(formatDiagnostics(diagnostics));
52+
console.error(formatDiagnostics(diagnostics));
53+
console.error(chalk.red('TypeScript compilation failed. Exiting process.'));
54+
process.exit(1);
5555
}
5656
}

0 commit comments

Comments
 (0)