browserify / randombytes

random bytes from browserify stand alone
MIT License
99 stars 47 forks source link

Use globalThis code in place of global #24

Closed RMacfarlane closed 4 years ago

RMacfarlane commented 4 years ago

Fixes https://github.com/crypto-browserify/randombytes/issues/22

jimmywarting commented 4 years ago

should just use globalThis and if it isn't supported one should just do

self.globalThis = self window.globalThis = window global.globalThis = global

in top of their script runtime

calvinmetcalf commented 4 years ago

this is intended for use with a bundler which should handle this sort of thing, are you having problems somewhere

RMacfarlane commented 4 years ago

I'm using webpack and targeting webworker. The bundler does not do any sort of shim for global, in a webworker the only way to access the global object is self.

calvinmetcalf commented 4 years ago

Webpack 100% provides a global shim, and will provide it once to be shared by all your code, have you either turned this off? Or has web pack maybe decided to break stuff by turning it off by default?

On Thu, Sep 3, 2020, 11:16 AM Rachel Macfarlane notifications@github.com wrote:

I'm using webpack and targeting webworker. The bundler does not do any sort of shim for global, in a webworker the only way to access the global object is self.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/crypto-browserify/randombytes/pull/24#issuecomment-686562358, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITRHZYX7DPC5KMY5HWIRDSD6XLFANCNFSM4O4YOTLA .

RMacfarlane commented 4 years ago

Perhaps unintentionally.

IMO, I shouldn't have to fiddle with my bundler to get this code to run in a browser context, it should be able to do so without outside intervention.

calvinmetcalf commented 4 years ago

I know for a fact that this has worked with webpack in the past. So if it's not working out of the box anymore that could be a webpack change that will effect a lot of other libraries. I can look into it more but not until after labor day.

On Thu, Sep 3, 2020, 2:57 PM Rachel Macfarlane notifications@github.com wrote:

Perhaps unintentionally.

IMO, I shouldn't have to fiddle with my bundler to get this code to run in a browser context, it should be able to do so without outside intervention.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/crypto-browserify/randombytes/pull/24#issuecomment-686695634, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAITRH2VWKQXDGLCLKHUVUDSD7RJHANCNFSM4O4YOTLA .

RMacfarlane commented 4 years ago

Thanks!

Here's the webpack config I'm using, I may just be doing something stupid: https://github.com/microsoft/vscode/blob/616afa93e2da5a5a92b14863bab8b339b977edc4/extensions/microsoft-authentication/extension-browser.webpack.config.js

That being said, I think it's pretty easy to misconfigure webpack, and it would be helpful to others if there wasn't direct global usage that needs to be shimmed

calvinmetcalf commented 4 years ago

what version of webpack is this ?

RMacfarlane commented 4 years ago

4.43.0

calvinmetcalf commented 4 years ago

I think you turned it off here

RMacfarlane commented 4 years ago

If you don't intend to accept fixes for https://github.com/crypto-browserify/randombytes/issues/22, please close it, then.