@@ -158,49 +158,47 @@ export class NodeTypingsInstaller extends TypingsInstaller {
158
158
this . typesRegistry = loadTypesRegistryFile ( getTypesRegistryFileLocation ( globalTypingsCacheLocation ) , this . installTypingHost , this . log ) ;
159
159
}
160
160
161
- listen ( ) {
162
- process . on ( "message" , ( req : TypingInstallerRequestUnion ) => {
163
- if ( this . delayedInitializationError ) {
164
- // report initializationFailed error
165
- this . sendResponse ( this . delayedInitializationError ) ;
166
- this . delayedInitializationError = undefined ;
161
+ handleRequest ( req : TypingInstallerRequestUnion ) {
162
+ if ( this . delayedInitializationError ) {
163
+ // report initializationFailed error
164
+ this . sendResponse ( this . delayedInitializationError ) ;
165
+ this . delayedInitializationError = undefined ;
166
+ }
167
+ switch ( req . kind ) {
168
+ case "discover" :
169
+ this . install ( req ) ;
170
+ break ;
171
+ case "closeProject" :
172
+ this . closeProject ( req ) ;
173
+ break ;
174
+ case "typesRegistry" : {
175
+ const typesRegistry : { [ key : string ] : MapLike < string > } = { } ;
176
+ this . typesRegistry . forEach ( ( value , key ) => {
177
+ typesRegistry [ key ] = value ;
178
+ } ) ;
179
+ const response : TypesRegistryResponse = { kind : EventTypesRegistry , typesRegistry } ;
180
+ this . sendResponse ( response ) ;
181
+ break ;
167
182
}
168
- switch ( req . kind ) {
169
- case "discover" :
170
- this . install ( req ) ;
171
- break ;
172
- case "closeProject" :
173
- this . closeProject ( req ) ;
174
- break ;
175
- case "typesRegistry" : {
176
- const typesRegistry : { [ key : string ] : MapLike < string > } = { } ;
177
- this . typesRegistry . forEach ( ( value , key ) => {
178
- typesRegistry [ key ] = value ;
183
+ case "installPackage" : {
184
+ const { fileName, packageName, projectName, projectRootPath } = req ;
185
+ const cwd = getDirectoryOfPackageJson ( fileName , this . installTypingHost ) || projectRootPath ;
186
+ if ( cwd ) {
187
+ this . installWorker ( - 1 , [ packageName ] , cwd , success => {
188
+ const message = success ? `Package ${ packageName } installed.` : `There was an error installing ${ packageName } .` ;
189
+ const response : PackageInstalledResponse = { kind : ActionPackageInstalled , projectName, success, message } ;
190
+ this . sendResponse ( response ) ;
179
191
} ) ;
180
- const response : TypesRegistryResponse = { kind : EventTypesRegistry , typesRegistry } ;
181
- this . sendResponse ( response ) ;
182
- break ;
183
192
}
184
- case "installPackage" : {
185
- const { fileName, packageName, projectName, projectRootPath } = req ;
186
- const cwd = getDirectoryOfPackageJson ( fileName , this . installTypingHost ) || projectRootPath ;
187
- if ( cwd ) {
188
- this . installWorker ( - 1 , [ packageName ] , cwd , success => {
189
- const message = success ? `Package ${ packageName } installed.` : `There was an error installing ${ packageName } .` ;
190
- const response : PackageInstalledResponse = { kind : ActionPackageInstalled , projectName, success, message } ;
191
- this . sendResponse ( response ) ;
192
- } ) ;
193
- }
194
- else {
195
- const response : PackageInstalledResponse = { kind : ActionPackageInstalled , projectName, success : false , message : "Could not determine a project root path." } ;
196
- this . sendResponse ( response ) ;
197
- }
198
- break ;
193
+ else {
194
+ const response : PackageInstalledResponse = { kind : ActionPackageInstalled , projectName, success : false , message : "Could not determine a project root path." } ;
195
+ this . sendResponse ( response ) ;
199
196
}
200
- default :
201
- Debug . assertNever ( req ) ;
197
+ break ;
202
198
}
203
- } ) ;
199
+ default :
200
+ Debug . assertNever ( req ) ;
201
+ }
204
202
}
205
203
206
204
protected sendResponse ( response : TypingInstallerResponseUnion ) {
@@ -272,8 +270,11 @@ process.on("disconnect", () => {
272
270
}
273
271
process . exit ( 0 ) ;
274
272
} ) ;
275
- const installer = new NodeTypingsInstaller ( globalTypingsCacheLocation ! , typingSafeListLocation ! , typesMapLocation ! , npmLocation , validateDefaultNpmLocation , /*throttleLimit*/ 5 , log ) ; // TODO: GH#18217
276
- installer . listen ( ) ;
273
+ let installer : NodeTypingsInstaller | undefined ;
274
+ process . on ( "message" , ( req : TypingInstallerRequestUnion ) => {
275
+ installer ??= new NodeTypingsInstaller ( globalTypingsCacheLocation ! , typingSafeListLocation ! , typesMapLocation ! , npmLocation , validateDefaultNpmLocation , /*throttleLimit*/ 5 , log ) ; // TODO: GH#18217
276
+ installer . handleRequest ( req ) ;
277
+ } ) ;
277
278
278
279
function indent ( newline : string , str : string | undefined ) : string {
279
280
return str && str . length
0 commit comments