@@ -558,42 +558,45 @@ export class ProjectChangeAnalyzer {
558558 }
559559 }
560560
561- const changedCatalogPackages : Map < string , Set < string > > = new Map < string , Set < string > > ( ) ;
561+ const changedCatalogPackages : Map < string , Set < string > > = new Map ( ) ;
562+ const currentCatalogEntries : Map < string , Record < string , string > > = new Map (
563+ Object . entries ( currentCatalogs )
564+ ) ;
562565
563566 if ( oldCatalogs === undefined ) {
564567 // Could not load old catalogs — treat all packages in all current catalogs as changed
565- for ( const [ catalogName , packages ] of Object . entries ( currentCatalogs ) ) {
568+ for ( const [ catalogName , packages ] of currentCatalogEntries ) {
566569 changedCatalogPackages . set ( catalogName , new Set ( Object . keys ( packages ) ) ) ;
567570 }
568571 } else {
569572 // Check current catalogs for new or modified package entries
570- for ( const [ catalogName , packages ] of Object . entries ( currentCatalogs ) ) {
573+ for ( const [ catalogName , packages ] of currentCatalogEntries ) {
571574 const oldPackages : Record < string , string > | undefined = oldCatalogs [ catalogName ] ;
572575 if ( ! oldPackages ) {
573576 // Entire catalog is new — all packages in it are changed
574577 changedCatalogPackages . set ( catalogName , new Set ( Object . keys ( packages ) ) ) ;
575578 continue ;
576579 }
577- const changedPkgs : Set < string > = new Set < string > ( ) ;
580+ const changedPackages : Set < string > = new Set ( ) ;
578581 for ( const [ pkgName , version ] of Object . entries ( packages ) ) {
579582 if ( oldPackages [ pkgName ] !== version ) {
580- changedPkgs . add ( pkgName ) ;
583+ changedPackages . add ( pkgName ) ;
581584 }
582585 }
583586 // Check for packages that were removed from this catalog
584587 for ( const pkgName of Object . keys ( oldPackages ) ) {
585- if ( ! ( pkgName in packages ) ) {
586- changedPkgs . add ( pkgName ) ;
588+ if ( ! Object . prototype . hasOwnProperty . call ( packages , pkgName ) ) {
589+ changedPackages . add ( pkgName ) ;
587590 }
588591 }
589- if ( changedPkgs . size > 0 ) {
590- changedCatalogPackages . set ( catalogName , changedPkgs ) ;
592+ if ( changedPackages . size > 0 ) {
593+ changedCatalogPackages . set ( catalogName , changedPackages ) ;
591594 }
592595 }
593596
594597 // Check for catalogs that were entirely removed
595598 for ( const [ catalogName , oldPackages ] of Object . entries ( oldCatalogs ) ) {
596- if ( ! ( catalogName in currentCatalogs ) ) {
599+ if ( ! Object . prototype . hasOwnProperty . call ( currentCatalogs , catalogName ) ) {
597600 changedCatalogPackages . set ( catalogName , new Set ( Object . keys ( oldPackages ) ) ) ;
598601 }
599602 }
@@ -602,38 +605,28 @@ export class ProjectChangeAnalyzer {
602605 if ( changedCatalogPackages . size > 0 ) {
603606 // Check each project in the subspace to see if it depends on a changed catalog package
604607 const subspaceProjects : RushConfigurationProject [ ] = subspace . getProjects ( ) ;
605- for ( const project of subspaceProjects ) {
606- const { dependencies, devDependencies, optionalDependencies, peerDependencies } = project . packageJson ;
607- const allDeps : Record < string , string > [ ] = [
608- dependencies ?? { } ,
609- devDependencies ?? { } ,
610- optionalDependencies ?? { } ,
611- peerDependencies ?? { }
612- ] ;
613-
614- let isAffected : boolean = false ;
615- for ( const deps of allDeps ) {
616- if ( isAffected ) {
617- break ;
618- }
619- for ( const [ depName , depVersion ] of Object . entries ( deps ) ) {
620- const specifier : DependencySpecifier = DependencySpecifier . parseWithCache ( depName , depVersion ) ;
621- if ( specifier . specifierType === DependencySpecifierType . Catalog ) {
622- // versionSpecifier holds the catalog name (empty string for "catalog:")
623- const catalogName : string = specifier . versionSpecifier || 'default' ;
624- const changedPkgs : Set < string > | undefined = changedCatalogPackages . get ( catalogName ) ;
625- if ( changedPkgs ?. has ( depName ) ) {
626- isAffected = true ;
627- break ;
628- }
608+ subspaceProjects . forEach ( ( project ) => {
609+ const { dependencies, devDependencies, optionalDependencies, peerDependencies } =
610+ project . packageJson ;
611+ const allDependencies : Set < [ string , string ] > = new Set (
612+ [ dependencies , devDependencies , optionalDependencies , peerDependencies ] . flatMap ( ( deps ) =>
613+ Object . entries ( deps ?? { } )
614+ )
615+ ) ;
616+
617+ for ( const [ depName , depVersion ] of allDependencies ) {
618+ const specifier : DependencySpecifier = DependencySpecifier . parseWithCache ( depName , depVersion ) ;
619+ if ( specifier . specifierType === DependencySpecifierType . Catalog ) {
620+ // versionSpecifier holds the catalog name (empty string for "catalog:")
621+ const catalogName : string = specifier . versionSpecifier || 'default' ;
622+ const changedPkgs : Set < string > | undefined = changedCatalogPackages . get ( catalogName ) ;
623+ if ( changedPkgs ?. has ( depName ) ) {
624+ changedProjects . add ( project ) ;
625+ return ;
629626 }
630627 }
631628 }
632-
633- if ( isAffected ) {
634- changedProjects . add ( project ) ;
635- }
636- }
629+ } ) ;
637630 }
638631 }
639632}
0 commit comments