diff --git a/typescript/cli/src/config/chain.ts b/typescript/cli/src/config/chain.ts index ba804c666e..7a1f2509e8 100644 --- a/typescript/cli/src/config/chain.ts +++ b/typescript/cli/src/config/chain.ts @@ -1,5 +1,4 @@ import { confirm, input, select } from '@inquirer/prompts'; -import fs from 'fs'; import { ChainMap, @@ -11,7 +10,12 @@ import { ProtocolType, objMerge } from '@hyperlane-xyz/utils'; import { errorRed, log, logBlue, logGreen } from '../../logger.js'; import { getMultiProvider } from '../context.js'; -import { FileFormat, mergeYamlOrJson, readYamlOrJson } from '../utils/files.js'; +import { + FileFormat, + isFile, + mergeYamlOrJson, + readYamlOrJson, +} from '../utils/files.js'; export function readChainConfigs(filePath: string) { log(`Reading file configs in ${filePath}`); @@ -57,7 +61,7 @@ export function readChainConfigs(filePath: string) { } export function readChainConfigsIfExists(filePath: string) { - if (!fs.existsSync(filePath)) { + if (!isFile(filePath)) { log('No chain config file provided'); return {}; } else { diff --git a/typescript/cli/src/deploy/warp.ts b/typescript/cli/src/deploy/warp.ts index 317df98c06..d44b75e82b 100644 --- a/typescript/cli/src/deploy/warp.ts +++ b/typescript/cli/src/deploy/warp.ts @@ -28,6 +28,7 @@ import { getMergedContractAddresses, } from '../context.js'; import { + isFile, prepNewArtifactsFiles, runFileSelectionStep, writeJson, @@ -53,12 +54,14 @@ export async function runWarpDeploy({ }) { const { multiProvider, signer } = getContextWithSigner(key, chainConfigPath); - if (!warpConfigPath) { + if (!warpConfigPath || !isFile(warpConfigPath)) { warpConfigPath = await runFileSelectionStep( './configs', 'Warp config', 'warp', ); + } else { + log(`Using warp config at ${warpConfigPath}`); } const warpRouteConfig = readWarpRouteConfig(warpConfigPath); @@ -115,11 +118,6 @@ async function runBuildConfigStep({ const mergedContractAddrs = getMergedContractAddresses(artifacts); - logGray( - 'Contract addresses from artifacts:\n', - JSON.stringify(mergedContractAddrs[baseChainName], null, 4), - ); - // Create configs that coalesce together values from the config file, // the artifacts, and the SDK as a fallback const configMap: ChainMap = { @@ -130,12 +128,12 @@ async function runBuildConfigStep({ ? base.address! : ethers.constants.AddressZero, owner, - mailbox: base.mailbox || mergedContractAddrs[baseChainName].mailbox, + mailbox: base.mailbox || mergedContractAddrs[baseChainName]?.mailbox, interchainSecurityModule: base.interchainSecurityModule || - mergedContractAddrs[baseChainName].interchainSecurityModule || - mergedContractAddrs[baseChainName].multisigIsm, - // ismFactory: mergedContractAddrs[baseChainName].routingIsmFactory, // fix when updating from routingIsm + mergedContractAddrs[baseChainName]?.interchainSecurityModule || + mergedContractAddrs[baseChainName]?.multisigIsm, + // ismFactory: mergedContractAddrs[baseChainName].routingIsmFactory, // TODO fix when updating from routingIsm foreignDeployment: base.foreignDeployment, name: baseMetadata.name, symbol: baseMetadata.symbol, @@ -154,9 +152,9 @@ async function runBuildConfigStep({ mailbox: synthetic.mailbox || mergedContractAddrs[sChainName].mailbox, interchainSecurityModule: synthetic.interchainSecurityModule || - mergedContractAddrs[sChainName].interchainSecurityModule || - mergedContractAddrs[sChainName].multisigIsm, - // ismFactory: mergedContractAddrs[sChainName].routingIsmFactory, // fix + mergedContractAddrs[sChainName]?.interchainSecurityModule || + mergedContractAddrs[sChainName]?.multisigIsm, + // ismFactory: mergedContractAddrs[sChainName].routingIsmFactory, // TODO fix foreignDeployment: synthetic.foreignDeployment, }; } diff --git a/typescript/cli/src/utils/files.ts b/typescript/cli/src/utils/files.ts index 7d57dec276..aa0cfd65f5 100644 --- a/typescript/cli/src/utils/files.ts +++ b/typescript/cli/src/utils/files.ts @@ -6,14 +6,24 @@ import { parse as yamlParse, stringify as yamlStringify } from 'yaml'; import { objMerge } from '@hyperlane-xyz/utils'; -import { logBlue } from '../../logger.js'; +import { log, logBlue } from '../../logger.js'; import { getTimestampForFilename } from './time.js'; export type FileFormat = 'yaml' | 'json'; +export function isFile(filepath: string) { + if (!filepath) return false; + try { + return fs.existsSync(filepath) && fs.lstatSync(filepath).isFile(); + } catch (error) { + log(`Error checking for file: ${filepath}`); + return false; + } +} + export function readFileAtPath(filepath: string) { - if (!fs.existsSync(filepath)) { + if (!isFile(filepath)) { throw Error(`File doesn't exist at ${filepath}`); } return fs.readFileSync(filepath, 'utf8'); @@ -21,7 +31,7 @@ export function readFileAtPath(filepath: string) { export function writeFileAtPath(filepath: string, value: string) { const dirname = path.dirname(filepath); - if (!fs.existsSync(dirname)) { + if (!isFile(dirname)) { fs.mkdirSync(dirname, { recursive: true }); } fs.writeFileSync(filepath, value); @@ -47,7 +57,7 @@ export function mergeJson>( filepath: string, obj: T, ) { - if (fs.existsSync(filepath)) { + if (isFile(filepath)) { const previous = readJson(filepath); writeJson(filepath, objMerge(previous, obj)); } else { @@ -75,7 +85,7 @@ export function mergeYaml>( filepath: string, obj: T, ) { - if (fs.existsSync(filepath)) { + if (isFile(filepath)) { const previous = readYaml(filepath); writeYaml(filepath, objMerge(previous, obj)); } else {