|
9 | 9 | import {logging} from '@angular-devkit/core'; |
10 | 10 | import {Rule, SchematicContext, SchematicsException, Tree} from '@angular-devkit/schematics'; |
11 | 11 | import {AotCompiler} from '@angular/compiler'; |
| 12 | +import {Diagnostic as NgDiagnostic} from '@angular/compiler-cli'; |
12 | 13 | import {PartialEvaluator} from '@angular/compiler-cli/src/ngtsc/partial_evaluator'; |
13 | 14 | import {TypeScriptReflectionHost} from '@angular/compiler-cli/src/ngtsc/reflection'; |
14 | 15 | import {relative} from 'path'; |
@@ -84,10 +85,11 @@ function runUndecoratedClassesMigration( |
84 | 85 | const partialEvaluator = |
85 | 86 | new PartialEvaluator(new TypeScriptReflectionHost(typeChecker), typeChecker); |
86 | 87 | const declarationCollector = new NgDeclarationCollector(typeChecker, partialEvaluator); |
87 | | - const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !); |
| 88 | + const sourceFiles = program.getSourceFiles().filter( |
| 89 | + s => !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s)); |
88 | 90 |
|
89 | 91 | // Analyze source files by detecting all directives, components and providers. |
90 | | - rootSourceFiles.forEach(sourceFile => declarationCollector.visitNode(sourceFile)); |
| 92 | + sourceFiles.forEach(sourceFile => declarationCollector.visitNode(sourceFile)); |
91 | 93 |
|
92 | 94 | const {decoratedDirectives, decoratedProviders, undecoratedDeclarations} = declarationCollector; |
93 | 95 | const transform = |
@@ -151,14 +153,28 @@ function runUndecoratedClassesMigration( |
151 | 153 | } |
152 | 154 | } |
153 | 155 |
|
| 156 | +function getErrorDiagnostics(diagnostics: ReadonlyArray<ts.Diagnostic|NgDiagnostic>) { |
| 157 | + return <ts.Diagnostic[]>diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error); |
| 158 | +} |
| 159 | + |
154 | 160 | function gracefullyCreateProgram( |
155 | 161 | tree: Tree, basePath: string, tsconfigPath: string, |
156 | 162 | logger: logging.LoggerApi): {compiler: AotCompiler, program: ts.Program}|null { |
157 | 163 | try { |
158 | 164 | const {ngcProgram, host, program, compiler} = createNgcProgram( |
159 | 165 | (options) => createMigrationCompilerHost(tree, options, basePath), tsconfigPath); |
160 | | - const syntacticDiagnostics = ngcProgram.getTsSyntacticDiagnostics(); |
161 | | - const structuralDiagnostics = ngcProgram.getNgStructuralDiagnostics(); |
| 166 | + const syntacticDiagnostics = getErrorDiagnostics(ngcProgram.getTsSyntacticDiagnostics()); |
| 167 | + const structuralDiagnostics = getErrorDiagnostics(ngcProgram.getNgStructuralDiagnostics()); |
| 168 | + const configDiagnostics = getErrorDiagnostics( |
| 169 | + [...program.getOptionsDiagnostics(), ...ngcProgram.getNgOptionDiagnostics()]); |
| 170 | + |
| 171 | + if (configDiagnostics.length) { |
| 172 | + logger.warn( |
| 173 | + `\nTypeScript project "${tsconfigPath}" has configuration errors. This could cause ` + |
| 174 | + `an incomplete migration. Please fix the following failures and rerun the migration:`); |
| 175 | + logger.error(ts.formatDiagnostics(configDiagnostics, host)); |
| 176 | + return null; |
| 177 | + } |
162 | 178 |
|
163 | 179 | // Syntactic TypeScript errors can throw off the query analysis and therefore we want |
164 | 180 | // to notify the developer that we couldn't analyze parts of the project. Developers |
|
0 commit comments