1 | import debug from "debug";
|
2 |
|
3 | import { BuidlerContext } from "./internal/context";
|
4 | import { loadConfigAndTasks } from "./internal/core/config/config-loading";
|
5 | import { BUIDLER_PARAM_DEFINITIONS } from "./internal/core/params/buidler-params";
|
6 | import { getEnvBuidlerArguments } from "./internal/core/params/env-variables";
|
7 | import { Environment } from "./internal/core/runtime-environment";
|
8 | import { loadTsNodeIfPresent } from "./internal/core/typescript-support";
|
9 | import {
|
10 | disableReplWriterShowProxy,
|
11 | isNodeCalledWithoutAScript,
|
12 | } from "./internal/util/console";
|
13 |
|
14 | if (!BuidlerContext.isCreated()) {
|
15 |
|
16 | require("source-map-support/register");
|
17 |
|
18 | const ctx = BuidlerContext.createBuidlerContext();
|
19 |
|
20 | if (isNodeCalledWithoutAScript()) {
|
21 | disableReplWriterShowProxy();
|
22 | }
|
23 |
|
24 | loadTsNodeIfPresent();
|
25 |
|
26 | const buidlerArguments = getEnvBuidlerArguments(
|
27 | BUIDLER_PARAM_DEFINITIONS,
|
28 | process.env
|
29 | );
|
30 |
|
31 | if (buidlerArguments.verbose) {
|
32 | debug.enable("buidler*");
|
33 | }
|
34 |
|
35 | const config = loadConfigAndTasks(buidlerArguments);
|
36 |
|
37 |
|
38 |
|
39 | if (buidlerArguments.network === undefined) {
|
40 | buidlerArguments.network = config.defaultNetwork;
|
41 | }
|
42 |
|
43 | const env = new Environment(
|
44 | config,
|
45 | buidlerArguments,
|
46 | ctx.tasksDSL.getTaskDefinitions(),
|
47 | ctx.extendersManager.getExtenders(),
|
48 | ctx.experimentalBuidlerEVMMessageTraceHooks
|
49 | );
|
50 |
|
51 | ctx.setBuidlerRuntimeEnvironment(env);
|
52 |
|
53 | env.injectToGlobal();
|
54 | }
|