@nomiclabs/buidler
Version:
Buidler is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
51 lines • 1.7 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/**
* This function resets the buidler context.
*
* This doesn't unload any loaded Buidler plugin, so those have to be unloaded
* manually with `unloadModule`.
*/
const context_1 = require("./context");
const project_structure_1 = require("./core/project-structure");
function resetBuidlerContext() {
if (context_1.BuidlerContext.isCreated()) {
const ctx = context_1.BuidlerContext.getBuidlerContext();
const globalAsAny = global;
if (ctx.environment !== undefined) {
for (const key of Object.keys(ctx.environment)) {
globalAsAny[key] = undefined;
}
// unload config file too.
unloadModule(ctx.environment.config.paths.configFile);
}
else {
// We may get here if loading the config has thrown, so be unload it
let configPath;
try {
configPath = project_structure_1.getUserConfigPath();
}
catch (error) {
// We weren't in a buidler project
}
if (configPath !== undefined) {
unloadModule(configPath);
}
}
context_1.BuidlerContext.deleteBuidlerContext();
}
// Unload all the buidler's entry-points.
unloadModule("../register");
unloadModule("./cli/cli");
unloadModule("./lib/buidler-lib");
}
exports.resetBuidlerContext = resetBuidlerContext;
function unloadModule(path) {
try {
delete require.cache[require.resolve(path)];
}
catch (err) {
// module wasn't loaded
}
}
//# sourceMappingURL=reset.js.map
;