@@ -2,9 +2,20 @@ import * as cp from "child_process";
2
2
import * as fs from "fs" ;
3
3
import * as net from "net" ;
4
4
import * as path from "path" ;
5
- import { logger , field } from "@coder/logger/src" ;
5
+ import { Logger , logger , field } from "@coder/logger/src" ;
6
6
7
- declare var __non_webpack_require__ : typeof require ;
7
+ const getChildLogger = ( modulePath : string ) : Logger => {
8
+ const basename = modulePath . split ( "/" ) . pop ( ) ! ;
9
+ let i = 0 ;
10
+ for ( ; i < basename . length ; i ++ ) {
11
+ const character = basename . charAt ( i ) ;
12
+ if ( character === character . toUpperCase ( ) ) {
13
+ break ;
14
+ }
15
+ }
16
+
17
+ return logger . named ( basename . substring ( 0 , i ) ) ;
18
+ } ;
8
19
9
20
export const requireModule = ( modulePath : string ) : void => {
10
21
process . env . AMD_ENTRYPOINT = modulePath ;
@@ -16,6 +27,7 @@ export const requireModule = (modulePath: string): void => {
16
27
process . emit ( "message" , JSON . parse ( data . toString ( ) ) , undefined ) ;
17
28
} ) ;
18
29
30
+ // tslint:disable-next-line no-any
19
31
process . send = ( message : any ) : void => {
20
32
socket . write ( JSON . stringify ( message ) ) ;
21
33
} ;
@@ -28,22 +40,13 @@ export const requireModule = (modulePath: string): void => {
28
40
/**
29
41
* Uses the internal bootstrap-fork.js to load a module
30
42
* @example
31
- * const cp = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain", true );
43
+ * const cp = forkModule("vs/code/electron-browser/sharedProcess/sharedProcessMain");
32
44
* cp.stdout.on("data", (data) => console.log(data.toString("utf8")));
33
45
* cp.stderr.on("data", (data) => console.log(data.toString("utf8")));
34
46
* @param modulePath Path of the VS Code module to load.
35
- * @param stdio Whether to use stdio (spawn) or send/onMessage (fork).
36
47
*/
37
- export const forkModule = ( modulePath : string , stdio ?: boolean ) : cp . ChildProcess => {
38
- const basename = modulePath . split ( "/" ) . pop ( ) ! ;
39
- let i = 0 ;
40
- for ( ; i < basename . length ; i ++ ) {
41
- const character = basename . charAt ( i ) ;
42
- if ( character === character . toUpperCase ( ) ) {
43
- break ;
44
- }
45
- }
46
- const childLogger = logger . named ( basename . substring ( 0 , i ) ) ;
48
+ export const forkModule = ( modulePath : string ) : cp . ChildProcess => {
49
+ const childLogger = getChildLogger ( modulePath ) ;
47
50
childLogger . debug ( "Forking..." , field ( "module" , modulePath ) ) ;
48
51
49
52
let proc : cp . ChildProcess | undefined ;
@@ -53,27 +56,11 @@ export const forkModule = (modulePath: string, stdio?: boolean): cp.ChildProcess
53
56
stdio : [ null , null , null , "pipe" ] ,
54
57
} ;
55
58
if ( process . env . CLI === "true" ) {
56
- proc = stdio ? cp . spawn ( process . execPath , args , options ) : cp . fork ( process . execPath , args , options ) ;
59
+ proc = cp . spawn ( process . execPath , args , options ) ;
57
60
} else {
58
61
proc = cp . spawn ( process . execArgv [ 0 ] , [ "-r" , "tsconfig-paths/register" , process . argv [ 1 ] , ...args ] , options ) ;
59
62
}
60
63
61
- proc . stdout . on ( "data" , ( message ) => {
62
- childLogger . debug ( "stdout" , field ( "message" , message . toString ( ) . trim ( ) ) ) ;
63
- } ) ;
64
-
65
- proc . stderr . on ( "data" , ( message ) => {
66
- childLogger . debug ( "stderr" , field ( "message" , message . toString ( ) . trim ( ) ) ) ;
67
- } ) ;
68
-
69
- proc . stdin . on ( "data" , ( message ) => {
70
- childLogger . debug ( "stdin" , field ( "message" , message . toString ( ) . trim ( ) ) ) ;
71
- } ) ;
72
-
73
- proc . on ( "message" , ( message ) => {
74
- childLogger . debug ( "message" , field ( "message" , message . toString ( ) . trim ( ) ) ) ;
75
- } ) ;
76
-
77
64
proc . on ( "exit" , ( exitCode ) => {
78
65
childLogger . debug ( `Exited with ${ exitCode } ` ) ;
79
66
} ) ;
0 commit comments