1
1
/// <reference path="../../../../lib/vscode/src/typings/spdlog.d.ts" />
2
+ /// <reference path="../../node_modules/node-pty-prebuilt/typings/node-pty.d.ts" />
2
3
import { ChildProcess , SpawnOptions , ForkOptions } from "child_process" ;
3
4
import { EventEmitter } from "events" ;
4
5
import { Socket } from "net" ;
@@ -20,22 +21,25 @@ interface ActiveEvalEmitter {
20
21
on ( event : string , cb : ( ...args : any [ ] ) => void ) : void ;
21
22
}
22
23
24
+ /**
25
+ * For any non-external modules that are not built in, we need to require and
26
+ * access them server-side. A require on the client-side won't work since that
27
+ * code won't exist on the server (and bloat the client with an unused import),
28
+ * and we can't manually import on the server-side and then call
29
+ * `__webpack_require__` on the client-side because Webpack stores modules by
30
+ * their paths which would require us to hard-code the path.
31
+ */
32
+ export interface Modules {
33
+ pty : typeof import ( "node-pty" ) ;
34
+ spdlog : typeof import ( "spdlog" ) ;
35
+ trash : typeof import ( "trash" ) ;
36
+ }
37
+
23
38
/**
24
39
* Helper class for server-side evaluations.
25
40
*/
26
41
export class EvalHelper {
27
- // For any non-external modules that are not built in, we need to require and
28
- // access them here. A require on the client-side won't work since that code
29
- // won't exist on the server (and bloat the client with an unused import), and
30
- // we can't manually import on the server-side and then call
31
- // `__webpack_require__` on the client-side because Webpack stores modules by
32
- // their paths which would require us to hard-code the path. These aren't
33
- // required immediately so we have a chance to unpack the .node files and set
34
- // their locations.
35
- public modules = {
36
- spdlog : require ( "spdlog" ) as typeof import ( "spdlog" ) ,
37
- pty : require ( "node-pty-prebuilt" ) as typeof import ( "node-pty" ) ,
38
- } ;
42
+ public constructor ( public modules : Modules ) { }
39
43
40
44
/**
41
45
* Some spawn code tries to preserve the env (the debug adapter for instance)
@@ -113,11 +117,11 @@ export class ActiveEvalHelper implements ActiveEvalEmitter {
113
117
* Helper class for server-side active evaluations.
114
118
*/
115
119
export class ServerActiveEvalHelper extends ActiveEvalHelper implements EvalHelper {
116
- private readonly evalHelper = new EvalHelper ( ) ;
117
- public modules = this . evalHelper . modules ;
120
+ private readonly evalHelper : EvalHelper ;
118
121
119
- public constructor ( emitter : ActiveEvalEmitter , public readonly fork : ForkProvider ) {
122
+ public constructor ( public modules : Modules , emitter : ActiveEvalEmitter , public readonly fork : ForkProvider ) {
120
123
super ( emitter ) ;
124
+ this . evalHelper = new EvalHelper ( modules ) ;
121
125
}
122
126
123
127
public preserveEnv ( options : SpawnOptions | ForkOptions ) : void {
@@ -208,7 +212,7 @@ export class ServerActiveEvalHelper extends ActiveEvalHelper implements EvalHelp
208
212
}
209
213
210
214
public createUnique ( id : number | "stdout" | "stderr" | "stdin" ) : ServerActiveEvalHelper {
211
- return new ServerActiveEvalHelper ( this . createUniqueEmitter ( id ) , this . fork ) ;
215
+ return new ServerActiveEvalHelper ( this . modules , this . createUniqueEmitter ( id ) , this . fork ) ;
212
216
}
213
217
}
214
218
0 commit comments