11import * as cp from "child_process" ;
22import * as net from "net" ;
33import * as stream from "stream" ;
4- import { CallbackEmitter , ActiveEvalReadable , ActiveEvalWritable , createUniqueEval } from "./evaluation " ;
4+ import { CallbackEmitter , ActiveEvalReadable , ActiveEvalWritable } from "@coder/protocol " ;
55import { client } from "./client" ;
66import { promisify } from "util" ;
77
@@ -33,27 +33,19 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
3333
3434 this . ae = client . run ( ( ae , command , method , args , options , callbackId ) => {
3535 const cp = __non_webpack_require__ ( "child_process" ) as typeof import ( "child_process" ) ;
36- const { maybeCallback, createUniqueEval, bindWritable, bindReadable, preserveEnv } = __non_webpack_require__ ( "@coder/ide/src/fill/evaluation" ) as typeof import ( "@coder/ide/src/fill/evaluation" ) ;
3736
38- preserveEnv ( options ) ;
37+ ae . preserveEnv ( options ) ;
3938
4039 let childProcess : cp . ChildProcess ;
4140 switch ( method ) {
4241 case "exec" :
43- childProcess = cp . exec ( command , options , maybeCallback ( ae , callbackId ) ) ;
42+ childProcess = cp . exec ( command , options , ae . maybeCallback ( callbackId ) ) ;
4443 break ;
4544 case "spawn" :
4645 childProcess = cp . spawn ( command , args , options ) ;
4746 break ;
4847 case "fork" :
49- const forkOptions = options as cp . ForkOptions ;
50- if ( forkOptions && forkOptions . env && forkOptions . env . AMD_ENTRYPOINT ) {
51- // TODO: This is vscode-specific and should be abstracted.
52- const { forkModule } = __non_webpack_require__ ( "@coder/server/src/vscode/bootstrapFork" ) as typeof import ( "@coder/server/src/vscode/bootstrapFork" ) ;
53- childProcess = forkModule ( forkOptions . env . AMD_ENTRYPOINT , args , forkOptions ) ;
54- } else {
55- childProcess = cp . fork ( command , args , options ) ;
56- }
48+ childProcess = ae . fork ( command , args , options ) ;
5749 break ;
5850 default :
5951 throw new Error ( `invalid method ${ method } ` ) ;
@@ -62,7 +54,7 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
6254 ae . on ( "disconnect" , ( ) => childProcess . disconnect ( ) ) ;
6355 ae . on ( "kill" , ( signal : string ) => childProcess . kill ( signal ) ) ;
6456 ae . on ( "ref" , ( ) => childProcess . ref ( ) ) ;
65- ae . on ( "send" , ( message : string , callbackId : number ) => childProcess . send ( message , maybeCallback ( ae , callbackId ) ) ) ;
57+ ae . on ( "send" , ( message : string , callbackId : number ) => childProcess . send ( message , ae . maybeCallback ( callbackId ) ) ) ;
6658 ae . on ( "unref" , ( ) => childProcess . unref ( ) ) ;
6759
6860 ae . emit ( "pid" , childProcess . pid ) ;
@@ -73,13 +65,16 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
7365 childProcess . on ( "message" , ( message ) => ae . emit ( "message" , message ) ) ;
7466
7567 if ( childProcess . stdin ) {
76- bindWritable ( createUniqueEval ( ae , "stdin" ) , childProcess . stdin ) ;
68+ const stdinAe = ae . createUnique ( "stdin" ) ;
69+ stdinAe . bindWritable ( childProcess . stdin ) ;
7770 }
7871 if ( childProcess . stdout ) {
79- bindReadable ( createUniqueEval ( ae , "stdout" ) , childProcess . stdout ) ;
72+ const stdoutAe = ae . createUnique ( "stdout" ) ;
73+ stdoutAe . bindReadable ( childProcess . stdout ) ;
8074 }
8175 if ( childProcess . stderr ) {
82- bindReadable ( createUniqueEval ( ae , "stderr" ) , childProcess . stderr ) ;
76+ const stderrAe = ae . createUnique ( "stderr" ) ;
77+ stderrAe . bindReadable ( childProcess . stderr ) ;
8378 }
8479
8580 return {
@@ -96,9 +91,9 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
9691 this . _connected = true ;
9792 } ) ;
9893
99- this . stdin = new ActiveEvalWritable ( createUniqueEval ( this . ae , "stdin" ) ) ;
100- this . stdout = new ActiveEvalReadable ( createUniqueEval ( this . ae , "stdout" ) ) ;
101- this . stderr = new ActiveEvalReadable ( createUniqueEval ( this . ae , "stderr" ) ) ;
94+ this . stdin = new ActiveEvalWritable ( this . ae . createUnique ( "stdin" ) ) ;
95+ this . stdout = new ActiveEvalReadable ( this . ae . createUnique ( "stdout" ) ) ;
96+ this . stderr = new ActiveEvalReadable ( this . ae . createUnique ( "stderr" ) ) ;
10297
10398 this . ae . on ( "close" , ( code , signal ) => this . emit ( "close" , code , signal ) ) ;
10499 this . ae . on ( "disconnect" , ( ) => this . emit ( "disconnect" ) ) ;
0 commit comments