Permalink
Browse files

fix(compiler-cli): diagnostics file paths relative to cwd, not tsconf…

…ig (#19748)

PR Close #19748
  • Loading branch information...
alexeagle authored and tbosch committed Oct 16, 2017
1 parent c0cc6ee commit 56774dfb7911cc65013ca1938b15f91ef5236e95
@@ -205,7 +205,7 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
const tsickleEmitResult = emitResult as tsickle.EmitResult;
let externs = '/** @externs */\n';
if (diagnostics.length) {
console.error(ng.formatDiagnostics(compilerOpts, diagnostics));
console.error(ng.formatDiagnostics(diagnostics));
} else {
if (bazelOpts.tsickleGenerateExterns) {
externs += tsickle.getGeneratedExterns(tsickleEmitResult.externs);
@@ -28,15 +28,15 @@ export function main(
let {project, rootNames, options, errors: configErrors, watch, emitFlags} =
config || readNgcCommandLineAndConfiguration(args);
if (configErrors.length) {
return reportErrorsAndExit(options, configErrors, consoleError);
return reportErrorsAndExit(configErrors, consoleError);
}
if (watch) {
const result = watchMode(project, options, consoleError);
return reportErrorsAndExit({}, result.firstCompileResult, consoleError);
return reportErrorsAndExit(result.firstCompileResult, consoleError);
}
const {diagnostics: compileDiags} = performCompilation(
{rootNames, options, emitFlags, emitCallback: createEmitCallback(options)});
return reportErrorsAndExit(options, compileDiags, consoleError);
return reportErrorsAndExit(compileDiags, consoleError);
}
function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|undefined {
@@ -128,19 +128,18 @@ export function readCommandLineAndConfiguration(
}
function reportErrorsAndExit(
options: api.CompilerOptions, allDiagnostics: Diagnostics,
consoleError: (s: string) => void = console.error): number {
allDiagnostics: Diagnostics, consoleError: (s: string) => void = console.error): number {
const errorsAndWarnings = filterErrorsAndWarnings(allDiagnostics);
if (errorsAndWarnings.length) {
consoleError(formatDiagnostics(options, errorsAndWarnings));
consoleError(formatDiagnostics(errorsAndWarnings));
}
return exitCodeFromResult(allDiagnostics);
}
export function watchMode(
project: string, options: api.CompilerOptions, consoleError: (s: string) => void) {
return performWatchCompilation(createPerformWatchHost(project, diagnostics => {
consoleError(formatDiagnostics(options, diagnostics));
consoleError(formatDiagnostics(diagnostics));
}, options, options => createEmitCallback(options)));
}
@@ -131,6 +131,6 @@ export function createCompilerHost(
// Wrapper for formatDiagnostics.
export type Diagnostics = Array<ts.Diagnostic|Diagnostic>;
export function formatDiagnostics(options: CompilerOptions, diags: Diagnostics): string {
return formatDiagnosticsOrig(options, diags);
export function formatDiagnostics(diags: Diagnostics): string {
return formatDiagnosticsOrig(diags);
}
@@ -23,13 +23,15 @@ export function filterErrorsAndWarnings(diagnostics: Diagnostics): Diagnostics {
return diagnostics.filter(d => d.category !== ts.DiagnosticCategory.Message);
}
export function formatDiagnostics(options: api.CompilerOptions, diags: Diagnostics): string {
const defaultFormatHost: ts.FormatDiagnosticsHost = {
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
getCanonicalFileName: fileName => fileName,
getNewLine: () => ts.sys.newLine
};
export function formatDiagnostics(
diags: Diagnostics, tsFormatHost: ts.FormatDiagnosticsHost = defaultFormatHost): string {
if (diags && diags.length) {
const tsFormatHost: ts.FormatDiagnosticsHost = {
getCurrentDirectory: () => options.basePath || process.cwd(),
getCanonicalFileName: fileName => fileName,
getNewLine: () => ts.sys.newLine
};
return diags
.map(d => {
if (api.isTsDiagnostic(d)) {
@@ -44,6 +44,7 @@ describe('ngc transformer command-line', () => {
beforeEach(() => {
errorSpy = jasmine.createSpy('consoleError').and.callFake(console.error);
basePath = makeTempDir();
process.chdir(basePath);
write = (fileName: string, content: string) => {
const dir = path.dirname(fileName);
if (dir != '.') {
@@ -112,7 +112,7 @@ export function setup(): TestSupport {
export function expectNoDiagnostics(options: ng.CompilerOptions, diags: ng.Diagnostics) {
const errorDiags = diags.filter(d => d.category !== ts.DiagnosticCategory.Message);
if (errorDiags.length) {
throw new Error(`Expected no diagnostics: ${ng.formatDiagnostics(options, errorDiags)}`);
throw new Error(`Expected no diagnostics: ${ng.formatDiagnostics(errorDiags)}`);
}
}

0 comments on commit 56774df

Please sign in to comment.