Skip to content
Prev Previous commit
Next Next commit
Remove fork override
  • Loading branch information
code-asher committed Apr 9, 2019
commit 9de64009e891460666fd11b4f34c8d06a7261a90
21 changes: 3 additions & 18 deletions packages/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from "path";
import * as WebSocket from "ws";
import { buildDir, cacheHome, dataHome, isCli, serveStatic } from "./constants";
import { createApp } from "./server";
import { forkModule, requireFork, requireModule } from "./vscode/bootstrapFork";
import { forkModule, requireModule } from "./vscode/bootstrapFork";
import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess";
import opn = require("opn");

Expand All @@ -30,7 +30,6 @@ commander.version(process.env.VERSION || "development")
.option("-H, --allow-http", "Allow http connections.", false)
.option("-P, --password <value>", "Specify a password for authentication.")
.option("--bootstrap-fork <name>", "Used for development. Never set.")
.option("--fork <name>", "Used for development. Never set.")
.option("--extra-args <args>", "Used for development. Never set.")
.arguments("Specify working directory.")
.parse(process.argv);
Expand Down Expand Up @@ -62,7 +61,6 @@ const bold = (text: string | number): string | number => {
readonly certKey?: string;

readonly bootstrapFork?: string;
readonly fork?: string;
readonly extraArgs?: string;
};

Expand Down Expand Up @@ -119,13 +117,7 @@ const bold = (text: string | number): string | number => {
process.argv[i + 2] = arg;
});

return requireModule(modulePath, dataDir, builtInExtensionsDir);
}

if (options.fork) {
const modulePath = options.fork;

return requireFork(modulePath, JSON.parse(options.extraArgs!), builtInExtensionsDir);
return requireModule(modulePath, builtInExtensionsDir);
}

const logDir = path.join(cacheHome, "code-server/logs", new Date().toISOString().replace(/[-:.TZ]/g, ""));
Expand Down Expand Up @@ -231,14 +223,7 @@ const bold = (text: string | number): string | number => {
return forkModule(options.env.AMD_ENTRYPOINT, args, options, dataDir);
}

if (isCli) {
return spawn(process.execPath, [path.join(buildDir, "out", "cli.js"), "--fork", modulePath, "--extra-args", JSON.stringify(args), "--data-dir", dataDir], {
Comment thread
code-asher marked this conversation as resolved.
...options,
stdio: [null, null, null, "ipc"],
});
} else {
return fork(modulePath, args, options);
}
return fork(modulePath, args, options);
},
},
password,
Expand Down
54 changes: 2 additions & 52 deletions packages/server/src/vscode/bootstrapFork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,13 @@ const requireFilesystemModule = (id: string, builtInExtensionsDir: string): any
return customMod.require(id);
};

/**
* Called from forking a module
*/
export const requireFork = (modulePath: string, args: string[], builtInExtensionsDir: string): void => {
const Module = require("module") as typeof import("module");
const oldRequire = Module.prototype.require;
// tslint:disable-next-line:no-any
const oldLoad = (Module as any)._findPath;
// @ts-ignore
(Module as any)._findPath = function (request, parent, isMain): any {
const lookupPaths = oldLoad.call(this, request, parent, isMain);

return lookupPaths;
};
// tslint:disable-next-line:no-any
Module.prototype.require = function (id: string): any {
if (id === "typescript") {
return require("typescript");
}

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

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

process.argv = ["", "", ...args];
requireFilesystemModule(modulePath, builtInExtensionsDir);

if (ipcMsgBuffer && ipcMsgListener) {
process.removeListener("message", ipcMsgListener);
// tslint:disable-next-line:no-any
ipcMsgBuffer.forEach((i) => process.emit("message" as any, i as any));
ipcMsgBuffer = undefined;
ipcMsgListener = undefined;
}
};

export const requireModule = (modulePath: string, dataDir: string, builtInExtensionsDir: string): void => {
export const requireModule = (modulePath: string, builtInExtensionsDir: string): void => {
process.env.AMD_ENTRYPOINT = modulePath;
const xml = require("xhr2");
xml.XMLHttpRequest.prototype._restrictedHeaders["user-agent"] = false;
// tslint:disable-next-line no-any this makes installing extensions work.
(global as any).XMLHttpRequest = xml.XMLHttpRequest;

const mod = require("module") as typeof import("module");
const promiseFinally = require("promise.prototype.finally") as { shim: () => void };
promiseFinally.shim();
/**
Expand All @@ -102,16 +61,7 @@ export const requireModule = (modulePath: string, dataDir: string, builtInExtens
};

if (isCli) {
/**
* Needed for properly forking external modules within the CLI
*/
// tslint:disable-next-line:no-any
(<any>cp).fork = (modulePath: string, args: ReadonlyArray<string> = [], options?: cp.ForkOptions): cp.ChildProcess => {
return cp.spawn(process.execPath, [path.join(buildDir, "out", "cli.js"), "--fork", modulePath, "--extra-args", JSON.stringify(args), "--data-dir", dataDir], {
...options,
stdio: [null, null, null, "ipc"],
});
};
process.env.NBIN_BYPASS = "true";
}

const baseDir = path.join(buildDir, "build");
Expand Down