-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add check to determine if in browser or node #6
Conversation
Let me know what you think, though, because the other direction I could go in is making a totally separate import for |
var stdin = process.stdin; | ||
var in_node = true; | ||
} catch (reference_error) { | ||
var in_node = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Sorry for commenting from non-contributor)
How about this way to check:
var in_node = typeof module !== 'undefined' && module.exports
Ref: http://stackoverflow.com/questions/4224606/how-to-check-whether-a-script-is-running-under-node-js
Then, maybe sneakCase is preferable. inNode
Just ran into this and let me say I really do appreciate your timeliness! I think the API is fine, just fix the bug. I'm going to pull this down locally and report back. |
Confirming that it works. |
Hi @laszlopandy, can you get a chance to review this soon? I can change it to the solution from @igrep if you think that's better. |
👍 |
Also asking for a quick merge, as this is holding up a lot of testing and dependent packages. |
Sorry guys, I didn't see this until the mention. I will merge, I just have one concern. |
What's your concern? |
// trigger the initial IO requests | ||
sendResponseString(null); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@deadfoxygrandpa my concern is here. This fails silently if you are trying to write something to the console. It does not need to be wrapped with isNode
because unlike at the top of the file, this part doesn't run by default.
I fixed it in a different way (without wrapping everything in I published it, but I have only tested it with 0.15.1. Please let me know if there are any problems with 0.16.0: |
OK, thanks. I'll test it out in browser right now. |
Yep, this works with Elm 0.16.0 in browser. Thanks! |
Thanks Laszlo! |
When I simplified the public API for
elm-test
, it caused a runtime error in the browser since the node-specific code here runs and crashes: deadfoxygrandpa/elm-test#32I've added some runtime checks to disable those things if it's run in the browser.