diff --git a/.changeset/poor-carrots-walk.md b/.changeset/poor-carrots-walk.md new file mode 100644 index 0000000000000..a79494f47e3e5 --- /dev/null +++ b/.changeset/poor-carrots-walk.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/hardhat-deploy-config': patch +--- + +Add getter for other network's deploy config diff --git a/packages/hardhat-deploy-config/src/plugin.ts b/packages/hardhat-deploy-config/src/plugin.ts index 12058b51cd895..150bd2458a67e 100644 --- a/packages/hardhat-deploy-config/src/plugin.ts +++ b/packages/hardhat-deploy-config/src/plugin.ts @@ -27,32 +27,42 @@ const normalizePath = ( } export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => { - let config: any - try { - const base = `${hre.config.paths.deployConfig}/${hre.network.name}` - if (fs.existsSync(`${base}.ts`)) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - config = require(`${base}.ts`).default - } else if (fs.existsSync(`${base}.json`)) { - // eslint-disable-next-line @typescript-eslint/no-var-requires - config = require(`${base}.json`) - } else { - throw new Error('not found') + const getDeployConfig = (dir: string, network: string): any => { + let config: any + try { + const base = `${dir}/${network}` + if (fs.existsSync(`${base}.ts`)) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + config = require(`${base}.ts`).default + } else if (fs.existsSync(`${base}.json`)) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + config = require(`${base}.json`) + } else { + throw new Error('not found') + } + } catch (err) { + throw new Error( + `error while loading deploy config for network: ${hre.network.name}, ${err}` + ) } - } catch (err) { - throw new Error( - `error while loading deploy config for network: ${hre.network.name}, ${err}` - ) + return config + } + + const paths = hre.config.paths.deployConfig + const conf = getDeployConfig(paths, hre.network.name) + const spec = parseDeployConfig(hre, conf) + + spec.getDeployConfig = (network: string) => { + return getDeployConfig(paths, network) } - return new Proxy(parseDeployConfig(hre, config), { + return new Proxy(spec, { get: (target, prop) => { if (target.hasOwnProperty(prop)) { return target[prop] } - // Explicitly throw if the property is not found since I can't yet figure out a good way to - // handle the necessary typings. + // Explicitly throw if the property is not found throw new Error( `property does not exist in deploy config: ${String(prop)}` ) diff --git a/packages/hardhat-deploy-config/src/type-extensions.ts b/packages/hardhat-deploy-config/src/type-extensions.ts index cbda129bdf4fd..aaa8935931608 100644 --- a/packages/hardhat-deploy-config/src/type-extensions.ts +++ b/packages/hardhat-deploy-config/src/type-extensions.ts @@ -24,8 +24,8 @@ declare module 'hardhat/types/config' { declare module 'hardhat/types/runtime' { interface HardhatRuntimeEnvironment { deployConfig: { - // TODO: Is there any good way to type this? [key: string]: any + getDeployConfig(arg0: string): { [key: string]: any } } } }