-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
39d0732
Compare
I'm +1 on this change, and LGTM. It might be worth referencing the previous discussion on #253. |
Thanks, @cjihrig. Left a comment there to try to persuade my boss that this PR is a good idea. |
good luck on that, he's been the most vocal against it |
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 |
Existing detection mechanisms that I can think of that should be cross-platform safe: Versionfunction isiojs () {
return parseInt(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_VERSIONfunction isiojs () {
return parseInt(process.versions.modules >= 42 && process.versions.modules < 100)
} This is semi-safe for similar reasons but has some additional possible benefits:
Forkfunction isiojs (callback) {
require('child_process').exec(process.execPath + ' -h', function (err, stderr, stdout) {
if (err) return callback(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. |
If we really must have a User-Agent equivalent then I'd like to propose a |
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 |
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. |
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? |
@othiym23 note my PR has a |
@rvagg 👍 With that, I withdraw this PR in favor of that one, even though I personally think this solution is simpler than either |
@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 :-) |
@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. |
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? |
If there is a breaking change in the API for |
@dougwilson you test to see which behavior you have and throw an error if you get the behavior you don't want. |
At that point, why do i even bother putting anything in my |
I don't see why you would even bother with semver if I cannot use it. |
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. |
Right, but is |
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.node
alone.This will be helpful for tools like
node-gyp
to 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