@kubiklabs/wasmkit
Version:
Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.
54 lines (53 loc) • 1.83 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetWasmkitContext = void 0;
/**
* This function resets the WasmKit context.
*
* This doesn't unload any loaded WasmKit plugin, so those have to be unloaded
* manually with `unloadModule`.
*/
const context_1 = require("./context");
const project_structure_1 = require("./core/project-structure");
function resetWasmkitContext() {
if (context_1.WasmkitContext.isCreated()) {
const ctx = context_1.WasmkitContext.getWasmkitContext();
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 WasmKit project
}
if (configPath !== undefined) {
unloadModule(configPath);
}
}
context_1.WasmkitContext.deleteWasmkitContext();
}
// Unload all the WasmKit's entry-points.
unloadModule("../register");
unloadModule("./cli/cli");
unloadModule("./lib/lib");
}
exports.resetWasmkitContext = resetWasmkitContext;
function unloadModule(path) {
try {
delete require.cache[require.resolve(path)];
}
catch (err) {
// module wasn't loaded
}
}