Fix debugging

This commit is contained in:
Kyle Carberry 2019-03-19 12:53:05 -04:00
parent 277c6cb690
commit 2169045377
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
2 changed files with 18 additions and 11 deletions

View File

@ -1,19 +1,19 @@
import * as fse from "fs-extra";
import { field, logger } from "@coder/logger"; import { field, logger } from "@coder/logger";
import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto"; import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto";
import { Command, flags } from "@oclif/command"; import { Command, flags } from "@oclif/command";
import { fork, ForkOptions, ChildProcess } from "child_process"; import { ChildProcess, fork, ForkOptions, spawn } from "child_process";
import { randomFillSync } from "crypto"; import { randomFillSync } from "crypto";
import * as fs from "fs"; import * as fs from "fs";
import * as fse from "fs-extra";
import * as os from "os"; import * as os from "os";
import * as path from "path"; import * as path from "path";
import * as WebSocket from "ws"; import * as WebSocket from "ws";
import { createApp } from "./server"; import { buildDir, cacheHome, dataHome, isCli, serveStatic } from "./constants";
import { requireModule, requireFork, forkModule } from "./vscode/bootstrapFork";
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import { setup as setupNativeModules } from "./modules";
import { fillFs } from "./fill"; import { fillFs } from "./fill";
import { isCli, serveStatic, buildDir, dataHome, cacheHome } from "./constants"; import { setup as setupNativeModules } from "./modules";
import { createApp } from "./server";
import { forkModule, requireFork, requireModule } from "./vscode/bootstrapFork";
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import opn = require("opn"); import opn = require("opn");
export class Entry extends Command { export class Entry extends Command {
@ -187,7 +187,14 @@ export class Entry extends Command {
return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir); return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir);
} }
if (isCli) {
return spawn(process.execPath, ["--fork", modulePath, "--args", JSON.stringify(args), "--data-dir", dataDir], {
...options,
stdio: [null, null, null, "ipc"],
});
} else {
return fork(modulePath, args, options); return fork(modulePath, args, options);
}
}, },
}, },
password, password,

View File

@ -46,12 +46,13 @@ export const requireFork = (modulePath: string, args: string[], builtInExtension
const Module = require("module") as typeof import("module"); const Module = require("module") as typeof import("module");
const oldRequire = Module.prototype.require; const oldRequire = Module.prototype.require;
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
Module.prototype.require = (id: string): any => { Module.prototype.require = function (id: string): any {
if (id === "typescript") { if (id === "typescript") {
return require("typescript"); return require("typescript");
} }
return oldRequire(id); // tslint:disable-next-line:no-any
return oldRequire.call(this, id as any);
}; };
if (!process.send) { if (!process.send) {
@ -59,7 +60,6 @@ export const requireFork = (modulePath: string, args: string[], builtInExtension
} }
process.argv = ["", "", ...args]; process.argv = ["", "", ...args];
requireFilesystemModule(modulePath, builtInExtensionsDir); requireFilesystemModule(modulePath, builtInExtensionsDir);
if (ipcMsgBuffer && ipcMsgListener) { if (ipcMsgBuffer && ipcMsgListener) {