@@ -7,18 +7,14 @@ import { PluginMessage } from './message.js';
77
88const ipcMessageValidator = ajv . compile ( IpcMessageSchema ) ;
99
10- type Resolve = ( value : unknown ) => void ;
10+ type Resolve < T > = ( value : T ) => void ;
1111type Reject = ( reason ?: Error ) => void ;
1212
1313const resultFunctionName = ( cmd : string ) => `${ cmd } _Response` ;
1414
1515export class PluginProcess {
1616 process : ChildProcess ;
1717
18- constructor ( process : ChildProcess ) {
19- this . process = process ;
20- }
21-
2218 static async start ( pluginPath : string , name : string ) : Promise < PluginProcess > {
2319 const isTypescript = pluginPath . endsWith ( '.ts' ) ;
2420 const isTsxInstalled = PluginProcess . isTsxInstalled ( ) ;
@@ -48,7 +44,11 @@ export class PluginProcess {
4844 return new PluginProcess ( _process ) ;
4945 }
5046
51- async sendMessageForResult ( message : PluginMessage ) : Promise < unknown > {
47+ constructor ( process : ChildProcess ) {
48+ this . process = process ;
49+ }
50+
51+ async sendMessageForResult ( message : PluginMessage ) : Promise < IpcMessage > {
5252 return new Promise ( ( resolve , reject ) => {
5353 const handler = new SendMessageForResultHandler ( message , this . process , resolve , reject ) ;
5454
@@ -76,14 +76,14 @@ export class PluginProcess {
7676class SendMessageForResultHandler {
7777 messageToSend : PluginMessage ;
7878 process : ChildProcess ;
79- promiseResolve : Resolve ;
79+ promiseResolve : Resolve < IpcMessage > ;
8080 promiseReject : Reject ;
8181 timer : NodeJS . Timeout ;
8282
8383 constructor (
8484 messageToSend : PluginMessage ,
8585 process : ChildProcess ,
86- resolve : Resolve ,
86+ resolve : Resolve < IpcMessage > ,
8787 reject : Reject ,
8888 timeout = 600_000 , // Default time is 10 minutes for a command
8989 ) {
@@ -98,11 +98,11 @@ class SendMessageForResultHandler {
9898 ctx . debug ( JSON . stringify ( incomingMessage , null , 2 ) ) ;
9999
100100 if ( ! this . validateIpcMessage ( incomingMessage ) ) {
101- return this . reject ( new Error ( `Bad message from plugin. ${ JSON . stringify ( incomingMessage , null , 2 ) } ` ) )
101+ return this . reject ( new Error ( `Invalid message from plugin. ${ JSON . stringify ( incomingMessage , null , 2 ) } ` ) )
102102 }
103103
104104 if ( incomingMessage . cmd === resultFunctionName ( this . messageToSend . cmd ) ) {
105- this . resolve ( incomingMessage . data ) ;
105+ this . resolve ( incomingMessage ) ;
106106 }
107107 } ;
108108
@@ -115,7 +115,7 @@ class SendMessageForResultHandler {
115115 this . promiseReject ( err ) ;
116116 }
117117
118- private resolve = ( value : unknown ) => {
118+ private resolve = ( value : IpcMessage ) => {
119119 if ( this . timer . hasRef ( ) ) {
120120 clearTimeout ( this . timer ) ;
121121 }
0 commit comments