commit
85dd29e576
29
index.js
29
index.js
@ -1,26 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
var bitcore = module.exports;
|
var bitcore = module.exports;
|
||||||
|
|
||||||
// module information
|
// module information
|
||||||
bitcore.version = 'v' + require('./package.json').version;
|
bitcore.version = 'v' + require('./package.json').version;
|
||||||
|
bitcore.versionGuard = function(version) {
|
||||||
var inBrowser = typeof process === 'undefined' || typeof process.versions === 'undefined';
|
if (version !== undefined) {
|
||||||
if ((inBrowser && window._bitcore) || (!inBrowser && global._bitcore)) {
|
var message = 'More than one instance of bitcore found with versions: ' + bitcore.version +
|
||||||
var versions = bitcore.version + ' and ' + (inBrowser ? window._bitcore : global._bitcore);
|
' and ' + version + '. Please make sure to require bitcore and check that submodules do' +
|
||||||
var message = 'More than one instance of bitcore found with different versions: ' + versions;
|
' not also include their own bitcore dependency.';
|
||||||
if (inBrowser) {
|
throw new Error(message);
|
||||||
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);
|
bitcore.versionGuard(global._bitcore);
|
||||||
}
|
global._bitcore = bitcore.version;
|
||||||
if (inBrowser) {
|
|
||||||
window._bitcore = bitcore.version;
|
|
||||||
} else {
|
|
||||||
global._bitcore = bitcore.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
// crypto
|
// crypto
|
||||||
bitcore.crypto = {};
|
bitcore.crypto = {};
|
||||||
|
|||||||
16
test/index.js
Normal file
16
test/index.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var should = require('chai').should();
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user