Merge pull request #420 from atom/process-main-module
remote.require should search module from user's app
This commit is contained in:
commit
17842e06aa
5 changed files with 13 additions and 8 deletions
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue