@@ -962,7 +962,7 @@ export class ProjectService {
962962 public readonly globalPlugins : readonly string [ ] ;
963963 public readonly pluginProbeLocations : readonly string [ ] ;
964964 public readonly allowLocalPluginLoads : boolean ;
965- private currentPluginConfigOverrides : Map < string , any > | undefined ;
965+ /** @internal */ currentPluginConfigOverrides : Map < string , any > | undefined ;
966966
967967 public readonly typesMapLocation : string | undefined ;
968968
@@ -2189,7 +2189,6 @@ export class ProjectService {
21892189 /*lastFileExceededProgramSize*/ this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
21902190 options . compileOnSave === undefined ? true : options . compileOnSave ,
21912191 /*projectFilePath*/ undefined ,
2192- this . currentPluginConfigOverrides ,
21932192 watchOptionsAndErrors ?. watchOptions
21942193 ) ;
21952194 project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
@@ -2354,7 +2353,7 @@ export class ProjectService {
23542353 project . enableLanguageService ( ) ;
23552354 this . watchWildcards ( configFilename , configFileExistenceInfo , project ) ;
23562355 }
2357- project . enablePluginsWithOptions ( compilerOptions , this . currentPluginConfigOverrides ) ;
2356+ project . enablePluginsWithOptions ( compilerOptions ) ;
23582357 const filesToAdd = parsedCommandLine . fileNames . concat ( project . getExternalFiles ( ) ) ;
23592358 this . updateRootAndOptionsOfNonInferredProject ( project , filesToAdd , fileNamePropertyReader , compilerOptions , parsedCommandLine . typeAcquisition ! , parsedCommandLine . compileOnSave , parsedCommandLine . watchOptions ) ;
23602359 tracing ?. pop ( ) ;
@@ -2737,7 +2736,7 @@ export class ProjectService {
27372736 typeAcquisition = this . typeAcquisitionForInferredProjects ;
27382737 }
27392738 watchOptionsAndErrors = watchOptionsAndErrors || undefined ;
2740- const project = new InferredProject ( this , this . documentRegistry , compilerOptions , watchOptionsAndErrors ?. watchOptions , projectRootPath , currentDirectory , this . currentPluginConfigOverrides , typeAcquisition ) ;
2739+ const project = new InferredProject ( this , this . documentRegistry , compilerOptions , watchOptionsAndErrors ?. watchOptions , projectRootPath , currentDirectory , typeAcquisition ) ;
27412740 project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
27422741 if ( isSingleInferredProject ) {
27432742 this . inferredProjects . unshift ( project ) ;
@@ -4242,8 +4241,11 @@ export class ProjectService {
42424241 return false ;
42434242 }
42444243
4245- /** @internal */
4246- requestEnablePlugin ( project : Project , pluginConfigEntry : PluginImport , searchPaths : string [ ] , pluginConfigOverrides : Map < string , any > | undefined ) {
4244+ /**
4245+ * Performs the initial steps of enabling a plugin by finding and instantiating the module for a plugin either asynchronously or synchronously
4246+ * @internal
4247+ */
4248+ requestEnablePlugin ( project : Project , pluginConfigEntry : PluginImport , searchPaths : string [ ] ) {
42474249 if ( ! this . host . importPlugin && ! this . host . require ) {
42484250 this . logger . info ( "Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded" ) ;
42494251 return ;
@@ -4257,7 +4259,12 @@ export class ProjectService {
42574259
42584260 // If the host supports dynamic import, begin enabling the plugin asynchronously.
42594261 if ( this . host . importPlugin ) {
4260- const importPromise = project . beginEnablePluginAsync ( pluginConfigEntry , searchPaths , pluginConfigOverrides ) ;
4262+ const importPromise = Project . importServicePluginAsync (
4263+ pluginConfigEntry ,
4264+ searchPaths ,
4265+ this . host ,
4266+ s => this . logger . info ( s ) ,
4267+ ) as Promise < BeginEnablePluginResult > ;
42614268 this . pendingPluginEnablements ??= new Map ( ) ;
42624269 let promises = this . pendingPluginEnablements . get ( project ) ;
42634270 if ( ! promises ) this . pendingPluginEnablements . set ( project , promises = [ ] ) ;
@@ -4266,7 +4273,33 @@ export class ProjectService {
42664273 }
42674274
42684275 // Otherwise, load the plugin using `require`
4269- project . endEnablePlugin ( project . beginEnablePluginSync ( pluginConfigEntry , searchPaths , pluginConfigOverrides ) ) ;
4276+ this . endEnablePlugin ( project , Project . importServicePluginSync (
4277+ pluginConfigEntry ,
4278+ searchPaths ,
4279+ this . host ,
4280+ s => this . logger . info ( s ) ,
4281+ ) ) ;
4282+ }
4283+
4284+ /**
4285+ * Performs the remaining steps of enabling a plugin after its module has been instantiated.
4286+ * @internal
4287+ */
4288+ private endEnablePlugin ( project : Project , { pluginConfigEntry, resolvedModule, errorLogs } : BeginEnablePluginResult ) {
4289+ if ( resolvedModule ) {
4290+ const configurationOverride = this . currentPluginConfigOverrides ?. get ( pluginConfigEntry . name ) ;
4291+ if ( configurationOverride ) {
4292+ // Preserve the name property since it's immutable
4293+ const pluginName = pluginConfigEntry . name ;
4294+ pluginConfigEntry = configurationOverride ;
4295+ pluginConfigEntry . name = pluginName ;
4296+ }
4297+ project . enableProxy ( resolvedModule , pluginConfigEntry ) ;
4298+ }
4299+ else {
4300+ forEach ( errorLogs , message => this . logger . info ( message ) ) ;
4301+ this . logger . info ( `Couldn't find ${ pluginConfigEntry . name } ` ) ;
4302+ }
42704303 }
42714304
42724305 /** @internal */
@@ -4345,7 +4378,7 @@ export class ProjectService {
43454378 }
43464379
43474380 for ( const result of results ) {
4348- project . endEnablePlugin ( result ) ;
4381+ this . endEnablePlugin ( project , result ) ;
43494382 }
43504383
43514384 // Plugins may have modified external files, so mark the project as dirty.
0 commit comments