]> khamidou — GitHub mirrors - electron.git/commitdiff
Simplify how we remove user-defined search paths
authorCheng Zhao <zcbenz@gmail.com>
Thu, 23 Apr 2015 05:13:58 +0000 (13:13 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 23 Apr 2015 05:13:58 +0000 (13:13 +0800)
atom/browser/lib/init.coffee

index 8bd264cf5f837fec37d96877ff8fb704a4ba2913..fec5a64ac07ef39c21b53cef05aa37ee9226964c 100644 (file)
@@ -7,28 +7,21 @@ util   = require 'util'
 # we need to restore it here.
 process.argv.splice 1, 1
 
-# Add browser/api/lib to require's search paths,
-# which contains javascript part of Atom's built-in libraries.
+# Global module search paths.
+globalPaths = module.globalPaths
+
+# Don't lookup modules in user-defined search paths, see http://git.io/vf8sF.
 homeDir =
   if process.platform is 'win32'
     process.env.USERPROFILE
   else
     process.env.HOME
+if homeDir  # Node only add user-defined search paths when $HOME is defined.
+  userModulePath = path.resolve homeDir, '.node_modules'
+  globalPaths.splice globalPaths.indexOf(userModulePath), 2
 
-syspath = []
-
-if homeDir
-  syspath.push(path.resolve(homeDir, '.node_modules'))
-  syspath.push(path.resolve(homeDir, '.node_libraries'))
-
-# Remove system paths from module lookups as it may contain modules not
-# shipped with the app or compiled with wrong v8 headers.
-syspath.map (path) ->
-  index = module.globalPaths.indexOf path
-  if index > -1
-    module.globalPaths.splice(index,1)
-
-globalPaths = module.globalPaths
+# Add browser/api/lib to module search paths, which contains javascript part of
+# Electron's built-in libraries.
 globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
 
 # Import common settings.