bn.js
bn.js copied to clipboard
remove Buffer dependency
Would it be possible to remove the Buffer dependency outright. My webpack is including Buffer, but I dont use it anywhere else, I traced it to BN.js.
You should be able to exclude Buffer
to no ill-affect, the require
is wrapped in a try catch and is only done lazily if necessary.
Just be careful if you have other dependencies (now or in the future) that could break.
On Wed, Apr 12, 2017, 6:25 PM Daniel Cousens [email protected] wrote:
You should be able to exclude Buffer to no ill-affect, the require is wrapped in a try catch and is only done lazily if necessary.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/indutny/bn.js/issues/160#issuecomment-293724829, or mute the thread https://github.com/notifications/unsubscribe-auth/ABE4nyXPvUVB7wF7vVCSeNhT3wYbAjxHks5rvU9ggaJpZM4M8CmK .
@dcousens webpack still registers it as a dependency. It tries to make sense of the dynamics of it. I just think it's bad design to have dynamic requires. I would remove it outright. It doesn't seem needed for the trouble.
@SilentCicero except for those of us that use Buffer
everywhere in crypto.
@dcousens well yes, your definitely right there, it is used in a ton of places for crypto (I use it a lot in a ton of places). But my extreme UNIX and module isolation policy has made me an insane person. And I thought I would make a case to have it removed since it plays a very little role in this specific module (as well, many of us are switching to Uin8Arrays =D).
UInt8Arrays
You know that is what a Buffer
is?
@dcousens I'm not actually aware of what buffer is using internally, although I know it uses them. But a lot of the work we do for crypto stuff just requires some basic uses of uint8arrays (we are finding we dont need the whole buffer module for things).
Anyway, no worries, just trying to get that dynamic/almost unused buffer dependency removed. I love BN.js, it has been a solid fantastic module for me.
@SilentCicero Buffer
is quite literally UInt8Array
, see here.
The difference is the added methods for serialization and conversion to avoid re-implementations popping up everywhere that almost always lead to bugs. It also makes node compatibility dead simple.
Anyway :+1:
I think package.json
has buffer: false
in browser
field now. Does this suffice?
@indutny actually, that simply disables it out-right for all browserify users... even if buffer
is imported elsewhere in your bundle.
It removes it from the dependency chain for bn.js
so the require
fails.
Oh yikes. Bundling is hard 😭
@indutny I am not against using a require('bn.js/buffer')
like import to get Buffer
in there if it drops the dep in areas where it unnecessary.
Breaking change obviously.