]> khamidou — GitHub mirrors - electron.git/commitdiff
Add electron.hideInternalModules
authorCheng Zhao <zcbenz@gmail.com>
Thu, 12 Nov 2015 13:46:03 +0000 (21:46 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 12 Nov 2015 13:46:03 +0000 (21:46 +0800)
atom/browser/lib/init.coffee
atom/common/api/lib/exports/electron.coffee
atom/renderer/lib/init.coffee

index e3b15dee21a4ecaf6862a0047a831761ff8bcdb8..ec0fd16c89ff6ca3a31be959a254dc684d752114 100644 (file)
@@ -13,13 +13,13 @@ require path.resolve(__dirname, '..', '..', 'common', 'lib', 'reset-search-paths
 # Import common settings.
 require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
 
-# Expose public APIs.
 globalPaths = Module.globalPaths
-globalPaths.push path.resolve(__dirname, '..', 'api', 'lib', 'exports')
-
 unless process.env.ELECTRON_HIDE_INTERNAL_MODULES
   globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
 
+# Expose public APIs.
+globalPaths.push path.resolve(__dirname, '..', 'api', 'lib', 'exports')
+
 if process.platform is 'win32'
   # Redirect node's console to use our own implementations, since node can not
   # handle console output when running as GUI program.
index 7bcb23a2ca4dfb7738149d17753f2bfbe5b9d29b..e98144306561b8512c2c246588012e1b324a5c8f 100644 (file)
@@ -1,3 +1,10 @@
+# Do not expose the internal modules to `require`.
+exports.hideInternalModules = ->
+  {globalPaths} = require 'module'
+  if globalPaths.length is 3
+    # Remove the "common/api/lib" and "browser-or-renderer/api/lib".
+    globalPaths.splice 0, 2
+
 Object.defineProperties exports,
   # Common modules, please sort with alphabet order.
   clipboard:
index 596c2f786df56a900741eb93a890566afa9422ea..b7155c1cc55a0dc2ee8dcde5fc51152407842935 100644 (file)
@@ -13,13 +13,13 @@ require path.resolve(__dirname, '..', '..', 'common', 'lib', 'reset-search-paths
 # Import common settings.
 require path.resolve(__dirname, '..', '..', 'common', 'lib', 'init')
 
-# Expose public APIs.
 globalPaths = Module.globalPaths
-globalPaths.push path.resolve(__dirname, '..', 'api', 'lib', 'exports')
-
 unless process.env.ELECTRON_HIDE_INTERNAL_MODULES
   globalPaths.push path.resolve(__dirname, '..', 'api', 'lib')
 
+# Expose public APIs.
+globalPaths.push path.resolve(__dirname, '..', 'api', 'lib', 'exports')
+
 # The global variable will be used by ipc for event dispatching
 v8Util = process.atomBinding 'v8_util'
 v8Util.setHiddenValue global, 'ipc', new events.EventEmitter