11/// <reference path="../../../../lib/vscode/src/typings/spdlog.d.ts" />
2+ /// <reference path="../../node_modules/node-pty-prebuilt/typings/node-pty.d.ts" />
23import { ChildProcess , SpawnOptions , ForkOptions } from "child_process" ;
34import { EventEmitter } from "events" ;
45import { Socket } from "net" ;
@@ -20,22 +21,25 @@ interface ActiveEvalEmitter {
2021 on ( event : string , cb : ( ...args : any [ ] ) => void ) : void ;
2122}
2223
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+
2338/**
2439 * Helper class for server-side evaluations.
2540 */
2641export 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 ) { }
3943
4044 /**
4145 * Some spawn code tries to preserve the env (the debug adapter for instance)
@@ -113,11 +117,11 @@ export class ActiveEvalHelper implements ActiveEvalEmitter {
113117 * Helper class for server-side active evaluations.
114118 */
115119export class ServerActiveEvalHelper extends ActiveEvalHelper implements EvalHelper {
116- private readonly evalHelper = new EvalHelper ( ) ;
117- public modules = this . evalHelper . modules ;
120+ private readonly evalHelper : EvalHelper ;
118121
119- public constructor ( emitter : ActiveEvalEmitter , public readonly fork : ForkProvider ) {
122+ public constructor ( public modules : Modules , emitter : ActiveEvalEmitter , public readonly fork : ForkProvider ) {
120123 super ( emitter ) ;
124+ this . evalHelper = new EvalHelper ( modules ) ;
121125 }
122126
123127 public preserveEnv ( options : SpawnOptions | ForkOptions ) : void {
@@ -208,7 +212,7 @@ export class ServerActiveEvalHelper extends ActiveEvalHelper implements EvalHelp
208212 }
209213
210214 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 ) ;
212216 }
213217}
214218
0 commit comments