Reuse root path variable
This commit is contained in:
parent
905e9e9645
commit
bac4d51169
1 changed files with 6 additions and 8 deletions
|
@ -9,21 +9,19 @@ module.paths = []
|
||||||
module.parent.paths = []
|
module.parent.paths = []
|
||||||
|
|
||||||
// Prevent Node from adding paths outside this app to search paths.
|
// Prevent Node from adding paths outside this app to search paths.
|
||||||
|
const resourcesPathWithTrailingSlash = process.resourcesPath + path.sep
|
||||||
const originalNodeModulePaths = Module._nodeModulePaths
|
const originalNodeModulePaths = Module._nodeModulePaths
|
||||||
Module._nodeModulePaths = function (from) {
|
Module._nodeModulePaths = function (from) {
|
||||||
const paths = originalNodeModulePaths(from)
|
const paths = originalNodeModulePaths(from)
|
||||||
|
|
||||||
// If "from" is outside the app then we do nothing.
|
|
||||||
const rootPath = process.resourcesPath + path.sep
|
|
||||||
const fromPath = path.resolve(from) + path.sep
|
const fromPath = path.resolve(from) + path.sep
|
||||||
const skipOutsidePaths = fromPath.startsWith(rootPath)
|
// If "from" is outside the app then we do nothing.
|
||||||
if (skipOutsidePaths) {
|
if (fromPath.startsWith(resourcesPathWithTrailingSlash)) {
|
||||||
return paths.filter(function (candidate) {
|
return paths.filter(function (candidate) {
|
||||||
return candidate.startsWith(rootPath)
|
return candidate.startsWith(resourcesPathWithTrailingSlash)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch Module._resolveFilename to always require the Electron API when
|
// Patch Module._resolveFilename to always require the Electron API when
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue