Skip to content

Commit 2169045

Browse files
committed
Fix debugging
1 parent 277c6cb commit 2169045

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

packages/server/src/cli.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import * as fse from "fs-extra";
21
import { field, logger } from "@coder/logger";
32
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
43
import { Command, flags } from "@oclif/command";
5-
import { fork, ForkOptions, ChildProcess } from "child_process";
4+
import { ChildProcess, fork, ForkOptions, spawn } from "child_process";
65
import { randomFillSync } from "crypto";
76
import * as fs from "fs";
7+
import * as fse from "fs-extra";
88
import * as os from "os";
99
import * as path from "path";
1010
import * as WebSocket from "ws";
11+
import { buildDir, cacheHome, dataHome, isCli, serveStatic } from "./constants";
12+
import { fillFs } from "./fill";
13+
import { setup as setupNativeModules } from "./modules";
1114
import { createApp } from "./server";
12-
import { requireModule, requireFork, forkModule } from "./vscode/bootstrapFork";
15+
import { forkModule, requireFork, requireModule } from "./vscode/bootstrapFork";
1316
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
14-
import { setup as setupNativeModules } from "./modules";
15-
import { fillFs } from "./fill";
16-
import { isCli, serveStatic, buildDir, dataHome, cacheHome } from "./constants";
1717
import opn = require("opn");
1818

1919
export class Entry extends Command {
@@ -187,7 +187,14 @@ export class Entry extends Command {
187187
return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir);
188188
}
189189

190-
return fork(modulePath, args, options);
190+
if (isCli) {
191+
return spawn(process.execPath, ["--fork", modulePath, "--args", JSON.stringify(args), "--data-dir", dataDir], {
192+
...options,
193+
stdio: [null, null, null, "ipc"],
194+
});
195+
} else {
196+
return fork(modulePath, args, options);
197+
}
191198
},
192199
},
193200
password,

packages/server/src/vscode/bootstrapFork.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ export const requireFork = (modulePath: string, args: string[], builtInExtension
4646
const Module = require("module") as typeof import("module");
4747
const oldRequire = Module.prototype.require;
4848
// tslint:disable-next-line:no-any
49-
Module.prototype.require = (id: string): any => {
49+
Module.prototype.require = function (id: string): any {
5050
if (id === "typescript") {
5151
return require("typescript");
5252
}
5353

54-
return oldRequire(id);
54+
// tslint:disable-next-line:no-any
55+
return oldRequire.call(this, id as any);
5556
};
5657

5758
if (!process.send) {
5859
throw new Error("No IPC messaging initialized");
5960
}
6061

6162
process.argv = ["", "", ...args];
62-
6363
requireFilesystemModule(modulePath, builtInExtensionsDir);
6464

6565
if (ipcMsgBuffer && ipcMsgListener) {

0 commit comments

Comments
 (0)