1
1
import * as cp from "child_process" ;
2
2
import * as net from "net" ;
3
3
import * as stream from "stream" ;
4
- import { CallbackEmitter , ActiveEvalReadable , ActiveEvalWritable , createUniqueEval } from "./evaluation " ;
4
+ import { CallbackEmitter , ActiveEvalReadable , ActiveEvalWritable } from "@coder/protocol " ;
5
5
import { client } from "./client" ;
6
6
import { promisify } from "util" ;
7
7
@@ -33,27 +33,19 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
33
33
34
34
this . ae = client . run ( ( ae , command , method , args , options , callbackId ) => {
35
35
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" ) ;
37
36
38
- preserveEnv ( options ) ;
37
+ ae . preserveEnv ( options ) ;
39
38
40
39
let childProcess : cp . ChildProcess ;
41
40
switch ( method ) {
42
41
case "exec" :
43
- childProcess = cp . exec ( command , options , maybeCallback ( ae , callbackId ) ) ;
42
+ childProcess = cp . exec ( command , options , ae . maybeCallback ( callbackId ) ) ;
44
43
break ;
45
44
case "spawn" :
46
45
childProcess = cp . spawn ( command , args , options ) ;
47
46
break ;
48
47
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 ) ;
57
49
break ;
58
50
default :
59
51
throw new Error ( `invalid method ${ method } ` ) ;
@@ -62,7 +54,7 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
62
54
ae . on ( "disconnect" , ( ) => childProcess . disconnect ( ) ) ;
63
55
ae . on ( "kill" , ( signal : string ) => childProcess . kill ( signal ) ) ;
64
56
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 ) ) ) ;
66
58
ae . on ( "unref" , ( ) => childProcess . unref ( ) ) ;
67
59
68
60
ae . emit ( "pid" , childProcess . pid ) ;
@@ -73,13 +65,16 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
73
65
childProcess . on ( "message" , ( message ) => ae . emit ( "message" , message ) ) ;
74
66
75
67
if ( childProcess . stdin ) {
76
- bindWritable ( createUniqueEval ( ae , "stdin" ) , childProcess . stdin ) ;
68
+ const stdinAe = ae . createUnique ( "stdin" ) ;
69
+ stdinAe . bindWritable ( childProcess . stdin ) ;
77
70
}
78
71
if ( childProcess . stdout ) {
79
- bindReadable ( createUniqueEval ( ae , "stdout" ) , childProcess . stdout ) ;
72
+ const stdoutAe = ae . createUnique ( "stdout" ) ;
73
+ stdoutAe . bindReadable ( childProcess . stdout ) ;
80
74
}
81
75
if ( childProcess . stderr ) {
82
- bindReadable ( createUniqueEval ( ae , "stderr" ) , childProcess . stderr ) ;
76
+ const stderrAe = ae . createUnique ( "stderr" ) ;
77
+ stderrAe . bindReadable ( childProcess . stderr ) ;
83
78
}
84
79
85
80
return {
@@ -96,9 +91,9 @@ class ChildProcess extends CallbackEmitter implements cp.ChildProcess {
96
91
this . _connected = true ;
97
92
} ) ;
98
93
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" ) ) ;
102
97
103
98
this . ae . on ( "close" , ( code , signal ) => this . emit ( "close" , code , signal ) ) ;
104
99
this . ae . on ( "disconnect" , ( ) => this . emit ( "disconnect" ) ) ;
0 commit comments