UNPKG

2.56 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const extenders_1 = require("./core/config/extenders");
4const errors_1 = require("./core/errors");
5const errors_list_1 = require("./core/errors-list");
6const dsl_1 = require("./core/tasks/dsl");
7class BuidlerContext {
8 constructor() {
9 this.tasksDSL = new dsl_1.TasksDSL();
10 this.extendersManager = new extenders_1.ExtenderManager();
11 this.loadedPlugins = [];
12 this.configExtenders = [];
13 // NOTE: This is experimental and will be removed. Please contact our team if
14 // you are planning to use it.
15 this.experimentalBuidlerEVMMessageTraceHooks = [];
16 }
17 static isCreated() {
18 const globalWithBuidlerContext = global;
19 return globalWithBuidlerContext.__buidlerContext !== undefined;
20 }
21 static createBuidlerContext() {
22 if (this.isCreated()) {
23 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED);
24 }
25 const globalWithBuidlerContext = global;
26 const ctx = new BuidlerContext();
27 globalWithBuidlerContext.__buidlerContext = ctx;
28 return ctx;
29 }
30 static getBuidlerContext() {
31 const globalWithBuidlerContext = global;
32 const ctx = globalWithBuidlerContext.__buidlerContext;
33 if (ctx === undefined) {
34 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED);
35 }
36 return ctx;
37 }
38 static deleteBuidlerContext() {
39 const globalAsAny = global;
40 globalAsAny.__buidlerContext = undefined;
41 }
42 setBuidlerRuntimeEnvironment(env) {
43 if (this.environment !== undefined) {
44 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_ALREADY_DEFINED);
45 }
46 this.environment = env;
47 }
48 getBuidlerRuntimeEnvironment() {
49 if (this.environment === undefined) {
50 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_BRE_NOT_DEFINED);
51 }
52 return this.environment;
53 }
54 setPluginAsLoaded(pluginName) {
55 this.loadedPlugins.push(pluginName);
56 }
57 setConfigPath(configPath) {
58 this._configPath = configPath;
59 }
60 getConfigPath() {
61 if (this._configPath === undefined) {
62 throw new errors_1.BuidlerError(errors_list_1.ERRORS.GENERAL.CONTEXT_CONFIG_PATH_NOT_SET);
63 }
64 return this._configPath;
65 }
66}
67exports.BuidlerContext = BuidlerContext;
68//# sourceMappingURL=context.js.map
\No newline at end of file