Skip to content

Commit ffbb280

Browse files
committed
1 parent 39cddc9 commit ffbb280

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/bootstrap-fork.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
const bootstrap = require('./bootstrap');
1010

11+
// Remove global paths from the node module lookup
12+
bootstrap.removeGlobalNodeModuleLookupPaths();
13+
1114
// Enable ASAR in our forked processes
1215
bootstrap.enableASARSupport();
1316

src/bootstrap.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ exports.injectNodeModuleLookupPath = function (injectPath) {
5353
};
5454
//#endregion
5555

56+
//#region Remove global paths from the node lookup paths
57+
58+
exports.removeGlobalNodeModuleLookupPaths = function() {
59+
// @ts-ignore
60+
const Module = require('module');
61+
// @ts-ignore
62+
const globalPaths = Module.globalPaths;
63+
64+
// @ts-ignore
65+
const originalResolveLookupPaths = Module._resolveLookupPaths;
66+
67+
// @ts-ignore
68+
Module._resolveLookupPaths = function (moduleName, parent) {
69+
const paths = originalResolveLookupPaths(moduleName, parent);
70+
let commonSuffixLength = 0;
71+
while (commonSuffixLength < paths.length && paths[paths.length - 1 - commonSuffixLength] === globalPaths[globalPaths.length - 1 - commonSuffixLength]) {
72+
commonSuffixLength++;
73+
}
74+
return paths.slice(0, paths.length - commonSuffixLength);
75+
};
76+
};
77+
//#endregion
78+
5679
//#region Add support for using node_modules.asar
5780
/**
5881
* @param {string=} nodeModulesPath

0 commit comments

Comments
 (0)