UNPKG

1.88 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5const debug_1 = __importDefault(require("debug"));
6const context_1 = require("../context");
7const config_loading_1 = require("../core/config/config-loading");
8const errors_1 = require("../core/errors");
9const errors_list_1 = require("../core/errors-list");
10const buidler_params_1 = require("../core/params/buidler-params");
11const env_variables_1 = require("../core/params/env-variables");
12const runtime_environment_1 = require("../core/runtime-environment");
13let ctx;
14let env;
15if (context_1.BuidlerContext.isCreated()) {
16 ctx = context_1.BuidlerContext.getBuidlerContext();
17 // The most probable reason for this to happen is that this file was imported
18 // from the config file
19 if (ctx.environment === undefined) {
20 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.LIB_IMPORTED_FROM_THE_CONFIG);
21 }
22 env = ctx.environment;
23}
24else {
25 ctx = context_1.BuidlerContext.createBuidlerContext();
26 const buidlerArguments = env_variables_1.getEnvBuidlerArguments(buidler_params_1.BUIDLER_PARAM_DEFINITIONS, process.env);
27 if (buidlerArguments.verbose) {
28 debug_1.default.enable("buidler*");
29 }
30 const config = config_loading_1.loadConfigAndTasks(buidlerArguments);
31 // TODO: This is here for backwards compatibility.
32 // There are very few projects using this.
33 if (buidlerArguments.network === undefined) {
34 buidlerArguments.network = config.defaultNetwork;
35 }
36 env = new runtime_environment_1.Environment(config, buidlerArguments, ctx.tasksDSL.getTaskDefinitions(), ctx.extendersManager.getExtenders(), ctx.experimentalBuidlerEVMMessageTraceHooks);
37 ctx.setBuidlerRuntimeEnvironment(env);
38}
39module.exports = env;
40//# sourceMappingURL=buidler-lib.js.map
\No newline at end of file