dmonad / lib0

Monorepo of isomorphic utility functions
MIT License
345 stars 63 forks source link

isNode detection not always working #67

Closed garth closed 10 months ago

garth commented 1 year ago

Describe the bug

Remix recently moved their development libs to depend on @jspm/core. Unfortunately this package will polyfill window.process to make it look the like node, so that the following line returns true in the browser:

https://github.com/dmonad/lib0/blob/bd69ab4dc701d77e808f2bab08d96d63acd297da/environment.js#L15-L16

I realise this is not strictly a bug in lib0, but maybe the isNode detection could be tweaked to work in browser environments patched with @jspm/core?

To Reproduce Load y-js into any project with running via @remix-run/dev@1.16 and the browser logic thinks it's running in node.

Expected behavior Be able to detect the browser environment despite process being patched by @jspm/core.

Environment Information

garth commented 1 year ago

This approach by the detect-node module seems to work even when @jspm/core is loaded:

https://github.com/iliakan/detect-node/blob/00381fd0fdbdefa625ac7b8230adfc1df11d49ad/index.js#L1-L2

dmonad commented 10 months ago

Makes sense. I implemented the recommended approach.