Skip to content

Commit 6866cc5

Browse files
committed
clean exposed on compile --force
1 parent e2aaf00 commit 6866cc5

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.3.12
4+
5+
- Clean exposed files on `hardhat compile --force`.
6+
37
## 0.3.11
48

59
- Fix error with types defined inside libraries.

src/plugin.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { extendConfig, task } from 'hardhat/config';
22
import {
3+
TASK_COMPILE_SOLIDITY,
34
TASK_COMPILE_SOLIDITY_COMPILE,
45
TASK_COMPILE_SOLIDITY_COMPILE_JOB,
56
TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT,
67
TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS,
78
TASK_CLEAN,
89
} 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';
1011

1112
import type {} from './type-extensions';
1213

@@ -22,10 +23,14 @@ extendConfig((config, { exposed: userConfig }) => {
2223

2324
task(TASK_CLEAN, async (opts: { global: boolean }, hre, superCall) => {
2425
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);
2934
}
3035
return superCall();
3136
});
@@ -73,16 +78,15 @@ task<CompileJobArgs>(TASK_COMPILE_SOLIDITY_COMPILE_JOB, async (args, hre, superC
7378
});
7479

7580
if (!output.errors?.some(e => e.severity === 'error')) {
76-
const exposedJob = await getExposedJob(compilationJob, output);
81+
const exposedJob = await getExposedJob(hre, compilationJob, output);
7782
await writeExposed(exposedJob);
7883
compilationJob = compilationJob.merge(exposedJob);
7984
}
8085

8186
return superCall({ ...args, compilationJob });
8287
});
8388

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> {
8690
const { getExposed } = await import('./core');
8791

8892
const inputFiles = Object.fromEntries(compilationJob.getResolvedFiles().map(rf => [rf.sourceName, rf.absolutePath]));
@@ -111,6 +115,14 @@ async function writeExposed(exposedJob: CompilationJob) {
111115
}
112116
}
113117

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+
114126
async function getMatcher(config: HardhatConfig) {
115127
const { isMatch } = await import('micromatch');
116128
const path = await import('path');

0 commit comments

Comments
 (0)