Skip to content

Commit de656c6

Browse files
krzkaczoralcuadrado
andauthoredJun 9, 2022
Add dontOverrideCompile setting and fix a bug (#714)
Co-authored-by: Patricio Palladino <email@patriciopalladino.com>
1 parent 015abb2 commit de656c6

File tree

13 files changed

+328
-111
lines changed

13 files changed

+328
-111
lines changed
 

Diff for: ‎.changeset/five-onions-notice.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@typechain/hardhat": patch
3+
---
4+
5+
Add `dontOverrideCompile` setting

Diff for: ‎examples/hardhat-truffe-v5/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"chai-as-promised": "^7.1.1",
2525
"chai-bn": "^0.2.1",
2626
"dotenv": "^8.2.0",
27-
"hardhat": "^2.0.10",
27+
"hardhat": "^2.9.9",
2828
"ts-generator": "0.0.8",
2929
"ts-node": "^10.7.0",
3030
"typechain": "workspace:^8.0.0",

Diff for: ‎examples/hardhat/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@ethersproject/providers": "5.4.0",
2828
"@ethersproject/contracts": "5.4.0",
2929
"@ethersproject/abi": "5.4.0",
30-
"hardhat": "^2.0.10",
30+
"hardhat": "^2.9.9",
3131
"ts-node": "^10.7.0",
3232
"typechain": "workspace:^8.0.0",
3333
"typescript": "^4.6"

Diff for: ‎packages/hardhat-test/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@typechain/ethers-v5": "workspace:^10.0.0",
2222
"@typechain/hardhat": "workspace:^6.0.0",
2323
"ethers": "^5.4.7",
24-
"hardhat": "^2.0.10",
24+
"hardhat": "^2.9.9",
2525
"test-utils": "1.0.0",
2626
"typechain": "workspace:^8.0.0"
2727
}

Diff for: ‎packages/hardhat/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ module.exports = {
104104
target: 'ethers-v5',
105105
alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
106106
externalArtifacts: ['externalArtifacts/*.json'], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules)
107+
dontOverrideCompile: false // defaults to true for javascript projects
107108
},
108109
}
109110
```

Diff for: ‎packages/hardhat/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@types/lodash": "^4.14.139",
4343
"@types/rimraf": "^3.0.0",
4444
"ethers": "^5.4.7",
45-
"hardhat": "^2.0.10",
45+
"hardhat": "^2.9.9",
4646
"rimraf": "^3.0.2",
4747
"typechain": "workspace:^8.0.0",
4848
"typescript": "^4"
@@ -52,7 +52,7 @@
5252
"@ethersproject/providers": "^5.4.7",
5353
"@typechain/ethers-v5": "workspace:^10.0.0",
5454
"ethers": "^5.4.7",
55-
"hardhat": "^2.0.10",
55+
"hardhat": "^2.9.9",
5656
"typechain": "workspace:^8.0.0"
5757
}
5858
}

Diff for: ‎packages/hardhat/src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function getDefaultTypechainConfig(config: HardhatConfig): TypechainConfi
99
alwaysGenerateOverloads: false,
1010
discriminateTypes: false,
1111
tsNocheck: false,
12+
dontOverrideCompile: config.paths.configFile.endsWith('.js'),
1213
}
1314

1415
return {

Diff for: ‎packages/hardhat/src/index.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ extendConfig((config) => {
1616
config.typechain = getDefaultTypechainConfig(config)
1717
})
1818

19-
task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
19+
task(TASK_COMPILE)
2020
.addFlag('noTypechain', 'Skip Typechain compilation')
21-
.setAction(async ({ noTypechain }: { global: boolean; noTypechain: boolean }, _, runSuper) => {
21+
.setAction(async ({ noTypechain }: { global: boolean; noTypechain: boolean }, { config }, runSuper) => {
2222
// just save task arguments for later b/c there is no easier way to access them in subtask
23-
taskArgsStore.noTypechain = noTypechain!!
23+
taskArgsStore.noTypechain = noTypechain!! || config.typechain.dontOverrideCompile
2424

2525
await runSuper()
2626
})
@@ -37,9 +37,7 @@ subtask(TASK_TYPECHAIN_GENERATE_TYPES)
3737
.addParam('compileSolOutput', 'Solidity compilation output', {}, types.any)
3838
.setAction(async ({ compileSolOutput }, { config, artifacts }) => {
3939
const artifactFQNs: string[] = getFQNamesFromCompilationOutput(compileSolOutput)
40-
const artifactPaths = uniq(
41-
artifactFQNs.map((fqn) => (artifacts as any)._getArtifactPathFromFullyQualifiedName(fqn)),
42-
)
40+
const artifactPaths = uniq(artifactFQNs.map((fqn) => artifacts.formArtifactPathFromFullyQualifiedName(fqn)))
4341

4442
if (taskArgsStore.noTypechain) {
4543
return compileSolOutput
@@ -107,7 +105,7 @@ task(
107105
'Clears the cache and deletes all artifacts',
108106
async ({ global }: { global: boolean }, { config }, runSuper) => {
109107
if (global) {
110-
return
108+
return runSuper()
111109
}
112110

113111
if (await fsExtra.pathExists(config.typechain.outDir)) {

Diff for: ‎packages/hardhat/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface TypechainConfig {
55
discriminateTypes: boolean
66
tsNocheck: boolean
77
externalArtifacts?: string[]
8+
dontOverrideCompile: boolean
89
}
910

1011
export interface TypechainUserConfig extends Partial<TypechainConfig> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pragma solidity ^0.7.3;
2+
3+
contract C {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// We load the plugin here.
2+
import '../../../src/index'
3+
4+
import { HardhatUserConfig } from 'hardhat/types'
5+
6+
const config: HardhatUserConfig = {
7+
solidity: '0.7.3',
8+
defaultNetwork: 'hardhat',
9+
typechain: {
10+
dontOverrideCompile: true,
11+
},
12+
}
13+
14+
export default config

Diff for: ‎packages/hardhat/test/project.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,30 @@ describe('Typechain x Hardhat', function () {
131131
})
132132
})
133133

134+
describe('dontOverrideCompile', function () {
135+
useEnvironment('no-override-project')
136+
let originalCwd: typeof process.cwd
137+
138+
beforeEach(async function () {
139+
originalCwd = process.cwd
140+
await this.hre.run('clean')
141+
})
142+
143+
this.afterEach(() => {
144+
process.cwd = originalCwd
145+
})
146+
147+
it('should desible typechain for the compile task', async function () {
148+
const exists = existsSync(this.hre.config.typechain.outDir)
149+
expect(exists).toEqual(false)
150+
151+
await this.hre.run('compile')
152+
153+
const existsAfter = existsSync(this.hre.config.typechain.outDir)
154+
expect(existsAfter).toEqual(false)
155+
})
156+
})
157+
134158
const contractDir = join(__dirname, 'fixture-projects/hardhat-project/contracts')
135159
const fixtureFilesDir = join(__dirname, 'fixture-files')
136160
const TestContract2OriginPath = join(fixtureFilesDir, 'TestContract2.sol')

Diff for: ‎pnpm-lock.yaml

+268-99
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.