This commit is contained in:
Alex Dima 2020-03-09 14:51:44 +01:00
parent 39cddc9315
commit ffbb280a36
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
2 changed files with 26 additions and 0 deletions

View file

@ -8,6 +8,9 @@
const bootstrap = require('./bootstrap');
// Remove global paths from the node module lookup
bootstrap.removeGlobalNodeModuleLookupPaths();
// Enable ASAR in our forked processes
bootstrap.enableASARSupport();

23
src/bootstrap.js vendored
View file

@ -53,6 +53,29 @@ exports.injectNodeModuleLookupPath = function (injectPath) {
};
//#endregion
//#region Remove global paths from the node lookup paths
exports.removeGlobalNodeModuleLookupPaths = function() {
// @ts-ignore
const Module = require('module');
// @ts-ignore
const globalPaths = Module.globalPaths;
// @ts-ignore
const originalResolveLookupPaths = Module._resolveLookupPaths;
// @ts-ignore
Module._resolveLookupPaths = function (moduleName, parent) {
const paths = originalResolveLookupPaths(moduleName, parent);
let commonSuffixLength = 0;
while (commonSuffixLength < paths.length && paths[paths.length - 1 - commonSuffixLength] === globalPaths[globalPaths.length - 1 - commonSuffixLength]) {
commonSuffixLength++;
}
return paths.slice(0, paths.length - commonSuffixLength);
};
};
//#endregion
//#region Add support for using node_modules.asar
/**
* @param {string=} nodeModulesPath