Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-carrots-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/hardhat-deploy-config': patch
---

Add getter for other network's deploy config
46 changes: 28 additions & 18 deletions packages/hardhat-deploy-config/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-deploy-config/src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
}