1
1
import { extendConfig , task } from 'hardhat/config' ;
2
2
import {
3
+ TASK_COMPILE_SOLIDITY ,
3
4
TASK_COMPILE_SOLIDITY_COMPILE ,
4
5
TASK_COMPILE_SOLIDITY_COMPILE_JOB ,
5
6
TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT ,
6
7
TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS ,
7
8
TASK_CLEAN ,
8
9
} from 'hardhat/builtin-tasks/task-names' ;
9
- import type { CompilationJob , CompilerInput , CompilerOutput , HardhatConfig , SolcBuild } from 'hardhat/types' ;
10
+ import type { CompilationJob , CompilerInput , CompilerOutput , HardhatConfig , HardhatRuntimeEnvironment , SolcBuild } from 'hardhat/types' ;
10
11
11
12
import type { } from './type-extensions' ;
12
13
@@ -22,10 +23,14 @@ extendConfig((config, { exposed: userConfig }) => {
22
23
23
24
task ( TASK_CLEAN , async ( opts : { global : boolean } , hre , superCall ) => {
24
25
if ( ! opts . global ) {
25
- const fs = await import ( 'fs/promises' ) ;
26
- const { getExposedPath } = await import ( './core' ) ;
27
- const exposedPath = getExposedPath ( hre . config ) ;
28
- await fs . rm ( exposedPath , { recursive : true , force : true } ) ;
26
+ await cleanExposed ( hre ) ;
27
+ }
28
+ return superCall ( ) ;
29
+ } ) ;
30
+
31
+ task ( TASK_COMPILE_SOLIDITY , async ( { force } : { force : boolean } , hre , superCall ) => {
32
+ if ( force ) {
33
+ await cleanExposed ( hre ) ;
29
34
}
30
35
return superCall ( ) ;
31
36
} ) ;
@@ -73,16 +78,15 @@ task<CompileJobArgs>(TASK_COMPILE_SOLIDITY_COMPILE_JOB, async (args, hre, superC
73
78
} ) ;
74
79
75
80
if ( ! output . errors ?. some ( e => e . severity === 'error' ) ) {
76
- const exposedJob = await getExposedJob ( compilationJob , output ) ;
81
+ const exposedJob = await getExposedJob ( hre , compilationJob , output ) ;
77
82
await writeExposed ( exposedJob ) ;
78
83
compilationJob = compilationJob . merge ( exposedJob ) ;
79
84
}
80
85
81
86
return superCall ( { ...args , compilationJob } ) ;
82
87
} ) ;
83
88
84
- async function getExposedJob ( compilationJob : CompilationJob , output : CompilerOutput ) : Promise < CompilationJob > {
85
- const hre = await import ( 'hardhat' ) ;
89
+ async function getExposedJob ( hre : HardhatRuntimeEnvironment , compilationJob : CompilationJob , output : CompilerOutput ) : Promise < CompilationJob > {
86
90
const { getExposed } = await import ( './core' ) ;
87
91
88
92
const inputFiles = Object . fromEntries ( compilationJob . getResolvedFiles ( ) . map ( rf => [ rf . sourceName , rf . absolutePath ] ) ) ;
@@ -111,6 +115,14 @@ async function writeExposed(exposedJob: CompilationJob) {
111
115
}
112
116
}
113
117
118
+ async function cleanExposed ( hre : HardhatRuntimeEnvironment ) {
119
+ const fs = await import ( 'fs/promises' ) ;
120
+ const { getExposedPath } = await import ( './core' ) ;
121
+
122
+ const exposedPath = getExposedPath ( hre . config ) ;
123
+ await fs . rm ( exposedPath , { recursive : true , force : true } ) ;
124
+ }
125
+
114
126
async function getMatcher ( config : HardhatConfig ) {
115
127
const { isMatch } = await import ( 'micromatch' ) ;
116
128
const path = await import ( 'path' ) ;
0 commit comments