@@ -74,4 +74,80 @@ describe(Subspace.name, () => {
7474 expect ( hashWithCatalogs ) . toBeDefined ( ) ;
7575 } ) ;
7676 } ) ;
77+
78+ describe ( 'getPackageJsonInjectedDependenciesHash' , ( ) => {
79+ it ( 'returns undefined when no injected dependencies exist' , ( ) => {
80+ const rushJsonFilename : string = path . resolve ( __dirname , 'repo' , 'rush-pnpm.json' ) ;
81+ const rushConfiguration : RushConfiguration =
82+ RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
83+ const defaultSubspace : Subspace = rushConfiguration . defaultSubspace ;
84+
85+ const hash : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
86+ expect ( hash ) . toBeUndefined ( ) ;
87+ } ) ;
88+
89+ it ( 'computes a hash when injected dependencies exist' , ( ) => {
90+ const rushJsonFilename : string = path . resolve ( __dirname , 'repoInjectedDeps' , 'rush.json' ) ;
91+ const rushConfiguration : RushConfiguration =
92+ RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
93+ const defaultSubspace : Subspace = rushConfiguration . defaultSubspace ;
94+
95+ const hash : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
96+ expect ( hash ) . toBeDefined ( ) ;
97+ expect ( typeof hash ) . toBe ( 'string' ) ;
98+ expect ( hash ) . toHaveLength ( 40 ) ; // SHA1 hash
99+ } ) ;
100+
101+ it ( 'does not change when devDependencies of the injected package change' , ( ) => {
102+ const rushJsonFilename : string = path . resolve ( __dirname , 'repoInjectedDeps' , 'rush.json' ) ;
103+ const rushConfiguration : RushConfiguration =
104+ RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
105+ const defaultSubspace : Subspace = rushConfiguration . defaultSubspace ;
106+
107+ const hashBefore : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
108+
109+ // Mutate devDependencies of the injected provider package
110+ const providerProject = rushConfiguration . getProjectByName ( 'provider' ) ! ;
111+ const originalDevDeps = providerProject . packageJson . devDependencies ;
112+ providerProject . packageJson . devDependencies = {
113+ ...originalDevDeps ,
114+ jest : '^29.0.0'
115+ } ;
116+
117+ const hashAfter : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
118+
119+ expect ( hashBefore ) . toBeDefined ( ) ;
120+ expect ( hashAfter ) . toBeDefined ( ) ;
121+ expect ( hashBefore ) . toBe ( hashAfter ) ;
122+
123+ // Restore
124+ providerProject . packageJson . devDependencies = originalDevDeps ;
125+ } ) ;
126+
127+ it ( 'changes when production dependencies of the injected package change' , ( ) => {
128+ const rushJsonFilename : string = path . resolve ( __dirname , 'repoInjectedDeps' , 'rush.json' ) ;
129+ const rushConfiguration : RushConfiguration =
130+ RushConfiguration . loadFromConfigurationFile ( rushJsonFilename ) ;
131+ const defaultSubspace : Subspace = rushConfiguration . defaultSubspace ;
132+
133+ const hashBefore : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
134+
135+ // Mutate dependencies of the injected provider package
136+ const providerProject = rushConfiguration . getProjectByName ( 'provider' ) ! ;
137+ const originalDeps = providerProject . packageJson . dependencies ;
138+ providerProject . packageJson . dependencies = {
139+ ...originalDeps ,
140+ axios : '^1.6.0'
141+ } ;
142+
143+ const hashAfter : string | undefined = defaultSubspace . getPackageJsonInjectedDependenciesHash ( ) ;
144+
145+ expect ( hashBefore ) . toBeDefined ( ) ;
146+ expect ( hashAfter ) . toBeDefined ( ) ;
147+ expect ( hashBefore ) . not . toBe ( hashAfter ) ;
148+
149+ // Restore
150+ providerProject . packageJson . dependencies = originalDeps ;
151+ } ) ;
152+ } ) ;
77153} ) ;
0 commit comments