88
99import { Rule , SchematicContext , Tree } from '@angular-devkit/schematics' ;
1010import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks' ;
11+ import { WorkspaceProject } from '@schematics/angular/utility/workspace-models' ;
1112
1213import { MigrationRuleType , runMigrationRules } from '../../update-tool' ;
1314import { TargetVersion } from '../../update-tool/target-version' ;
14- import { getProjectTsConfigPaths } from '../../utils/project-tsconfig-paths' ;
15+ import {
16+ getTargetTsconfigPath ,
17+ getWorkspaceConfigGracefully
18+ } from '../../utils/project-tsconfig-paths' ;
1519import { RuleUpgradeData } from '../upgrade-data' ;
1620
1721import { AttributeSelectorsRule } from './attribute-selectors-rule' ;
@@ -44,8 +48,8 @@ export const cdkMigrationRules: MigrationRuleType<RuleUpgradeData>[] = [
4448
4549type NullableMigrationRule = MigrationRuleType < RuleUpgradeData | null > ;
4650
47- type PostMigrationFn = ( context : SchematicContext , targetVersion : TargetVersion ,
48- hasFailure : boolean ) => void ;
51+ type PostMigrationFn =
52+ ( context : SchematicContext , targetVersion : TargetVersion , hasFailure : boolean ) => void ;
4953
5054/**
5155 * Creates a Angular schematic rule that runs the upgrade for the
@@ -56,35 +60,47 @@ export function createUpgradeRule(
5660 onMigrationCompleteFn ?: PostMigrationFn ) : Rule {
5761 return async ( tree : Tree , context : SchematicContext ) => {
5862 const logger = context . logger ;
59- const { buildPaths , testPaths } = getProjectTsConfigPaths ( tree ) ;
63+ const workspace = getWorkspaceConfigGracefully ( tree ) ;
6064
61- if ( ! buildPaths . length && ! testPaths . length ) {
62- // We don't want to throw here because it would mean that other migrations in the
63- // pipeline don't run either. Rather print an error message.
64- logger . error ( 'Could not find any TypeScript project in the CLI workspace configuration.' ) ;
65+ if ( workspace === null ) {
66+ logger . error ( 'Could not find workspace configuration file.' ) ;
6567 return ;
6668 }
6769
6870 // Keep track of all project source files which have been checked/migrated. This is
6971 // necessary because multiple TypeScript projects can contain the same source file and
7072 // we don't want to check these again, as this would result in duplicated failure messages.
7173 const analyzedFiles = new Set < string > ( ) ;
74+ const projectNames = Object . keys ( workspace . projects ) ;
7275 const rules = [ ...cdkMigrationRules , ...extraRules ] ;
7376 let hasRuleFailures = false ;
7477
75- const runMigration = ( tsconfigPath : string , isTestTarget : boolean ) => {
76- const result = runMigrationRules (
77- tree , context . logger , tsconfigPath , isTestTarget , targetVersion ,
78- rules , upgradeData , analyzedFiles ) ;
79-
80- hasRuleFailures = hasRuleFailures || result . hasFailures ;
81- } ;
82-
83- buildPaths . forEach ( p => runMigration ( p , false ) ) ;
84- testPaths . forEach ( p => runMigration ( p , true ) ) ;
78+ const runMigration =
79+ ( project : WorkspaceProject , tsconfigPath : string , isTestTarget : boolean ) => {
80+ const result = runMigrationRules (
81+ project , tree , context . logger , tsconfigPath , isTestTarget , targetVersion , rules ,
82+ upgradeData , analyzedFiles ) ;
83+ hasRuleFailures = hasRuleFailures || result . hasFailures ;
84+ } ;
85+
86+ for ( const projectName of projectNames ) {
87+ const project = workspace . projects [ projectName ] ;
88+ const buildTsconfigPath = getTargetTsconfigPath ( project , 'build' ) ;
89+ const testTsconfigPath = getTargetTsconfigPath ( project , 'test' ) ;
90+
91+ if ( ! buildTsconfigPath && ! testTsconfigPath ) {
92+ logger . warn ( `Could not find TypeScript project for project: ${ projectName } ` ) ;
93+ continue ;
94+ }
95+ if ( buildTsconfigPath !== null ) {
96+ runMigration ( project , buildTsconfigPath , false ) ;
97+ }
98+ if ( testTsconfigPath !== null ) {
99+ runMigration ( project , testTsconfigPath , true ) ;
100+ }
101+ }
85102
86103 let runPackageManager = false ;
87-
88104 // Run the global post migration static members for all migration rules.
89105 rules . forEach ( rule => {
90106 const actionResult = rule . globalPostMigration ( tree , context ) ;
0 commit comments