UNPKG

1.7 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * This function resets the buidler context.
5 *
6 * This doesn't unload any loaded Buidler plugin, so those have to be unloaded
7 * manually with `unloadModule`.
8 */
9const context_1 = require("./context");
10const project_structure_1 = require("./core/project-structure");
11function resetBuidlerContext() {
12 if (context_1.BuidlerContext.isCreated()) {
13 const ctx = context_1.BuidlerContext.getBuidlerContext();
14 const globalAsAny = global;
15 if (ctx.environment !== undefined) {
16 for (const key of Object.keys(ctx.environment)) {
17 globalAsAny[key] = undefined;
18 }
19 // unload config file too.
20 unloadModule(ctx.environment.config.paths.configFile);
21 }
22 else {
23 // We may get here if loading the config has thrown, so be unload it
24 let configPath;
25 try {
26 configPath = project_structure_1.getUserConfigPath();
27 }
28 catch (error) {
29 // We weren't in a buidler project
30 }
31 if (configPath !== undefined) {
32 unloadModule(configPath);
33 }
34 }
35 context_1.BuidlerContext.deleteBuidlerContext();
36 }
37 // Unload all the buidler's entry-points.
38 unloadModule("../register");
39 unloadModule("./cli/cli");
40 unloadModule("./lib/buidler-lib");
41}
42exports.resetBuidlerContext = resetBuidlerContext;
43function unloadModule(path) {
44 try {
45 delete require.cache[require.resolve(path)];
46 }
47 catch (err) {
48 // module wasn't loaded
49 }
50}
51//# sourceMappingURL=reset.js.map
\No newline at end of file