@@ -33,35 +33,6 @@ interface IProjectConfigurationFileEntry<TConfigFile> {
33
33
loader : ProjectConfigurationFile < TConfigFile > ;
34
34
}
35
35
36
- const projectConfigurationFileRegistry : Map < string , IProjectConfigurationFileEntry < unknown > > = new Map ( ) ;
37
- function getAndValidateProjectConfigurationFileEntry < TConfigFile > (
38
- options : IProjectConfigurationFileSpecification < TConfigFile >
39
- ) : IProjectConfigurationFileEntry < TConfigFile > {
40
- let entry : IProjectConfigurationFileEntry < TConfigFile > | undefined = projectConfigurationFileRegistry . get (
41
- options . projectRelativeFilePath
42
- ) as IProjectConfigurationFileEntry < TConfigFile > | undefined ;
43
-
44
- if ( ! entry ) {
45
- entry = {
46
- options : Object . freeze ( options ) ,
47
- loader : new ProjectConfigurationFile < TConfigFile > ( options )
48
- } ;
49
- } else if ( options !== entry . options ) {
50
- throw new Error (
51
- `The project configuration file for ${ options . projectRelativeFilePath } has already been loaded with different options. Please ensure that options object used to load the configuration file is the same referenced object in all calls.`
52
- ) ;
53
- }
54
-
55
- return entry ;
56
- }
57
- /**
58
- * For unit test usage.
59
- * @internal
60
- */
61
- export function _clearProjectConfigurationFileRegistry ( ) : void {
62
- projectConfigurationFileRegistry . clear ( ) ;
63
- }
64
-
65
36
/**
66
37
* @public
67
38
*/
@@ -75,6 +46,8 @@ export class HeftConfiguration {
75
46
private _terminalProvider ! : ITerminalProvider ;
76
47
private _rigPackageResolver ! : RigPackageResolver ;
77
48
49
+ private readonly _knownConfigurationFiles : Map < string , IProjectConfigurationFileEntry < unknown > > = new Map ( ) ;
50
+
78
51
/**
79
52
* Project build folder path. This is the folder containing the project's package.json file.
80
53
*/
@@ -197,7 +170,7 @@ export class HeftConfiguration {
197
170
options : IProjectConfigurationFileSpecification < TConfigFile > ,
198
171
terminal : ITerminal
199
172
) : TConfigFile | undefined {
200
- const { loader } = getAndValidateProjectConfigurationFileEntry ( options ) ;
173
+ const loader : ProjectConfigurationFile < TConfigFile > = this . _getConfigFileLoader ( options ) ;
201
174
return loader . tryLoadConfigurationFileForProject ( terminal , this . _buildFolderPath , this . _rigConfig ) ;
202
175
}
203
176
@@ -211,7 +184,7 @@ export class HeftConfiguration {
211
184
options : IProjectConfigurationFileSpecification < TConfigFile > ,
212
185
terminal : ITerminal
213
186
) : Promise < TConfigFile | undefined > {
214
- const { loader } = getAndValidateProjectConfigurationFileEntry ( options ) ;
187
+ const loader : ProjectConfigurationFile < TConfigFile > = this . _getConfigFileLoader ( options ) ;
215
188
return loader . tryLoadConfigurationFileForProjectAsync ( terminal , this . _buildFolderPath , this . _rigConfig ) ;
216
189
}
217
190
@@ -241,4 +214,25 @@ export class HeftConfiguration {
241
214
configuration . _globalTerminal = new Terminal ( options . terminalProvider ) ;
242
215
return configuration ;
243
216
}
217
+
218
+ private _getConfigFileLoader < TConfigFile > (
219
+ options : IProjectConfigurationFileSpecification < TConfigFile >
220
+ ) : ProjectConfigurationFile < TConfigFile > {
221
+ let entry : IProjectConfigurationFileEntry < TConfigFile > | undefined = this . _knownConfigurationFiles . get (
222
+ options . projectRelativeFilePath
223
+ ) as IProjectConfigurationFileEntry < TConfigFile > | undefined ;
224
+
225
+ if ( ! entry ) {
226
+ entry = {
227
+ options : Object . freeze ( options ) ,
228
+ loader : new ProjectConfigurationFile < TConfigFile > ( options )
229
+ } ;
230
+ } else if ( options !== entry . options ) {
231
+ throw new Error (
232
+ `The project configuration file for ${ options . projectRelativeFilePath } has already been loaded with different options. Please ensure that options object used to load the configuration file is the same referenced object in all calls.`
233
+ ) ;
234
+ }
235
+
236
+ return entry . loader ;
237
+ }
244
238
}
0 commit comments