* Migrates the project to the specified target version. * @param migrationTypes Migrations that should be run. * @param target Version the project should be updated to. Can be `null` if the set of * specified migrations runs regardless of a target version. * @param data Upgrade data th
(
migrationTypes: MigrationCtor<Data, Context>[],
target: TargetVersion | null,
data: Data,
additionalStylesheetPaths?: string[],
limitToDirectory?: string,
)
| 55 | * @param limitToDirectory If specified, changes will be limited to the given directory. |
| 56 | */ |
| 57 | migrate<Data>( |
| 58 | migrationTypes: MigrationCtor<Data, Context>[], |
| 59 | target: TargetVersion | null, |
| 60 | data: Data, |
| 61 | additionalStylesheetPaths?: string[], |
| 62 | limitToDirectory?: string, |
| 63 | ): {hasFailures: boolean} { |
| 64 | limitToDirectory &&= this._fileSystem.resolve(limitToDirectory); |
| 65 | |
| 66 | // Create instances of the specified migrations. |
| 67 | const migrations = this._createMigrations(migrationTypes, target, data); |
| 68 | // Creates the component resource collector. The collector can visit arbitrary |
| 69 | // TypeScript nodes and will find Angular component resources. Resources include |
| 70 | // templates and stylesheets. It also captures inline stylesheets and templates. |
| 71 | const resourceCollector = new ComponentResourceCollector(this._typeChecker, this._fileSystem); |
| 72 | // Collect all of the TypeScript source files we want to migrate. We don't |
| 73 | // migrate type definition files, or source files from external libraries. |
| 74 | const sourceFiles = this._program.getSourceFiles().filter(f => { |
| 75 | return ( |
| 76 | !f.isDeclarationFile && |
| 77 | (limitToDirectory == null || |
| 78 | this._fileSystem.resolve(f.fileName).startsWith(limitToDirectory)) && |
| 79 | !this._program.isSourceFileFromExternalLibrary(f) |
| 80 | ); |
| 81 | }); |
| 82 | |
| 83 | // Helper function that visits a given TypeScript node and collects all referenced |
| 84 | // component resources (i.e. stylesheets or templates). Additionally, the helper |
| 85 | // visits the node in each instantiated migration. |
| 86 | const visitNodeAndCollectResources = (node: ts.Node) => { |
| 87 | migrations.forEach(r => r.visitNode(node)); |
| 88 | ts.forEachChild(node, visitNodeAndCollectResources); |
| 89 | resourceCollector.visitNode(node); |
| 90 | }; |
| 91 | |
| 92 | // Walk through all source file, if it has not been visited before, and |
| 93 | // visit found nodes while collecting potential resources. |
| 94 | sourceFiles.forEach(sourceFile => { |
| 95 | const resolvedPath = this._fileSystem.resolve(sourceFile.fileName); |
| 96 | // Do not visit source files which have been checked as part of a |
| 97 | // previously migrated TypeScript project. |
| 98 | if (!this._analyzedFiles.has(resolvedPath)) { |
| 99 | visitNodeAndCollectResources(sourceFile); |
| 100 | this._analyzedFiles.add(resolvedPath); |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | // Walk through all resolved templates and visit them in each instantiated |
| 105 | // migration. Note that this can only happen after source files have been |
| 106 | // visited because we find templates through the TypeScript source files. |
| 107 | resourceCollector.resolvedTemplates.forEach(template => { |
| 108 | // Do not visit the template if it has been checked before. Inline |
| 109 | // templates cannot be referenced multiple times. |
| 110 | if (template.inline || !this._analyzedFiles.has(template.filePath)) { |
| 111 | migrations.forEach(m => m.visitTemplate(template)); |
| 112 | this._analyzedFiles.add(template.filePath); |
| 113 | } |
| 114 | }); |
no test coverage detected