1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.HardhatContext = void 0;
|
4 | const errors_1 = require("./core/errors");
|
5 | const errors_list_1 = require("./core/errors-list");
|
6 | const vars_manager_1 = require("./core/vars/vars-manager");
|
7 | const dsl_1 = require("./core/tasks/dsl");
|
8 | const global_dir_1 = require("./util/global-dir");
|
9 | const platform_1 = require("./util/platform");
|
10 | class HardhatContext {
|
11 | constructor() {
|
12 | this.tasksDSL = new dsl_1.TasksDSL();
|
13 | this.environmentExtenders = [];
|
14 | this.providerExtenders = [];
|
15 | this.configExtenders = [];
|
16 |
|
17 |
|
18 | this.experimentalHardhatNetworkMessageTraceHooks = [];
|
19 | this.varsManager = new vars_manager_1.VarsManager((0, global_dir_1.getVarsFilePath)());
|
20 | }
|
21 | static isCreated() {
|
22 | const globalWithHardhatContext = global;
|
23 | return globalWithHardhatContext.__hardhatContext !== undefined;
|
24 | }
|
25 | static createHardhatContext() {
|
26 | if (this.isCreated()) {
|
27 | throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_ALREADY_CREATED);
|
28 | }
|
29 | const globalWithHardhatContext = global;
|
30 | const ctx = new HardhatContext();
|
31 | globalWithHardhatContext.__hardhatContext = ctx;
|
32 | return ctx;
|
33 | }
|
34 | static getHardhatContext() {
|
35 | const globalWithHardhatContext = global;
|
36 | const ctx = globalWithHardhatContext.__hardhatContext;
|
37 | if (ctx === undefined) {
|
38 | throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_NOT_CREATED);
|
39 | }
|
40 | return ctx;
|
41 | }
|
42 | static deleteHardhatContext() {
|
43 | const globalAsAny = global;
|
44 | globalAsAny.__hardhatContext = undefined;
|
45 | }
|
46 | setHardhatRuntimeEnvironment(env) {
|
47 | if (this.environment !== undefined) {
|
48 | throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_HRE_ALREADY_DEFINED);
|
49 | }
|
50 | this.environment = env;
|
51 | }
|
52 | getHardhatRuntimeEnvironment() {
|
53 | if (this.environment === undefined) {
|
54 | throw new errors_1.HardhatError(errors_list_1.ERRORS.GENERAL.CONTEXT_HRE_NOT_DEFINED);
|
55 | }
|
56 | return this.environment;
|
57 | }
|
58 | setConfigLoadingAsStarted() {
|
59 | this._filesLoadedBeforeConfig = (0, platform_1.getRequireCachedFiles)();
|
60 | }
|
61 | setConfigLoadingAsFinished() {
|
62 | this._filesLoadedAfterConfig = (0, platform_1.getRequireCachedFiles)();
|
63 | }
|
64 | getFilesLoadedDuringConfig() {
|
65 |
|
66 | if (this._filesLoadedBeforeConfig === undefined) {
|
67 | return [];
|
68 | }
|
69 | (0, errors_1.assertHardhatInvariant)(this._filesLoadedAfterConfig !== undefined, "Config loading was set as started and not finished");
|
70 | return arraysDifference(this._filesLoadedAfterConfig, this._filesLoadedBeforeConfig);
|
71 | }
|
72 | }
|
73 | exports.HardhatContext = HardhatContext;
|
74 | function arraysDifference(a, b) {
|
75 | return a.filter((e) => !b.includes(e));
|
76 | }
|
77 |
|
\ | No newline at end of file |