diff --git a/atom/common/api/lib/exports/electron.js b/atom/common/api/lib/exports/electron.js index 5b93d286da61..6811e73a10b6 100644 --- a/atom/common/api/lib/exports/electron.js +++ b/atom/common/api/lib/exports/electron.js @@ -1,5 +1,5 @@ // Do not expose the internal modules to `require`. -exports.hideInternalModules = function() { +const hideInternalModules = function() { var globalPaths = require('module').globalPaths; if (globalPaths.length === 3) { @@ -11,6 +11,10 @@ exports.hideInternalModules = function() { // Attaches properties to |exports|. exports.defineProperties = function(exports) { return Object.defineProperties(exports, { + hideInternalModules: { + enumerable: true, + value: hideInternalModules + }, // Common modules, please sort with alphabet order. clipboard: { diff --git a/script/test.py b/script/test.py index 7f75d3113d69..28aeac9dc1ff 100755 --- a/script/test.py +++ b/script/test.py @@ -16,9 +16,6 @@ PRODUCT_NAME = atom_gyp()['product_name%'] def main(): os.chdir(SOURCE_ROOT) - # Disable old APIs - os.environ['ELECTRON_HIDE_INTERNAL_MODULES'] = 'true' - config = 'D' if len(sys.argv) == 2 and sys.argv[1] == '-R': config = 'R' diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index dafaf44a2d15..0019ec59d5f0 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -10,6 +10,21 @@ remote = require('electron').remote; ref = remote.require('electron'), app = ref.app, BrowserWindow = ref.BrowserWindow; +describe('electron module', function() { + it ('can prevent exposing internal modules to require', function(done) { + const electron = require('electron'); + const clipboard = require('clipboard'); + assert.equal(typeof clipboard, 'object'); + electron.hideInternalModules(); + try { + require('clipboard'); + } catch(err) { + assert.equal(err.message, 'Cannot find module \'clipboard\''); + done(); + } + }); +}); + describe('app module', function() { describe('app.getVersion()', function() { return it('returns the version field of package.json', function() {