Merge pull request #1165 from eordano/feature/guard
Add guard to prevent more than one instance of bitcore
This commit is contained in:
commit
dc77afac1d
24
index.js
24
index.js
|
@ -1,5 +1,26 @@
|
|||
var bitcore = module.exports;
|
||||
|
||||
// module information
|
||||
bitcore.version = 'v'+require('./package.json').version;
|
||||
|
||||
var inBrowser = typeof process === 'undefined' || typeof process.versions === 'undefined';
|
||||
if ((inBrowser && window._bitcore) || (!inBrowser && global._bitcore)) {
|
||||
var versions = bitcore.version + ' and ' + inBrowser ? window._bitcore : global._bitcore;
|
||||
var message = 'More than one instance of bitcore found with different versions: ' + versions;
|
||||
if (inBrowser) {
|
||||
message += '. Make sure any scripts included don\'t contain their own bitcore bundle.';
|
||||
} else {
|
||||
message += '. Make sure there are no version conflicts between package.json files of your '
|
||||
+ 'dependencies. This could also happen when a package depends on a git repository.';
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
if (inBrowser) {
|
||||
window._bitcore = bitcore.version;
|
||||
} else {
|
||||
global._bitcore = bitcore.version;
|
||||
}
|
||||
|
||||
// crypto
|
||||
bitcore.crypto = {};
|
||||
|
@ -54,6 +75,3 @@ bitcore.deps._ = require('lodash');
|
|||
// Internal usage, exposed for testing/advanced tweaking
|
||||
bitcore._HDKeyCache = require('./lib/hdkeycache');
|
||||
bitcore.Transaction.sighash = require('./lib/transaction/sighash');
|
||||
|
||||
// module information
|
||||
bitcore.version = 'v'+require('./package.json').version;
|
||||
|
|
Loading…
Reference in New Issue