Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Fix double import breakage #220

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bitcore-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = {};
Expand Down Expand Up @@ -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}]},{},[]);
19 changes: 10 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;
8 changes: 1 addition & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});