Skip to content

Commit

Permalink
Recognize electron as a valid runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz committed Sep 24, 2015
1 parent 7a6148f commit da292e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Options include:

- `-C/--directory`: run the command in this directory
- `--build-from-source`: build from source instead of using pre-built binary
- `--runtime=node-webkit`: customize the runtime: `node` and `node-webkit` are the valid options
- `--runtime=node-webkit`: customize the runtime: `node`, `electron` and `node-webkit` are the valid options
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
- `--target=0.10.25`: Pass the target node or node-webkit version to compile against
- `--target_arch=ia32`: Pass the target arch and override the host `arch`. Valid values are 'ia32','x64', or `arm`.
Expand Down
16 changes: 16 additions & 0 deletions lib/util/versioning.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ if (process.env.NODE_PRE_GYP_ABI_CROSSWALK) {
abi_crosswalk = require('./abi_crosswalk.json');
}

function get_electron_abi(runtime, target_version) {
if (!runtime) {
throw new Error("get_electron_abi requires valid runtime arg");
}
if (typeof target_version === 'undefined') {
// erroneous CLI call
throw new Error("Empty target version is not supported if electron is the target.");
}
// Electron guarentees that patch version update won't break native modules.
var sem_ver = semver.parse(target_version);
return runtime + '-v' + sem_ver.major + '.' + sem_ver.minor;
}
module.exports.get_electron_abi = get_electron_abi;

function get_node_webkit_abi(runtime, target_version) {
if (!runtime) {
throw new Error("get_node_webkit_abi requires valid runtime arg");
Expand Down Expand Up @@ -55,6 +69,8 @@ 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);
} else {
if (runtime != 'node') {
throw new Error("Unknown Runtime: '" + runtime + "'");
Expand Down

3 comments on commit da292e7

@kenr
Copy link

@kenr kenr commented on da292e7 Oct 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess electron must be covered in

var runtime = options.runtime || (process.versions['node-webkit'] ? 'node-webkit' : 'node');
?

@zcbenz
Copy link
Contributor Author

@zcbenz zcbenz commented on da292e7 Oct 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless node-pre-gyp is executed with Electron instead of Node, detecting Electron there doesn't make much sense, the same goes for node-webkit too.

@enlight
Copy link
Contributor

@enlight enlight commented on da292e7 Nov 5, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get node-inspector to load source files from the app ASAR it needs to be executed from Electron (or at least that's the only workaround I've found), which is where I hit a bit of a snag at the line @kenr mentioned. I rebuilt the native modules of node-inspector for Electron but the runtime defaults to Node at the aforementioned line so path resolution using node-pre-gyp.find() fails for the native modules. I've submitted PR #187 to fix this.

Please sign in to comment.