feat(compiler-cli): add watch mode to ngc (#18818)

With this change ngc now accepts a `-w` or a `--watch`
command-line option that will automatically perform a
recompile whenever any source files change on disk.

PR Close #18818
This commit is contained in:
Chuck Jazdzewski
2017-08-18 14:03:59 -07:00
committed by Jason Aden
parent 0e64261f26
commit cf7d47dda0
18 changed files with 539 additions and 54 deletions

View File

@ -15,7 +15,7 @@ import * as ts from 'typescript';
import {BaseAotCompilerHost} from '../compiler_host';
import {TypeChecker} from '../diagnostics/check_types';
import {CompilerHost, CompilerOptions, CustomTransformers, Diagnostic, EmitFlags, Program, TsEmitArguments, TsEmitCallback} from './api';
import {CompilerHost, CompilerOptions, CustomTransformers, DEFAULT_ERROR_CODE, Diagnostic, EmitFlags, Program, SOURCE, TsEmitArguments, TsEmitCallback} from './api';
import {LowerMetadataCache, getExpressionLoweringTransformFactory} from './lower_expressions';
import {getAngularEmitterTransformFactory} from './node_emitter_transform';
@ -61,8 +61,12 @@ class AngularCompilerProgram implements Program {
if (errors) {
// TODO(tbosch): once we move MetadataBundler from tsc_wrapped into compiler_cli,
// directly create ng.Diagnostic instead of using ts.Diagnostic here.
this._optionsDiagnostics.push(
...errors.map(e => ({category: e.category, message: e.messageText as string})));
this._optionsDiagnostics.push(...errors.map(e => ({
category: e.category,
messageText: e.messageText as string,
source: SOURCE,
code: DEFAULT_ERROR_CODE
})));
} else {
rootNames.push(indexName !);
this.host = host = bundleHost;
@ -219,12 +223,19 @@ class AngularCompilerProgram implements Program {
if (parserErrors && parserErrors.length) {
this._structuralDiagnostics =
parserErrors.map<Diagnostic>(e => ({
message: e.contextualMessage(),
messageText: e.contextualMessage(),
category: ts.DiagnosticCategory.Error,
span: e.span
span: e.span,
source: SOURCE,
code: DEFAULT_ERROR_CODE
}));
} else {
this._structuralDiagnostics = [{message: e.message, category: ts.DiagnosticCategory.Error}];
this._structuralDiagnostics = [{
messageText: e.message,
category: ts.DiagnosticCategory.Error,
source: SOURCE,
code: DEFAULT_ERROR_CODE
}];
}
this._analyzedModules = emptyModules;
return emptyModules;
@ -252,8 +263,12 @@ class AngularCompilerProgram implements Program {
return this.options.skipTemplateCodegen ? [] : result;
} catch (e) {
if (isSyntaxError(e)) {
this._generatedFileDiagnostics =
[{message: e.message, category: ts.DiagnosticCategory.Error}];
this._generatedFileDiagnostics = [{
messageText: e.message,
category: ts.DiagnosticCategory.Error,
source: SOURCE,
code: DEFAULT_ERROR_CODE
}];
return [];
}
throw e;
@ -417,9 +432,11 @@ function getNgOptionDiagnostics(options: CompilerOptions): Diagnostic[] {
break;
default:
return [{
message:
messageText:
'Angular compiler options "annotationsAs" only supports "static fields" and "decorators"',
category: ts.DiagnosticCategory.Error
category: ts.DiagnosticCategory.Error,
source: SOURCE,
code: DEFAULT_ERROR_CODE
}];
}
}