Uh oh!
There was an error while loading. Please reload this page.
src: add process.versions.iojs - #491
Conversation
This gives user code a forward-compatible means for determining whether it's running in io.js or Node.js. Also, to ensure backwards compatibility, it leaves the existing `process.versions.node` alone.
272ee8b to
39d0732Comparecjihrig
commented
Jan 18, 2015
I'm +1 on this change, and LGTM. It might be worth referencing the previous discussion on #253. |
othiym23
commented
Jan 18, 2015
Thanks, @cjihrig. Left a comment there to try to persuade my boss that this PR is a good idea. |
rvagg
commented
Jan 18, 2015
good luck on that, he's been the most vocal against it |
isaacs
commented
Jan 18, 2015
Yeah, I guess nodejs/node-gyp#564 does present a worthwhile use-case. Mostly, I'm just opposed to people using it, and I've been burned in the past creating API that I don't think people should use. I fear What's wrong with just using If we're going to add a "brand name" to the API, I'd prefer it to be explicitly that, rather than tacking onto |
rvagg
commented
Jan 18, 2015
Existing detection mechanisms that I can think of that should be cross-platform safe: Versionfunctionisiojs(){returnparseInt(process.version.match(/v(\d+)/)[1],0)>=1}This is semi-safe because nobody here believes that "Node.js" will reach 1.0. There is a desire on both sides for reunification and when/if that happens there won't be an overlapping release numbering. If there isn't reunification then what's the realistic path for joyent/node to reach 1.0 when it can't even get to 0.12? NODE_MODULE_VERSIONfunctionisiojs(){returnparseInt(process.versions.modules>=42&&process.versions.modules<100)}This is semi-safe for similar reasons but has some additional possible benefits:
Forkfunctionisiojs(callback){require('child_process').exec(process.execPath+' -h',function(err,stderr,stdout){if(err)returncallback(err)callback(null,/iojs\.org/.test(stderr.toString()))})}This is probably the safest option as it's unlikely Node.js will ever include that in its help output (unless "reunification" results in both projects still existing and we decide to use The main drawback is the poor performance and need for forking. |
rvagg
commented
Jan 18, 2015
If we really must have a User-Agent equivalent then I'd like to propose a |
domenic
commented
Jan 18, 2015
nodejs/node-gyp#564 (comment) seems like the cleanest idea to me, FWIW. I agree that this is going to head toward user-agent hell, i.e. io.js already has |
bnoordhuis
commented
Jan 18, 2015
I like @rvagg's
Because Windows. :-) I'm given to understand by @piscisaureus that the node.exe stub would have a process.execPath that ends in node, not iojs. |
othiym23
commented
Jan 19, 2015
Well, not yet – this patch still isn't merged, and I will cry only a few salty tears of bitterness if it doesn't get merged, because I spent all of 10 minutes putting it together in the first place. I also see no reason why joyent/node would ever add a if(process.versions.iojs){// do iojs-specific stuff}else{// do "regular" Node.js stuff}Really, there's only two questions that need to be answerable, IMO:
#493 is acceptable to me, except that it I still have to do RegExp matching against URLs in its current form if I want to know whether I'm running io.js brand node, or Node.js brand node. As a side note, I feel like I'm missing something important. People claim that feature-detection isn't necessary, but if all I have is a runtime and / or V8 version, then I basically need to build some kind of kangax-style feature matrix corresponding to those versions. In what universe is this not a huge pain in the ass? |
rvagg
commented
Jan 19, 2015
@othiym23 note my PR has a |
othiym23
commented
Jan 19, 2015
@rvagg 👍 With that, I withdraw this PR in favor of that one, even though I personally think this solution is simpler than either |
ruimarinho
commented
Jan 19, 2015
@othiym23, what I think @domenic was referring to was the path that some user agent vendors, specifically MS/IE, took to precisely evade those checks by tricking user agent string matches (due to the replacement of "MSIE" for "like Gecko") into recognising it as another browser. When/if Joyent finds enough value on "built for io.js" packages that use the I may also not be getting the full picture, but I do believe some sort of feature detection will be needed if backwards compatibility is needed (e.g. use native Promises or fallback to a userland implementation) or a more convoluted syntax support test ( Even if developers find a specific need that does require knowledge about the runtime, in my opinion, we should focus on promoting use cases where they are actually necessary (as #493 shows). In fact, I'm surprised npmjs.com/is-iojs isn't already taken :-) |
rvagg
commented
Jan 19, 2015
@othiym23 providing explicit URLs gives us immediate support for nightlies when this lands in node-gyp, there's also the fact that we've improved (IMO) on some conventions in /dist/ inherited from node so we're not 100% compatible. |
edef1c
commented
Jan 21, 2015
I'm somewhat doubtful about the value of an explicit UA string style thing — feature flags / feature detection should take their place, imo. Is there any specific reason feature detection won't do, and if so, why is this considered a better solution than feature flags? |
dougwilson
commented
Feb 26, 2015
If there is a breaking change in the API for |
domenic
commented
Feb 26, 2015
@dougwilson you test to see which behavior you have and throw an error if you get the behavior you don't want. |
dougwilson
commented
Feb 26, 2015
At that point, why do i even bother putting anything in my |
dougwilson
commented
Feb 26, 2015
I don't see why you would even bother with semver if I cannot use it. |
domenic
commented
Feb 26, 2015
Are you just trolling? Obviously your dependencies are different than the executable running them, in that you actually control (through package.json) which versions of your dependencies get installed. |
dougwilson
commented
Feb 26, 2015
Right, but is |
dougwilson
commented
Feb 27, 2015
vkurchatkin
commented
Feb 27, 2015
No, please, don't |
This gives user code a forward-compatible means for determining whether it's running in io.js or Node.js. Also, to ensure backwards compatibility, it leaves the existing
process.versions.nodealone.This will be helpful for tools like
node-gypto figure out whether they're running against Node.js or io.js. See nodejs/node-gyp#564 for a discussion of how this might be useful.Everything's basically the same except:
PR: @rvagg
PR: @bnoordhuis