@@ -962,7 +962,7 @@ export class ProjectService {
962
962
public readonly globalPlugins : readonly string [ ] ;
963
963
public readonly pluginProbeLocations : readonly string [ ] ;
964
964
public readonly allowLocalPluginLoads : boolean ;
965
- private currentPluginConfigOverrides : Map < string , any > | undefined ;
965
+ /** @internal */ currentPluginConfigOverrides : Map < string , any > | undefined ;
966
966
967
967
public readonly typesMapLocation : string | undefined ;
968
968
@@ -2189,7 +2189,6 @@ export class ProjectService {
2189
2189
/*lastFileExceededProgramSize*/ this . getFilenameForExceededTotalSizeLimitForNonTsFiles ( projectFileName , compilerOptions , files , externalFilePropertyReader ) ,
2190
2190
options . compileOnSave === undefined ? true : options . compileOnSave ,
2191
2191
/*projectFilePath*/ undefined ,
2192
- this . currentPluginConfigOverrides ,
2193
2192
watchOptionsAndErrors ?. watchOptions
2194
2193
) ;
2195
2194
project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
@@ -2354,7 +2353,7 @@ export class ProjectService {
2354
2353
project . enableLanguageService ( ) ;
2355
2354
this . watchWildcards ( configFilename , configFileExistenceInfo , project ) ;
2356
2355
}
2357
- project . enablePluginsWithOptions ( compilerOptions , this . currentPluginConfigOverrides ) ;
2356
+ project . enablePluginsWithOptions ( compilerOptions ) ;
2358
2357
const filesToAdd = parsedCommandLine . fileNames . concat ( project . getExternalFiles ( ) ) ;
2359
2358
this . updateRootAndOptionsOfNonInferredProject ( project , filesToAdd , fileNamePropertyReader , compilerOptions , parsedCommandLine . typeAcquisition ! , parsedCommandLine . compileOnSave , parsedCommandLine . watchOptions ) ;
2360
2359
tracing ?. pop ( ) ;
@@ -2737,7 +2736,7 @@ export class ProjectService {
2737
2736
typeAcquisition = this . typeAcquisitionForInferredProjects ;
2738
2737
}
2739
2738
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 ) ;
2741
2740
project . setProjectErrors ( watchOptionsAndErrors ?. errors ) ;
2742
2741
if ( isSingleInferredProject ) {
2743
2742
this . inferredProjects . unshift ( project ) ;
@@ -4242,8 +4241,11 @@ export class ProjectService {
4242
4241
return false ;
4243
4242
}
4244
4243
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 [ ] ) {
4247
4249
if ( ! this . host . importPlugin && ! this . host . require ) {
4248
4250
this . logger . info ( "Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded" ) ;
4249
4251
return ;
@@ -4257,7 +4259,12 @@ export class ProjectService {
4257
4259
4258
4260
// If the host supports dynamic import, begin enabling the plugin asynchronously.
4259
4261
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 > ;
4261
4268
this . pendingPluginEnablements ??= new Map ( ) ;
4262
4269
let promises = this . pendingPluginEnablements . get ( project ) ;
4263
4270
if ( ! promises ) this . pendingPluginEnablements . set ( project , promises = [ ] ) ;
@@ -4266,7 +4273,33 @@ export class ProjectService {
4266
4273
}
4267
4274
4268
4275
// 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
+ }
4270
4303
}
4271
4304
4272
4305
/** @internal */
@@ -4345,7 +4378,7 @@ export class ProjectService {
4345
4378
}
4346
4379
4347
4380
for ( const result of results ) {
4348
- project . endEnablePlugin ( result ) ;
4381
+ this . endEnablePlugin ( project , result ) ;
4349
4382
}
4350
4383
4351
4384
// Plugins may have modified external files, so mark the project as dirty.
0 commit comments