Fix local building for module extraction

This commit is contained in:
Kyle Carberry 2019-02-22 15:06:34 -06:00
parent 73d6b77614
commit de3fbd689f
No known key found for this signature in database
GPG Key ID: A0409BDB6B0B3EDB
1 changed files with 2 additions and 6 deletions

View File

@ -8,10 +8,6 @@ declare var __non_webpack_require__: typeof require;
* Handling of native modules within the CLI
*/
export const setup = (dataDirectory: string): void => {
if (!isCli) {
return;
}
try {
fs.mkdirSync(path.join(dataDirectory, "modules"));
} catch (ex) {
@ -21,7 +17,7 @@ export const setup = (dataDirectory: string): void => {
}
const unpackModule = (moduleName: string): void => {
const memFile = path.join(buildDir!, "build/modules", moduleName + ".node");
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/modules", moduleName + ".node");
const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
if (!fs.existsSync(diskFile)) {
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
@ -38,7 +34,7 @@ export const setup = (dataDirectory: string): void => {
const nodePtyUtils = require("../../protocol/node_modules/node-pty/lib/utils") as typeof import("../../protocol/node_modules/node-pty/src/utils");
// tslint:disable-next-line:no-any
nodePtyUtils.loadNative = (modName: string): any => {
return __non_webpack_require__(path.join(dataDirectory, "modules", modName + ".node"));
return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "modules", modName + ".node"));
};
// tslint:disable-next-line:no-any
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "modules", "spdlog.node");