From 9b97ed55b32c6e9fc643910bf06429cd936b15c2 Mon Sep 17 00:00:00 2001 From: Igor Papandinas Date: Thu, 29 Feb 2024 09:57:16 +0100 Subject: [PATCH] fix: env in local config --- src/commands/env/install.ts | 11 ++++++----- src/lib/config-builder.ts | 4 +++- src/lib/swankyCommand.ts | 1 - src/types/index.ts | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/commands/env/install.ts b/src/commands/env/install.ts index a0ed55ff..1ee3d089 100644 --- a/src/commands/env/install.ts +++ b/src/commands/env/install.ts @@ -3,7 +3,7 @@ import { SwankyCommand } from "../../lib/swankyCommand.js"; import { InputError } from "../../lib/errors.js"; import { installCliDevDeps } from "../../lib/tasks.js"; import { SUPPORTED_DEPS } from "../../lib/consts.js"; -import { DependencyName, getSwankyConfig } from "../../index.js"; +import { DependencyName, SwankyConfig, getSwankyConfig } from "../../index.js"; import { ConfigBuilder } from "../../lib/config-builder.js"; export class Install extends SwankyCommand { @@ -50,9 +50,10 @@ export class Install extends SwankyCommand { newDeps[key] = value || "latest"; } - const globalConfig = getSwankyConfig("global"); - const newEnv = { ...globalConfig.env, ...newDeps }; + const localConfig = getSwankyConfig("local") as SwankyConfig; + const newEnv = { ...localConfig.env, ...newDeps }; const deps = Object.entries(newEnv); + for (const [dep, version] of deps) { const typedDep = dep as DependencyName; await this.spinner.runCommand( @@ -63,10 +64,10 @@ export class Install extends SwankyCommand { if (Object.keys(newDeps).length > 0) { await this.spinner.runCommand(async () => { - const newLocalConfig = new ConfigBuilder(getSwankyConfig("global")) + const newLocalConfig = new ConfigBuilder(getSwankyConfig("local")) .updateEnv(newDeps) .build(); - await this.storeConfig(newLocalConfig, "global"); + await this.storeConfig(newLocalConfig, "local"); }, "Updating swanky config"); } diff --git a/src/lib/config-builder.ts b/src/lib/config-builder.ts index 0938a099..9a4f4b0b 100644 --- a/src/lib/config-builder.ts +++ b/src/lib/config-builder.ts @@ -33,7 +33,9 @@ export class ConfigBuilder { } updateEnv(env: Record): ConfigBuilder { - this.config.env = {...this.config.env, ...env}; + if ("env" in this.config) { + this.config.env = {...this.config.env, ...env}; + } return this; } diff --git a/src/lib/swankyCommand.ts b/src/lib/swankyCommand.ts index bb53c7a1..d3c3ff43 100644 --- a/src/lib/swankyCommand.ts +++ b/src/lib/swankyCommand.ts @@ -108,7 +108,6 @@ export abstract class SwankyCommand extends Command { defaultAccount: newConfig.defaultAccount, accounts: newConfig.accounts, networks: newConfig.networks, - env: newConfig.env, }; } if (existsSync(configPath)) { diff --git a/src/types/index.ts b/src/types/index.ts index c9ff8a11..8c243e2e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -61,13 +61,13 @@ export interface SwankyConfig extends SwankySystemConfig{ }; contracts: Record | Record; zombienet?: ZombienetData; + env: Record; } export interface SwankySystemConfig { defaultAccount: string | null; accounts: AccountData[]; networks: Record; - env: Record; } export interface ZombienetData {