From 2ca5a33d287e2c601bf08b87226d4057571868d1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Nov 2015 21:46:03 +0800 Subject: [PATCH] Add electron.hideInternalModules --- atom/browser/lib/init.coffee | 6 +++--- atom/common/api/lib/exports/electron.coffee | 7 +++++++ atom/renderer/lib/init.coffee | 6 +++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/atom/browser/lib/init.coffee b/atom/browser/lib/init.coffee index e3b15dee21a4..ec0fd16c89ff 100644 --- a/atom/browser/lib/init.coffee +++ b/atom/browser/lib/init.coffee @@ -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. diff --git a/atom/common/api/lib/exports/electron.coffee b/atom/common/api/lib/exports/electron.coffee index 7bcb23a2ca4d..e98144306561 100644 --- a/atom/common/api/lib/exports/electron.coffee +++ b/atom/common/api/lib/exports/electron.coffee @@ -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: diff --git a/atom/renderer/lib/init.coffee b/atom/renderer/lib/init.coffee index 596c2f786df5..b7155c1cc55a 100644 --- a/atom/renderer/lib/init.coffee +++ b/atom/renderer/lib/init.coffee @@ -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