UNPKG

secret-polar

Version:

Polar is a development environment to compile, deploy, test, run scrt contracts on different networks.

54 lines (53 loc) 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resetPolarContext = void 0; /** * This function resets the polar context. * * This doesn't unload any loaded Polar plugin, so those have to be unloaded * manually with `unloadModule`. */ const context_1 = require("./context"); const project_structure_1 = require("./core/project-structure"); function resetPolarContext() { if (context_1.PolarContext.isCreated()) { const ctx = context_1.PolarContext.getPolarContext(); const globalAsAny = global; // eslint-disable-line @typescript-eslint/no-explicit-any if (ctx.environment !== undefined) { for (const key of Object.keys(ctx.environment)) { globalAsAny[key] = undefined; } // unload config file too. if (ctx.environment.config.paths != null) { 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 = (0, project_structure_1.getUserConfigPath)(); } catch (error) { // We weren't in a polar project } if (configPath !== undefined) { unloadModule(configPath); } } context_1.PolarContext.deletePolarContext(); } // Unload all the polar's entry-points. unloadModule("../register"); unloadModule("./cli/cli"); unloadModule("./lib/lib"); } exports.resetPolarContext = resetPolarContext; function unloadModule(path) { try { delete require.cache[require.resolve(path)]; } catch (err) { // module wasn't loaded } }