@@ -2,13 +2,21 @@ require("dotenv").config();
2
2
require ( "hardhat-contract-sizer" ) ;
3
3
4
4
import chalk from "chalk" ;
5
- import { HardhatUserConfig } from "hardhat/config" ;
5
+ import { HardhatUserConfig , task } from "hardhat/config" ;
6
6
import { privateKeys } from "./utils/wallets" ;
7
7
8
8
import "@nomiclabs/hardhat-waffle" ;
9
9
import "@typechain/hardhat" ;
10
10
import "solidity-coverage" ;
11
11
import "hardhat-deploy" ;
12
+ import {
13
+ TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE ,
14
+ TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH ,
15
+ TASK_COMPILE_SOLIDITY_COMPILE_JOB ,
16
+ } from "hardhat/builtin-tasks/task-names" ;
17
+
18
+ import type { DependencyGraph , CompilationJob } from "hardhat/types/builtin-tasks" ;
19
+
12
20
import "./tasks" ;
13
21
14
22
const forkingConfig = {
@@ -104,15 +112,87 @@ function getHardhatPrivateKeys() {
104
112
}
105
113
106
114
function checkForkedProviderEnvironment ( ) {
107
- if ( process . env . FORK &&
108
- ( ! process . env . ALCHEMY_TOKEN || process . env . ALCHEMY_TOKEN === "fake_alchemy_token" )
109
- ) {
110
- console . log ( chalk . red (
111
- "You are running forked provider tests with invalid Alchemy credentials.\n" +
112
- "Update your ALCHEMY_TOKEN settings in the `.env` file."
113
- ) ) ;
115
+ if (
116
+ process . env . FORK &&
117
+ ( ! process . env . ALCHEMY_TOKEN || process . env . ALCHEMY_TOKEN === "fake_alchemy_token" )
118
+ ) {
119
+ console . log (
120
+ chalk . red (
121
+ "You are running forked provider tests with invalid Alchemy credentials.\n" +
122
+ "Update your ALCHEMY_TOKEN settings in the `.env` file." ,
123
+ ) ,
124
+ ) ;
114
125
process . exit ( 1 ) ;
115
126
}
116
127
}
117
128
129
+ task ( "index:compile:one" , "Compiles a single contract in isolation" )
130
+ . addPositionalParam ( "contractName" )
131
+ . setAction ( async function ( args , env ) {
132
+ const sourceName = env . artifacts . readArtifactSync ( args . contractName ) . sourceName ;
133
+
134
+ const dependencyGraph : DependencyGraph = await env . run (
135
+ TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH ,
136
+ { sourceNames : [ sourceName ] } ,
137
+ ) ;
138
+
139
+ const resolvedFiles = dependencyGraph . getResolvedFiles ( ) . filter ( resolvedFile => {
140
+ return resolvedFile . sourceName === sourceName ;
141
+ } ) ;
142
+
143
+ const compilationJob : CompilationJob = await env . run (
144
+ TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE ,
145
+ {
146
+ dependencyGraph,
147
+ file : resolvedFiles [ 0 ] ,
148
+ } ,
149
+ ) ;
150
+
151
+ await env . run ( TASK_COMPILE_SOLIDITY_COMPILE_JOB , {
152
+ compilationJob,
153
+ compilationJobs : [ compilationJob ] ,
154
+ compilationJobIndex : 0 ,
155
+ emitsArtifacts : true ,
156
+ quiet : true ,
157
+ } ) ;
158
+
159
+ await env . run ( "typechain" ) ;
160
+ } ) ;
161
+
162
+ task ( "index:compile:all" , "Compiles all contracts in isolation" ) . setAction ( async function (
163
+ _args ,
164
+ env ,
165
+ ) {
166
+ const allArtifacts = await env . artifacts . getAllFullyQualifiedNames ( ) ;
167
+ for ( const contractName of allArtifacts ) {
168
+ const sourceName = env . artifacts . readArtifactSync ( contractName ) . sourceName ;
169
+
170
+ const dependencyGraph : DependencyGraph = await env . run (
171
+ TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH ,
172
+ {
173
+ sourceNames : [ sourceName ] ,
174
+ } ,
175
+ ) ;
176
+
177
+ const resolvedFiles = dependencyGraph . getResolvedFiles ( ) . filter ( resolvedFile => {
178
+ return resolvedFile . sourceName === sourceName ;
179
+ } ) ;
180
+
181
+ const compilationJob : CompilationJob = await env . run (
182
+ TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE ,
183
+ {
184
+ dependencyGraph,
185
+ file : resolvedFiles [ 0 ] ,
186
+ } ,
187
+ ) ;
188
+
189
+ await env . run ( TASK_COMPILE_SOLIDITY_COMPILE_JOB , {
190
+ compilationJob,
191
+ compilationJobs : [ compilationJob ] ,
192
+ compilationJobIndex : 0 ,
193
+ emitsArtifacts : true ,
194
+ quiet : true ,
195
+ } ) ;
196
+ }
197
+ } ) ;
118
198
export default config ;
0 commit comments