diff --git a/bitcore-lib.js b/bitcore-lib.js index 3014204b9..0d78d13c3 100644 --- a/bitcore-lib.js +++ b/bitcore-lib.js @@ -54080,16 +54080,15 @@ var bitcore = module.exports; // module information bitcore.version = 'v' + require('./package.json').version; -bitcore.versionGuard = function(version) { - if (version !== undefined) { - var message = 'More than one instance of bitcore-lib found. ' + - 'Please make sure to require bitcore-lib and check that submodules do' + - ' not also include their own bitcore-lib dependency.'; - throw new Error(message); + +if (global._bitcore !== undefind) { + if (typeof global._bitcore !== 'object' || global._bitcore.version !== bitcore.version) { + throw new Error('Outdated version of bitcore-lib found, ' + + 'please make sure all dependencies have the same version.'); } -}; -bitcore.versionGuard(global._bitcore); -global._bitcore = bitcore.version; + module.exports = global._bitcore; + return; +} // crypto bitcore.crypto = {}; @@ -54144,5 +54143,6 @@ bitcore.deps._ = require('lodash'); // Internal usage, exposed for testing/advanced tweaking bitcore.Transaction.sighash = require('./lib/transaction/sighash'); +global._bitcore = bitcore; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer) },{"./lib/address":1,"./lib/block":4,"./lib/block/blockheader":3,"./lib/block/merkleblock":5,"./lib/crypto/bn":6,"./lib/crypto/ecdsa":7,"./lib/crypto/hash":8,"./lib/crypto/point":9,"./lib/crypto/random":10,"./lib/crypto/signature":11,"./lib/encoding/base58":12,"./lib/encoding/base58check":13,"./lib/encoding/bufferreader":14,"./lib/encoding/bufferwriter":15,"./lib/encoding/varint":16,"./lib/errors":17,"./lib/hdprivatekey.js":19,"./lib/hdpublickey.js":20,"./lib/networks":21,"./lib/opcode":22,"./lib/privatekey":23,"./lib/publickey":24,"./lib/script":25,"./lib/transaction":28,"./lib/transaction/sighash":36,"./lib/unit":40,"./lib/uri":41,"./lib/util/buffer":42,"./lib/util/js":43,"./lib/util/preconditions":44,"./package.json":320,"bn.js":280,"bs58":281,"buffer":47,"elliptic":285,"lodash":319}]},{},[]); diff --git a/index.js b/index.js index eaa6107a4..af199970d 100644 --- a/index.js +++ b/index.js @@ -4,16 +4,15 @@ var bitcore = module.exports; // module information bitcore.version = 'v' + require('./package.json').version; -bitcore.versionGuard = function(version) { - if (version !== undefined) { - var message = 'More than one instance of bitcore-lib found. ' + - 'Please make sure to require bitcore-lib and check that submodules do' + - ' not also include their own bitcore-lib dependency.'; - throw new Error(message); + +if (global._bitcore !== undefined) { + if (typeof global._bitcore !== 'object' || global._bitcore.version !== bitcore.version) { + throw new Error('Outdated version of bitcore-lib found, ' + + 'please make sure all dependencies have the same version.'); } -}; -bitcore.versionGuard(global._bitcore); -global._bitcore = bitcore.version; + module.exports = global._bitcore; + return; +} // crypto bitcore.crypto = {}; @@ -67,3 +66,5 @@ bitcore.deps._ = require('lodash'); // Internal usage, exposed for testing/advanced tweaking bitcore.Transaction.sighash = require('./lib/transaction/sighash'); + +global._bitcore = bitcore; diff --git a/test/index.js b/test/index.js index 47bad735a..ea64101b3 100644 --- a/test/index.js +++ b/test/index.js @@ -5,12 +5,6 @@ var bitcore = require("../"); describe('#versionGuard', function() { it('global._bitcore should be defined', function() { - should.equal(global._bitcore, bitcore.version); - }); - - it('throw an error if version is already defined', function() { - (function() { - bitcore.versionGuard('version'); - }).should.throw('More than one instance of bitcore'); + should.equal(global._bitcore, bitcore); }); });