fix(core): migrations not always migrating all files (#30269)

In an Angular CLI project scenario where projects only reference
top-level source-files through the `tsconfig` `files` option, we currently
do not migrate referenced source-files. This can be fixed checking all
referenced source-files which aren't coming from an external library.

This is similar to how `tslint` determines project source-files.

PR Close #30269
This commit is contained in:
Paul Gschwendtner 2019-05-05 12:02:35 +02:00 committed by Alex Rickabaugh
parent 6357d4a0d3
commit 349935a434
4 changed files with 11 additions and 7 deletions

View File

@ -53,10 +53,11 @@ function runInjectablePipeMigration(tree: Tree, tsconfigPath: string, basePath:
const program = ts.createProgram(parsed.fileNames, parsed.options, host); const program = ts.createProgram(parsed.fileNames, parsed.options, host);
const typeChecker = program.getTypeChecker(); const typeChecker = program.getTypeChecker();
const visitor = new InjectablePipeVisitor(typeChecker); const visitor = new InjectablePipeVisitor(typeChecker);
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !); const sourceFiles = program.getSourceFiles().filter(
f => !f.isDeclarationFile && !program.isSourceFileFromExternalLibrary(f));
const printer = ts.createPrinter(); const printer = ts.createPrinter();
rootSourceFiles.forEach(sourceFile => visitor.visitNode(sourceFile)); sourceFiles.forEach(sourceFile => visitor.visitNode(sourceFile));
visitor.missingInjectablePipes.forEach(data => { visitor.missingInjectablePipes.forEach(data => {
const {classDeclaration, importDeclarationMissingImport} = data; const {classDeclaration, importDeclarationMissingImport} = data;

View File

@ -54,10 +54,11 @@ function runMoveDocumentMigration(tree: Tree, tsconfigPath: string, basePath: st
const program = ts.createProgram(parsed.fileNames, parsed.options, host); const program = ts.createProgram(parsed.fileNames, parsed.options, host);
const typeChecker = program.getTypeChecker(); const typeChecker = program.getTypeChecker();
const visitor = new DocumentImportVisitor(typeChecker); const visitor = new DocumentImportVisitor(typeChecker);
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !); const sourceFiles = program.getSourceFiles().filter(
f => !f.isDeclarationFile && !program.isSourceFileFromExternalLibrary(f));
// Analyze source files by finding imports. // Analyze source files by finding imports.
rootSourceFiles.forEach(sourceFile => visitor.visitNode(sourceFile)); sourceFiles.forEach(sourceFile => visitor.visitNode(sourceFile));
const {importsMap} = visitor; const {importsMap} = visitor;

View File

@ -117,7 +117,8 @@ function analyzeProject(tree: Tree, tsconfigPath: string, basePath: string):
const program = ts.createProgram(parsed.fileNames, parsed.options, host); const program = ts.createProgram(parsed.fileNames, parsed.options, host);
const typeChecker = program.getTypeChecker(); const typeChecker = program.getTypeChecker();
const sourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !); const sourceFiles = program.getSourceFiles().filter(
f => !f.isDeclarationFile && !program.isSourceFileFromExternalLibrary(f));
const queryVisitor = new NgQueryResolveVisitor(typeChecker); const queryVisitor = new NgQueryResolveVisitor(typeChecker);
// Analyze all project source-files and collect all queries that // Analyze all project source-files and collect all queries that

View File

@ -60,10 +60,11 @@ function runTemplateVariableAssignmentCheck(
const program = ts.createProgram(parsed.fileNames, parsed.options, host); const program = ts.createProgram(parsed.fileNames, parsed.options, host);
const typeChecker = program.getTypeChecker(); const typeChecker = program.getTypeChecker();
const templateVisitor = new NgComponentTemplateVisitor(typeChecker); const templateVisitor = new NgComponentTemplateVisitor(typeChecker);
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !); const sourceFiles = program.getSourceFiles().filter(
f => !f.isDeclarationFile && !program.isSourceFileFromExternalLibrary(f));
// Analyze source files by detecting HTML templates. // Analyze source files by detecting HTML templates.
rootSourceFiles.forEach(sourceFile => templateVisitor.visitNode(sourceFile)); sourceFiles.forEach(sourceFile => templateVisitor.visitNode(sourceFile));
const {resolvedTemplates} = templateVisitor; const {resolvedTemplates} = templateVisitor;
const collectedFailures: string[] = []; const collectedFailures: string[] = [];