Commit 5cf646ba authored by Mark Tyneway's avatar Mark Tyneway

hardhat-deploy-config: add getter

Add a getter to the `hre.deployConfig` object
that gives access to alternative network's deploy
configs. This is useful because multiple networks
can be linked and share config. In particular when
L2 networks are used with L1 networks, the entire
deploy config has be be shared with both networks
so it results in a copy paste.
parent 43b70f43
---
'@eth-optimism/hardhat-deploy-config': patch
---
Add getter for other network's deploy config
......@@ -27,9 +27,10 @@ const normalizePath = (
}
export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
const getDeployConfig = (dir: string, network: string): any => {
let config: any
try {
const base = `${hre.config.paths.deployConfig}/${hre.network.name}`
const base = `${dir}/${network}`
if (fs.existsSync(`${base}.ts`)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
config = require(`${base}.ts`).default
......@@ -44,15 +45,24 @@ export const loadDeployConfig = (hre: HardhatRuntimeEnvironment): any => {
`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)}`
)
......
......@@ -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 }
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment