UNPKG

1.55 kBPlain TextView Raw
1import debug from "debug";
2
3import { BuidlerContext } from "./internal/context";
4import { loadConfigAndTasks } from "./internal/core/config/config-loading";
5import { BUIDLER_PARAM_DEFINITIONS } from "./internal/core/params/buidler-params";
6import { getEnvBuidlerArguments } from "./internal/core/params/env-variables";
7import { Environment } from "./internal/core/runtime-environment";
8import { loadTsNodeIfPresent } from "./internal/core/typescript-support";
9import {
10 disableReplWriterShowProxy,
11 isNodeCalledWithoutAScript,
12} from "./internal/util/console";
13
14if (!BuidlerContext.isCreated()) {
15 // tslint:disable-next-line no-var-requires
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 // TODO: This is here for backwards compatibility.
38 // There are very few projects using this.
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}