UNPKG

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