36c05ed335
* Update VS Code to 1.32.0 * Update patch Most changes are moved files, most notably shell.contribution.ts which is now main.contribution.ts. Also: - repl.ts no longer uses isMacintosh - shell.ts doesn't exist - added back the commented-out CSP headers * Use es6 target for bootstrap-fork * Directly reference cross-env binary yarn and npm find the binary just fine when running the tasks from the root but it doesn't work if you run one of those tasks directly from within those directories. * Update import paths and bootstrap-fork ignores * Increase memory limit for building default extensions * Fix invalid regex in Firefox * Update startup function * Fix global.require error * Update zip extract arguments * Update travis to minimum required Node version * Always chmod executable dependencies Fixes EACCESS errors for users that had the files unpacked before we added the chmod call. * Remove unused var declaration
54 lines
2.4 KiB
TypeScript
54 lines
2.4 KiB
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
import * as os from "os";
|
|
import { isCli, buildDir } from "./constants";
|
|
|
|
/**
|
|
* Handling of native modules within the CLI
|
|
*/
|
|
export const setup = (dataDirectory: string): void => {
|
|
path.resolve(dataDirectory, "dependencies").split(path.sep).reduce((parentDir, childDir) => {
|
|
const currentDir = path.join(parentDir, childDir);
|
|
try {
|
|
fs.mkdirSync(currentDir);
|
|
} catch (ex) {
|
|
if (ex.code !== "EEXIST" && ex.code !== "EISDIR" && ex.code !== "ENOENT") {
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
return currentDir;
|
|
}, os.platform() === "win32" ? undefined! : path.sep); // Might need path.sep here for linux. Having it for windows causes an error because \C:\Users ...
|
|
|
|
const unpackModule = (moduleName: string, markExecutable: boolean = false): void => {
|
|
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/dependencies", moduleName);
|
|
const diskFile = path.join(dataDirectory, "dependencies", moduleName);
|
|
if (!fs.existsSync(diskFile)) {
|
|
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
|
|
}
|
|
if (markExecutable) {
|
|
fs.chmodSync(diskFile, "755");
|
|
}
|
|
};
|
|
|
|
/**
|
|
* We need to unpack node-pty and patch its `loadNative` function to require our unpacked pty.node
|
|
* If pty.node isn't unpacked a SIGSEGV is thrown and the application exits. The exact reasoning
|
|
* for this is unknown ATM, but this patch works around it.
|
|
*/
|
|
unpackModule("pty.node");
|
|
unpackModule("spdlog.node");
|
|
unpackModule("rg", true);
|
|
// const nodePtyUtils = require("../../protocol/node_modules/node-pty-prebuilt/lib/utils") as typeof import("../../protocol/node_modules/node-pty-prebuilt/src/utils");
|
|
// tslint:disable-next-line:no-any
|
|
// nodePtyUtils.loadNative = (modName: string): any => {
|
|
// return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "dependencies", modName + ".node"));
|
|
// };
|
|
(<any>global).RIPGREP_LOCATION = path.join(dataDirectory, "dependencies", "rg");
|
|
(<any>global).NODEPTY_LOCATION = path.join(dataDirectory, "dependencies", "pty.node");
|
|
// tslint:disable-next-line:no-any
|
|
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "dependencies", "spdlog.node");
|
|
// tslint:disable-next-line:no-unused-expression
|
|
require("../../protocol/node_modules/node-pty-prebuilt/lib/index") as typeof import("../../protocol/node_modules/node-pty-prebuilt/src/index");
|
|
};
|