This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add multi-target Typechain typings build option (#127)
Signed-off-by: Jawad Tariq <[email protected]>
- Loading branch information
Showing
17 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { task } from 'hardhat/config' | ||
|
||
enum SupportedTypechainTargets { | ||
'ethers-v5' = 'ethers-v5', | ||
'ethers-v6' = 'ethers-v6', | ||
'truffle-v4' = 'truffle-v4', | ||
'truffle-v5' = 'truffle-v5', | ||
'web3-v1' = 'web3-v1', | ||
} | ||
|
||
/** | ||
* This task overrides the original compile task to allow for setting the Typechain target | ||
* via several methods: | ||
* 1. Command line argument: `npx hardhat compile --typechain ethers-v5` | ||
* 2. Environment variable: `TYPECHAIN_TARGET=ethers-v5 npx hardhat compile` | ||
* 3. Hardhat config: `const config: HardhatUserConfig = { typechain: { target: 'ethers-v5' } }` | ||
* @param args.typechainTarget (optional) The Typechain target to build for | ||
*/ | ||
task( | ||
'compile', | ||
'Compiles the entire project, building all artifacts and custom Typechain typings' | ||
) | ||
.addOptionalParam('typechainTarget', 'The Typechain target to build for') | ||
.setAction(async (args, hre, runSuper) => { | ||
const typechainTarget = | ||
args.typechainTarget || | ||
process.env.TYPECHAIN_TARGET || | ||
hre.config.typechain.target // default 'ethers-v6' | ||
|
||
// Validate the Typechain target | ||
if (!Object.values(SupportedTypechainTargets).includes(typechainTarget)) { | ||
throw new Error(`Unsupported typechain target: ${typechainTarget}`) | ||
} | ||
// Override the Typechain target | ||
hre.config.typechain.target = typechainTarget | ||
hre.config.typechain.outDir = `typechain-types/${typechainTarget}` | ||
|
||
// Call the original compile task | ||
if (runSuper.isDefined) { | ||
await runSuper(args) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters