From 21690453775629a97627d37ee8703ab5718ebe35 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 19 Mar 2019 12:53:05 -0400 Subject: [PATCH] Fix debugging --- packages/server/src/cli.ts | 23 ++++++++++++++------- packages/server/src/vscode/bootstrapFork.ts | 6 +++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index f8820628..4e15d8ad 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -1,19 +1,19 @@ -import * as fse from "fs-extra"; import { field, logger } from "@coder/logger"; import { ServerMessage, SharedProcessActiveMessage } from "@coder/protocol/src/proto"; 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 * as fs from "fs"; +import * as fse from "fs-extra"; import * as os from "os"; import * as path from "path"; import * as WebSocket from "ws"; -import { createApp } from "./server"; -import { requireModule, requireFork, forkModule } from "./vscode/bootstrapFork"; -import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess"; -import { setup as setupNativeModules } from "./modules"; +import { buildDir, cacheHome, dataHome, isCli, serveStatic } from "./constants"; 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"); export class Entry extends Command { @@ -187,7 +187,14 @@ export class Entry extends Command { return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir); } - return fork(modulePath, args, options); + 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); + } }, }, password, diff --git a/packages/server/src/vscode/bootstrapFork.ts b/packages/server/src/vscode/bootstrapFork.ts index ac097a72..71ff3815 100644 --- a/packages/server/src/vscode/bootstrapFork.ts +++ b/packages/server/src/vscode/bootstrapFork.ts @@ -46,12 +46,13 @@ export const requireFork = (modulePath: string, args: string[], builtInExtension const Module = require("module") as typeof import("module"); const oldRequire = Module.prototype.require; // tslint:disable-next-line:no-any - Module.prototype.require = (id: string): any => { + Module.prototype.require = function (id: string): any { if (id === "typescript") { return require("typescript"); } - return oldRequire(id); + // tslint:disable-next-line:no-any + return oldRequire.call(this, id as any); }; if (!process.send) { @@ -59,7 +60,6 @@ export const requireFork = (modulePath: string, args: string[], builtInExtension } process.argv = ["", "", ...args]; - requireFilesystemModule(modulePath, builtInExtensionsDir); if (ipcMsgBuffer && ipcMsgListener) {