diff --git a/packages/bazel/src/ngc-wrapped/index.ts b/packages/bazel/src/ngc-wrapped/index.ts index 78e2ee1486..81b8b36491 100644 --- a/packages/bazel/src/ngc-wrapped/index.ts +++ b/packages/bazel/src/ngc-wrapped/index.ts @@ -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); diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index b34cf29596..d373cb8c89 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -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,11 +128,10 @@ 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); } @@ -140,7 +139,7 @@ function reportErrorsAndExit( 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))); } diff --git a/packages/compiler-cli/src/ngtools_api2.ts b/packages/compiler-cli/src/ngtools_api2.ts index d4c1c0ab2f..0a760b1623 100644 --- a/packages/compiler-cli/src/ngtools_api2.ts +++ b/packages/compiler-cli/src/ngtools_api2.ts @@ -131,6 +131,6 @@ export function createCompilerHost( // Wrapper for formatDiagnostics. export type Diagnostics = Array; -export function formatDiagnostics(options: CompilerOptions, diags: Diagnostics): string { - return formatDiagnosticsOrig(options, diags); +export function formatDiagnostics(diags: Diagnostics): string { + return formatDiagnosticsOrig(diags); } \ No newline at end of file diff --git a/packages/compiler-cli/src/perform_compile.ts b/packages/compiler-cli/src/perform_compile.ts index 0bfcf98fbb..f3f419eec7 100644 --- a/packages/compiler-cli/src/perform_compile.ts +++ b/packages/compiler-cli/src/perform_compile.ts @@ -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)) { diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 6c38d7d75d..82511a33b3 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -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 != '.') { diff --git a/packages/compiler-cli/test/test_support.ts b/packages/compiler-cli/test/test_support.ts index 38dd9e9678..122bb64492 100644 --- a/packages/compiler-cli/test/test_support.ts +++ b/packages/compiler-cli/test/test_support.ts @@ -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)}`); } }