From 41b9add5d6f4e29de7a240478f46a307cdf4b2bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 Jun 2014 14:55:41 +0800 Subject: [PATCH 1/5] Add spec for checking process.mainModule. --- spec/api-ipc-spec.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/api-ipc-spec.coffee b/spec/api-ipc-spec.coffee index 141818320551..86dbe810cff6 100644 --- a/spec/api-ipc-spec.coffee +++ b/spec/api-ipc-spec.coffee @@ -18,6 +18,10 @@ describe 'ipc module', -> a = remote.require path.join(fixtures, 'module', 'id.js') assert.equal a.id, 1127 + it 'should search module from the user app', -> + assert.equal remote.process.mainModule.filename, path.resolve(__dirname, 'static', 'main.js') + assert.equal remote.process.mainModule.paths[0], path.resolve(__dirname, 'static', 'node_modules') + describe 'remote.createFunctionWithReturnValue', -> it 'should be called in browser synchronously', -> buf = new Buffer('test') From 48224a6455c35f8f7cd2264abe4de510b29d5a1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 Jun 2014 14:56:00 +0800 Subject: [PATCH 2/5] Set process.mainModule to user's app. --- atom/browser/lib/init.coffee | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/atom/browser/lib/init.coffee b/atom/browser/lib/init.coffee index 67ac258097ce..f5445a0cc20b 100644 --- a/atom/browser/lib/init.coffee +++ b/atom/browser/lib/init.coffee @@ -1,6 +1,7 @@ -fs = require 'fs' -path = require 'path' -util = require 'util' +fs = require 'fs' +path = require 'path' +module = require 'module' +util = require 'util' # Expose information of current process. process.type = 'browser' @@ -17,7 +18,7 @@ process.execArgv = process.argv.splice startMark, endMark - startMark + 1 # Add browser/api/lib to require's search paths, # which contains javascript part of Atom's built-in libraries. -globalPaths = require('module').globalPaths +globalPaths = module.globalPaths globalPaths.push path.join process.resourcesPath, 'atom', 'browser', 'api', 'lib' # Do loading in next tick since we still need some initialize work before @@ -77,4 +78,4 @@ setImmediate -> app.setName packageJson.name # Finally load app's main.js and transfer control to C++. - require path.join(packagePath, packageJson.main) + module._load path.join(packagePath, packageJson.main), module, true From 9c84f92f3e31e30d8808c0fbe463003f2ecca8d2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 Jun 2014 14:56:30 +0800 Subject: [PATCH 3/5] remote.require should use process.mainModule.require. --- atom/browser/lib/rpc-server.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/lib/rpc-server.coffee b/atom/browser/lib/rpc-server.coffee index a28c4b25af3f..95d30f366a01 100644 --- a/atom/browser/lib/rpc-server.coffee +++ b/atom/browser/lib/rpc-server.coffee @@ -84,7 +84,7 @@ process.on 'ATOM_BROWSER_RELEASE_RENDER_VIEW', (id) -> ipc.on 'ATOM_BROWSER_REQUIRE', (event, module) -> try - event.returnValue = valueToMeta event.sender, require(module) + event.returnValue = valueToMeta event.sender, process.mainModule.require(module) catch e event.returnValue = errorToMeta e From ae3958c9977b2bcaa66f0e37ee477bcc19a03aaf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 Jun 2014 14:57:11 +0800 Subject: [PATCH 4/5] The default_app should also set process.mainModule. --- atom/browser/default_app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/default_app/main.js b/atom/browser/default_app/main.js index b0b5d9efa4c3..4afe4823ba47 100644 --- a/atom/browser/default_app/main.js +++ b/atom/browser/default_app/main.js @@ -30,7 +30,7 @@ if (argv._.length > 0) { } // Run the app. - require(packagePath); + require('module')._load(packagePath, module, true); } catch(e) { if (e.code == 'MODULE_NOT_FOUND') { app.focus(); From fe6eac6c7ddf24f0c0575000e621c8057955ee2f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 Jun 2014 14:59:14 +0800 Subject: [PATCH 5/5] Fix refreshing the spec window. --- spec/api-app-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-app-spec.coffee b/spec/api-app-spec.coffee index 7449c48a0454..b8b6ecf694c6 100644 --- a/spec/api-app-spec.coffee +++ b/spec/api-app-spec.coffee @@ -22,4 +22,4 @@ describe 'app module', -> assert.equal app.getName(), 'Atom Shell Test App' app.setName 'test-name' assert.equal app.getName(), 'test-name' - app.setName 'Atom Shell Default App' + app.setName 'Atom Shell Test App'