Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #2976 from atom/node_modules_paths
Prevent Node from adding paths outside the app to search paths
- Loading branch information
Showing
5 changed files
with
43 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| path = require 'path' | ||
| Module = require 'module' | ||
|
|
||
| # Clear Node's global search paths. | ||
| Module.globalPaths.length = 0 | ||
|
|
||
| # Clear current and parent(init.coffee)'s search paths. | ||
| module.paths = [] | ||
| module.parent.paths = [] | ||
|
|
||
| # Prevent Node from adding paths outside this app to search paths. | ||
| Module._nodeModulePaths = (from) -> | ||
| from = path.resolve from | ||
|
|
||
| # If "from" is outside the app then we do nothing. | ||
| skipOutsidePaths = from.startsWith process.resourcesPath | ||
|
|
||
| # Following logoic is copied from module.js. | ||
| splitRe = if process.platform is 'win32' then /[\/\\]/ else /\// | ||
| paths = [] | ||
|
|
||
| parts = from.split splitRe | ||
| for part, tip in parts by -1 | ||
| continue if part is 'node_modules' | ||
| dir = parts.slice(0, tip + 1).join path.sep | ||
| break if skipOutsidePaths and not dir.startsWith process.resourcesPath | ||
| paths.push path.join(dir, 'node_modules') | ||
|
|
||
| paths |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters