Pre-resolve electron require path

This commit is contained in:
Kevin Sawicki 2016-05-23 10:56:49 -07:00
parent daea448b61
commit 566b0676bc

View file

@ -17,7 +17,7 @@ Module._nodeModulePaths = function (from) {
// If "from" is outside the app then we do nothing. // If "from" is outside the app then we do nothing.
skipOutsidePaths = from.startsWith(process.resourcesPath) skipOutsidePaths = from.startsWith(process.resourcesPath)
// Following logoic is copied from module.js. // Following logic is copied from module.js.
splitRe = process.platform === 'win32' ? /[\/\\]/ : /\// splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//
paths = [] paths = []
parts = from.split(splitRe) parts = from.split(splitRe)
@ -34,3 +34,13 @@ Module._nodeModulePaths = function (from) {
} }
return paths return paths
} }
const electronPath = path.join(__dirname, '..', process.type, 'api', 'exports', 'electron.js')
const originalResolveFilename = Module._resolveFilename
Module._resolveFilename = function (request, parent, isMain) {
if (request === 'electron') {
return electronPath
} else {
return originalResolveFilename(request, parent, isMain)
}
}