-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expose API dependencies by default #231
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
Conversation
+1
Yes please |
This doesn't eliminate browserify, it just provides all the dependencies. You still need to use browserify to use the library properly in the browser, otherwise it will only work in node.js. See my comments on #228. I am opposed to de-coupling browserify from the code, and it's basically impossible to use it in the browser without using browserify anyways. If developers need these external dependencies, they should include them in their project directly. |
Possible compromise: We expose the dependencies, but in a way that's separated from the rest of the code. So, instead of doing Or more correctly, The thing is, at least one of these is guaranteed to eventually break, so why bother? |
I'm with you on this. At first I was in favor of the idea, but exposing dependencies (that are out of scope) seems like a bad way to tie yourself to legacy code. It also sets up expectations for consumers of the API. Now, it is true that this problem can be solved by proper adherence to semver, but what's the point if we know that these dependencies will change. Especially, |
Like I said to @dcousens on IRC, I'm on the fence. I used to strongly believe that what we are doing now (not exposing dependencies) is the way to go. But by now there are at least 3 people who have requested the opposite because they want to use bitcoinjs-lib as a bundle in browser without browserify. I hate to stop devs from using our library because of this. And code wise, it doesn't take us much effort to expose our dependencies. The downside of exposing our dependencies is the interface change when we swap/upgrade our underlining library. So going forward if we are using semver, when our dependencies bump their major version, we need to bump ours. |
Alternatively we could provide a secondary compilation target.
Which compiles the following (or something similar) using browserify: module.exports = {
base58: require('bs58'),
bigi: require('bigi'),
bitcoinjs: require('bitcoinjs-lib'),
cryptojs: require('crypto-js'),
ecurve: require('ecurve')
} That way in the event of an API change (say we switch |
I just wanted to chime in here, because, being a complete browserify idiot, and not knowing anything about js package development / management, I have basically been stuck as fook. Now, I did as @dcousens said; So on this basis, I would recommend including the compile-bundle one in the package.json . .. simply so people can either try the just compile on itself, or if they need access to the full feature set.. then they can run the compile bundle... and from what I can tell.. it doesn't increase file size at all.. only makes the inaccessible... accessible.. so makes sense.. |
Can we get away with simply documenting in README how one could create their own secondary compilation target? |
I'm okay with the compile-bundle compromise, if it was called 'compile-with-internal-deps' or something, and has a warning placed next to it (and in the README) that the dependencies are subject to change in newer versions. |
Added |
I agree with @kyledrake that Also can we avoid repeating ourselves by making bundle.js something like var bitcoin = require('./src/index')
var exports = {
base58: require('bs58'),
BigInteger: require('bigi'),
CryptoJS: require('crypto-js'),
ec: require('ecurve'),
securerandom: require('secure-random')
}
for(var key in bitcoin) {
exports[key] = bitcoin[key]
}
module.exports = exports |
@dcousens thoughts on the task name? |
Sounds good to me, @weilu thoughts on the corresponding file name |
|
move bundle.js to src and I'm +1! |
Despite everything that has been discussed to this point. I vote we expose the dependencies in favour of forcing users to use the version we use. It sucks, but The other option is |
At this point, the following code will throw an exception about
This is exactly how it should look as the 'ideal' demonstration of how to use our API, and yet it fails unless the user uses identical dependencies to us. |
As mentioned in #255 (comment), my take is that
|
If you want to adhere to semver, exposing dependencies is a bad idea as any incompatible change would force bitcoinjs-lib to bump its major version. Assuming you want to adhere to semver as it's kinda expected in the Node.js world. Get rid of |
An example of the var pub = new ECPubKey(...)
function someMethod(key) {
if (key.constructor.name !== 'ECPubKey') throw new Error('Not ECPubKey')
} This will work for different versions of ECPubKey. |
Per IRC discussion with @weilu I've changed my mind on exposing the dependencies. It makes sense so consumers can freely use them and not worry about incompatible changes amongst versions; even worse, if there was an improper calculation leading to a silent error. |
Hey folks, Just to weigh in with some opinions and more options... If I were you guys
There are potential options in between that I've seen for other languages that I guess could be adapted to javascript
Or heck, just lose the isInstanceOf and caveat emptor on the use of your library. Self-test asserts on init anyway. I don't have a Right Answer :) |
Thanks for the comments @glorat :) I am also tempted to just caveat emptor, but perhaps with some sanity checking on expected results. |
Wrapping |
Still thinking about this one, seriously considering the more caveat emptor approach for Ideally however, I'm hoping to just remove as many non POD types from the API as possible, without any compromise in performance capabilities. |
For ongoing food for thought... I still remain firmly on the fence :) |
This problem isn't solved, but this PR isn't the solution. Will close. |
Continuation of the discussion in #228.
There seems to be a collective of users that don't want to go down the
browserify
path, and instead prefer the all-in-1 bundle approach (for better or worse).This pull request would provide the latter.
On the surface, this is a terrible decision in avoiding future problems where we do intend to change the underlying
BigInteger
implementation, and removeCryptoJS
as a dependency completely.Its a step backwards in re-usable software, but its a massive convenience to those who just want to plug and play with bitcoin in Javascript.
Thoughts? Can we somehow have both? Maybe a separate repository that bundles all this together that we can point them at?