forked from trufflesuite/ganache
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
37 lines (33 loc) · 1.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// make sourcemaps work!
require("source-map-support/register");
const debug = require("debug")("ganache");
// we use optional dependencies which may, or may not exist, so try native first
try {
// make sure these exist before we try to load ganache with native modules
const optionalDependencies = require("./package.json").optionalDependencies;
const wrongWeb3 = require("web3/package.json").version !== optionalDependencies["web3"];
const wrongEthereumJs = require(
"ethereumjs-wallet/package.json"
).version !== optionalDependencies["ethereumjs-wallet"];
if (wrongWeb3 || wrongEthereumJs) {
useBundled();
} else {
module.exports = require("./public-exports.js");
module.exports._webpacked = false;
debug("Optional dependencies installed; exporting ganache-core with native optional dependencies.");
}
} catch (nativeError) {
debug(nativeError);
// grabbing the native/optional deps failed, try using our webpacked build.
useBundled();
}
function useBundled() {
try {
module.exports = require("./build/ganache.core.node.js");
module.exports._webpacked = true;
debug("Optional dependencies not installed; exporting ganache-core from `./build` directory.");
} catch (webpackError) {
debug("ganache-core could not be exported; optional dependencies nor webpack build available for export.");
throw webpackError;
}
}