diff --git a/lib/util/versioning.js b/lib/util/versioning.js index 92c13347..cae0c694 100644 --- a/lib/util/versioning.js +++ b/lib/util/versioning.js @@ -70,7 +70,13 @@ function get_runtime_abi(runtime, target_version) { if (runtime === 'node-webkit') { return get_node_webkit_abi(runtime, target_version || process.versions['node-webkit']); } else if (runtime === 'electron') { - return get_electron_abi(runtime, target_version || process.versions.electron); + var electron_version = target_version || process.versions.electron + if (!electron_version) { + // TODO PR something to electron to pass in the version number for forks + try { electron_version = require('electron/package.json').version } + catch (_) {} + } + return get_electron_abi(runtime, electron_version); } else { if (runtime != 'node') { throw new Error("Unknown Runtime: '" + runtime + "'"); @@ -245,12 +251,9 @@ function get_process_runtime(versions) { var runtime = 'node'; if (versions['node-webkit']) { runtime = 'node-webkit'; - } else if (versions.electron) { - runtime = 'electron'; - } else if (process.env.ELECTRON_RUN_AS_NODE) { - // Running in a childProcess.fork of electron + } else if (versions.electron || process.env.ELECTRON_RUN_AS_NODE) { + // Running in electron or a childProcess.fork of electron runtime = 'electron'; - process.versions.electron = require('electron/package.json').version; } return runtime; } diff --git a/test/versioning.test.js b/test/versioning.test.js index 69b66c05..1057911d 100644 --- a/test/versioning.test.js +++ b/test/versioning.test.js @@ -73,6 +73,12 @@ describe('versioning', function() { "node-webkit": '0.37.3', }; assert.equal(versioning.get_process_runtime(mock_process_versions3),'node-webkit'); + var mock_process_versions4 = { + "node": '0.8.0' + } + process.env.ELECTRON_RUN_AS_NODE = 1 + assert.equal(versioning.get_process_runtime(mock_process_versions4),'electron'); + delete process.env.ELECTRON_RUN_AS_NODE }); it('should detect abi for electron runtime', function() {