88
99import { Rule , SchematicContext , Tree } from '@angular-devkit/schematics' ;
1010
11- import { Constructor , runMigrationRules } from '../../update-tool' ;
12- import { MigrationRule } from '../../update-tool/migration-rule' ;
11+ import { MigrationRuleType , runMigrationRules } from '../../update-tool' ;
1312import { TargetVersion } from '../../update-tool/target-version' ;
1413import { getProjectTsConfigPaths } from '../../utils/project-tsconfig-paths' ;
1514import { RuleUpgradeData } from '../upgrade-data' ;
@@ -28,7 +27,7 @@ import {PropertyNamesRule} from './property-names-rule';
2827
2928
3029/** List of migration rules which run for the CDK update. */
31- export const cdkMigrationRules : Constructor < MigrationRule < RuleUpgradeData > > [ ] = [
30+ export const cdkMigrationRules : MigrationRuleType < RuleUpgradeData > [ ] = [
3231 AttributeSelectorsRule ,
3332 ClassInheritanceRule ,
3433 ClassNamesRule ,
@@ -42,7 +41,7 @@ export const cdkMigrationRules: Constructor<MigrationRule<RuleUpgradeData>>[] =
4241 PropertyNamesRule ,
4342] ;
4443
45- type NullableMigrationRule = Constructor < MigrationRule < RuleUpgradeData | null > > ;
44+ type NullableMigrationRule = MigrationRuleType < RuleUpgradeData | null > ;
4645
4746/**
4847 * Creates a Angular schematic rule that runs the upgrade for the
@@ -51,7 +50,7 @@ type NullableMigrationRule = Constructor<MigrationRule<RuleUpgradeData|null>>;
5150export function createUpgradeRule (
5251 targetVersion : TargetVersion , extraRules : NullableMigrationRule [ ] , upgradeData : RuleUpgradeData ,
5352 onMigrationCompleteFn ?: ( targetVersion : TargetVersion , hasFailures : boolean ) => void ) : Rule {
54- return ( tree : Tree , context : SchematicContext ) => {
53+ return async ( tree : Tree , context : SchematicContext ) => {
5554 const logger = context . logger ;
5655 const { buildPaths, testPaths} = getProjectTsConfigPaths ( tree ) ;
5756
@@ -66,13 +65,26 @@ export function createUpgradeRule(
6665 // necessary because multiple TypeScript projects can contain the same source file and
6766 // we don't want to check these again, as this would result in duplicated failure messages.
6867 const analyzedFiles = new Set < string > ( ) ;
68+ const rules = [ ...cdkMigrationRules , ...extraRules ] ;
6969 let hasRuleFailures = false ;
7070
71- for ( const tsconfigPath of [ ...buildPaths , ...testPaths ] ) {
72- hasRuleFailures = hasRuleFailures || runMigrationRules (
73- tree , context . logger , tsconfigPath , targetVersion , [ ...cdkMigrationRules , ...extraRules ] ,
74- upgradeData , analyzedFiles ) ;
75- }
71+ const runMigration = ( tsconfigPath : string , isTestTarget : boolean ) => {
72+ const result = runMigrationRules (
73+ tree , context . logger , tsconfigPath , isTestTarget , targetVersion ,
74+ rules , upgradeData , analyzedFiles ) ;
75+
76+ hasRuleFailures = hasRuleFailures || result . hasFailures ;
77+ } ;
78+
79+ buildPaths . forEach ( p => runMigration ( p , false ) ) ;
80+ testPaths . forEach ( p => runMigration ( p , true ) ) ;
81+
82+ // Run the global post migration static members for all migration rules.
83+ rules . forEach ( r => r . globalPostMigration ( tree , context ) ) ;
84+
85+ // Execute all asynchronous tasks and await them here. We want to run
86+ // the "onMigrationCompleteFn" after all work is done.
87+ await context . engine . executePostTasks ( ) . toPromise ( ) ;
7688
7789 if ( onMigrationCompleteFn ) {
7890 onMigrationCompleteFn ( targetVersion , hasRuleFailures ) ;
0 commit comments