From 09fca53d4fd82907b55d0ac4c213c79ffd5277b8 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Tue, 20 Oct 2015 14:47:02 -0400 Subject: [PATCH] allow multiple instances of bitcore-lib with the same version --- index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 9aa78d978..2c0d98ede 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,11 @@ 'use strict'; -var bitcore = module.exports; +var bitcore = {}; // module information bitcore.version = 'v' + require('./package.json').version; -bitcore.versionGuard = function(version) { - if (version !== undefined) { +bitcore.versionGuard = function(globalBitcore) { + if (globalBitcore && globalBitcore.version !== bitcore.version) { 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.'; @@ -13,7 +13,14 @@ bitcore.versionGuard = function(version) { } }; bitcore.versionGuard(global._bitcore); -global._bitcore = bitcore.version; + +// Return the original loaded bitcore-lib +if(global._bitcore) { + module.exports = global._bitcore; + return; +} + +global._bitcore = bitcore; // crypto bitcore.crypto = {}; @@ -68,3 +75,5 @@ bitcore.deps._ = require('lodash'); // Internal usage, exposed for testing/advanced tweaking bitcore._HDKeyCache = require('./lib/hdkeycache'); bitcore.Transaction.sighash = require('./lib/transaction/sighash'); + +module.exports = bitcore;