Uh oh!
There was an error while loading. Please reload this page.
using top level context to determine node vs browser environment - #350
Conversation
coveralls
commented
Jul 11, 2018
sprockow
commented
Jul 21, 2018
So, this environment detection function is kind of hard to test. It's by definition very tightly coupled with the environment in runs on. It's written to avoid being mocked (so that a node environment with a mocked window global, like with jsdom, doesn't trigger a false positive browser detection). I'm open to an argument as to how/why to test this function. |
tromey
commented
Jul 24, 2018
This looks reasonable to me, but it occurred to me that I didn't know whether it would work properly in the weird environment that the devtools run in. So, I think someone else ought to review it, like maybe @codehag |
codehag
commented
Aug 9, 2018
This looks good to me 👍 |
loganfsmyth
commented
Sep 25, 2018
Another option here would be to use a replacement file for browser builds, e.g. in then the alternate file would be used when the library is bundled with Webpack and such, and it would be up to the consumers of the package to choose the build target. |
sprockow
commented
Sep 26, 2018
@loganfsmyth - this seems like a much cleaner approach. I haven't done too much with npm publishing, so I'm unfamiliar with this environment specific configuration. Is there a good example/best practice of how webpack projects that target these sorts alternative builds? |
loganfsmyth
commented
Sep 26, 2018
Webpack has its I think it'd be a good approach to handle to existing way that this code works. That said, I do want to clarify that I have reservations in general about how this all works, since I think it is a little scary for a library to behave in two very different ways depending on how it is used, since a you have to pass the worker URL in one case but not the other. It might be nicer in the long run for the node build to use |
Possible solution for:
#349
Ran into this issue because of my node environment's fetch polyfill. To get around this, I used a solution inspired by the solution proposed in this stack overflow question to fix this for myself.