Skip to content

Commit

Permalink
Fixes #68024
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Mar 9, 2020
1 parent 39cddc9 commit ffbb280
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/bootstrap-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
23 changes: 23 additions & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffbb280

Please sign in to comment.