modules: more browser compat.
This commit is contained in:
parent
354cf00158
commit
baffd161b8
31
lib/env.js
31
lib/env.js
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var lazy = require('./utils/lazy');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A BCoin "environment" which is used for
|
* A BCoin "environment" which is used for
|
||||||
* bootstrapping the initial `bcoin` module.
|
* bootstrapping the initial `bcoin` module.
|
||||||
@ -105,6 +107,7 @@
|
|||||||
|
|
||||||
function Environment() {
|
function Environment() {
|
||||||
this.env = Environment;
|
this.env = Environment;
|
||||||
|
this.require = lazy(require, this);
|
||||||
|
|
||||||
// BN
|
// BN
|
||||||
this.require('bn', 'bn.js');
|
this.require('bn', 'bn.js');
|
||||||
@ -208,21 +211,6 @@ function Environment() {
|
|||||||
this.require('bip70', './bip70');
|
this.require('bip70', './bip70');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assign a lazily required module.
|
|
||||||
* @param {String} key
|
|
||||||
* @param {String} path
|
|
||||||
*/
|
|
||||||
|
|
||||||
Environment.prototype.require = function _require(key, path) {
|
|
||||||
var cache;
|
|
||||||
this.__defineGetter__(key, function() {
|
|
||||||
if (!cache)
|
|
||||||
cache = require(path);
|
|
||||||
return cache;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the default network.
|
* Set the default network.
|
||||||
* @param {String} options
|
* @param {String} options
|
||||||
@ -260,12 +248,12 @@ Environment.prototype.now = function now() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Environment.prototype.cache = function cache() {
|
Environment.prototype.cache = function cache() {
|
||||||
require('./node/fullnode');
|
this.fullnode;
|
||||||
require('./node/spvnode');
|
this.spvnode;
|
||||||
require('./http');
|
this.http;
|
||||||
require('./crypto/schnorr');
|
this.crypto.schnorr;
|
||||||
require('./utils/uri');
|
this.uri;
|
||||||
require('./bip70');
|
this.bip70;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -273,7 +261,6 @@ Environment.prototype.cache = function cache() {
|
|||||||
* Environment.
|
* Environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.require = Environment.prototype.require;
|
|
||||||
exports.cache = Environment.prototype.cache;
|
exports.cache = Environment.prototype.cache;
|
||||||
exports.set = Environment.prototype.set;
|
exports.set = Environment.prototype.set;
|
||||||
exports.now = Environment.prototype.now;
|
exports.now = Environment.prototype.now;
|
||||||
|
|||||||
@ -1946,9 +1946,6 @@ utils.U32 = function U32(num) {
|
|||||||
|
|
||||||
utils.lazy = require('./lazy');
|
utils.lazy = require('./lazy');
|
||||||
|
|
||||||
if (utils.lazy.unsupported)
|
|
||||||
utils.lazy = function() { return utils.nop; };
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expose other objects.
|
* Expose other objects.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -71,6 +71,7 @@
|
|||||||
"./lib/utils/native": "./browser/empty.js",
|
"./lib/utils/native": "./browser/empty.js",
|
||||||
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
|
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
|
||||||
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",
|
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",
|
||||||
|
"./lib/utils/lazy": "./lib/utils/lazy-browser.js",
|
||||||
"./lib/crypto/backend": "./lib/crypto/backend-browser.js",
|
"./lib/crypto/backend": "./lib/crypto/backend-browser.js",
|
||||||
"./lib/crypto/ec": "./lib/crypto/ec-elliptic.js",
|
"./lib/crypto/ec": "./lib/crypto/ec-elliptic.js",
|
||||||
"./lib/crypto/pk": "./lib/crypto/pk-browser.js",
|
"./lib/crypto/pk": "./lib/crypto/pk-browser.js",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user