Skip to content

Commit 0271b80

Browse files
committed
refactor: apply isolated declarations across v-next
Turn on the isolated declarations flag for the typescript compiler.
1 parent 4ed8298 commit 0271b80

File tree

47 files changed

+217
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+217
-99
lines changed

config-v-next/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"declarationMap": true,
66
"forceConsistentCasingInFileNames": true,
77
"isolatedModules": true,
8+
"isolatedDeclarations": true,
89
"noEmitOnError": true,
910
"noImplicitOverride": true,
1011
"skipDefaultLibCheck": true,

v-next/core/src/internal/parameters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ParameterType } from "../types/common.js";
77
/**
88
* Names that can't be used as global- nor task-parameter names.
99
*/
10-
export const RESERVED_PARAMETER_NAMES = new Set([
10+
export const RESERVED_PARAMETER_NAMES: Set<string> = new Set([
1111
"config",
1212
"help",
1313
"showStackTraces",

v-next/core/test/internal/fixture-plugins/config-plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
HardhatUserConfigValidationError,
55
} from "../../../src/types/hooks.js";
66

7-
export default async () => {
7+
export default async (): Promise<Partial<ConfigHooks>> => {
88
const handlers: Partial<ConfigHooks> = {
99
validateUserConfig: async (
1010
_config: HardhatUserConfig,

v-next/core/test/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function createTestEnvManager() {
1818
});
1919

2020
return {
21-
setEnvVar(name: string, value: string) {
21+
setEnvVar(name: string, value: string): void {
2222
// Before setting a new value, save the original value if it hasn't been saved yet
2323
if (!changes.has(name)) {
2424
originalValues.set(name, process.env[name]);

v-next/example-project/hardhat.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const greeting = task("hello", "Prints a greeting")
9595
})
9696
.build();
9797

98-
export default {
98+
const config: HardhatUserConfig = {
9999
tasks: [
100100
exampleTaskOverride,
101101
testTask,
@@ -130,4 +130,6 @@ export default {
130130
},
131131
],
132132
privateKey: configVariable("privateKey"),
133-
} satisfies HardhatUserConfig;
133+
};
134+
135+
export default config;

v-next/hardhat-build-system/src/internal/build-system.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
Artifacts,
44
CompilationJobCreationError,
55
BuildConfig,
6+
DependencyGraph,
67
} from "./types/index.js";
78

89
import {
@@ -71,7 +72,7 @@ export class BuildSystem {
7172
// TODO: TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS_FAILURE_REASONS - naming? Do we want to keep it?
7273
public async solidityGetCompilationJobsFailureReasons(
7374
errors: CompilationJobCreationError[],
74-
) {
75+
): Promise<string> {
7576
return taskCompileSolidityGetCompilationJobsFailureReasons(errors);
7677
}
7778

@@ -80,7 +81,7 @@ export class BuildSystem {
8081
public async solidityGetDependencyGraph(
8182
sourceNames: string[],
8283
config: BuildConfig,
83-
) {
84+
): Promise<DependencyGraph> {
8485
return taskCompileSolidityGetDependencyGraph(sourceNames, config);
8586
}
8687

v-next/hardhat-build-system/src/internal/builtin-tasks/utils/solidity-files-cache.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class SolidityFilesCache {
8484
this.#cache = _cache;
8585
}
8686

87-
public async removeNonExistingFiles() {
87+
public async removeNonExistingFiles(): Promise<void> {
8888
await Promise.all(
8989
Object.keys(this.#cache.files).map(async (absolutePath) => {
9090
if (!(await exists(absolutePath))) {
@@ -94,11 +94,11 @@ export class SolidityFilesCache {
9494
);
9595
}
9696

97-
public async writeToFile(solidityFilesCachePath: string) {
97+
public async writeToFile(solidityFilesCachePath: string): Promise<void> {
9898
await writeJsonFile(solidityFilesCachePath, this.#cache);
9999
}
100100

101-
public addFile(absolutePath: string, entry: CacheEntry) {
101+
public addFile(absolutePath: string, entry: CacheEntry): void {
102102
this.#cache.files[absolutePath] = entry;
103103
}
104104

@@ -110,7 +110,7 @@ export class SolidityFilesCache {
110110
return this.#cache.files[file];
111111
}
112112

113-
public removeEntry(file: string) {
113+
public removeEntry(file: string): void {
114114
delete this.#cache.files[file];
115115
}
116116

v-next/hardhat-build-system/src/internal/solidity/compilation-job.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class CompilationJob implements taskTypes.CompilationJob {
114114

115115
constructor(public solidityConfig: SolcConfig) {}
116116

117-
public addFileToCompile(file: ResolvedFile, emitsArtifacts: boolean) {
117+
public addFileToCompile(file: ResolvedFile, emitsArtifacts: boolean): void {
118118
const fileToCompile = this.#filesToCompile.get(file.sourceName);
119119

120120
// if the file doesn't exist, we add it
@@ -151,7 +151,7 @@ export class CompilationJob implements taskTypes.CompilationJob {
151151
return this.solidityConfig;
152152
}
153153

154-
public isEmpty() {
154+
public isEmpty(): boolean {
155155
return this.#filesToCompile.size === 0;
156156
}
157157

v-next/hardhat-build-system/src/internal/solidity/compiler/downloader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class CompilerDownloader implements ICompilerDownloader {
152152
constructor(
153153
_platform: CompilerPlatform,
154154
_compilersDir: string,
155-
_compilerListCachePeriodMs = CompilerDownloader.defaultCompilerListCachePeriod,
155+
_compilerListCachePeriodMs: number = CompilerDownloader.defaultCompilerListCachePeriod,
156156
_downloadFunction: typeof download = download,
157157
) {
158158
this.#platform = _platform;

v-next/hardhat-build-system/src/internal/solidity/compiler/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Compiler implements ICompiler {
2424
this.#pathToSolcJs = pathToSolcJs;
2525
}
2626

27-
public async compile(input: CompilerInput) {
27+
public async compile(input: CompilerInput): Promise<any> {
2828
const scriptPath = fileURLToPath(import.meta.resolve("./solcjs-runner.js"));
2929

3030
// If the script is a TypeScript file, we need to pass the --import tsx/esm
@@ -79,7 +79,7 @@ export class NativeCompiler implements ICompiler {
7979
this.#solcVersion = _solcVersion;
8080
}
8181

82-
public async compile(input: CompilerInput) {
82+
public async compile(input: CompilerInput): Promise<any> {
8383
const args = ["--standard-json"];
8484

8585
// Logic to make sure that solc default import callback is not being used.

v-next/hardhat-build-system/src/internal/solidity/resolver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ResolvedFile implements IResolvedFile {
5656
}
5757
}
5858

59-
public getVersionedName() {
59+
public getVersionedName(): string {
6060
return (
6161
this.sourceName +
6262
(this.library !== undefined ? `@v${this.library.version}` : "")

v-next/hardhat-build-system/src/internal/tasks.ts

+30-14
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ export async function taskCompileSolidityGetCompilationJobs(
173173
config: BuildConfig,
174174
dependencyGraph: taskTypes.DependencyGraph,
175175
solidityFilesCache?: SolidityFilesCache,
176-
) {
176+
): Promise<{
177+
jobs: taskTypes.CompilationJob[];
178+
errors: taskTypes.CompilationJobCreationError[];
179+
}> {
177180
const connectedComponents = dependencyGraph.getConnectedComponents();
178181

179182
log(
@@ -217,7 +220,7 @@ export async function taskCompileSolidityGetCompilationJobs(
217220
*/
218221
export async function taskCompileSolidityHandleCompilationJobsFailures(
219222
compilationJobsCreationErrors: CompilationJobCreationError[],
220-
) {
223+
): Promise<void> {
221224
const hasErrors = compilationJobsCreationErrors.length > 0;
222225

223226
if (hasErrors) {
@@ -535,7 +538,9 @@ export async function taskCompileSolidityMergeCompilationJobs(
535538
/**
536539
* Prints a message when there's nothing to compile.
537540
*/
538-
export async function taskCompileSolidityLogNothingToCompile(quiet: boolean) {
541+
export async function taskCompileSolidityLogNothingToCompile(
542+
quiet: boolean,
543+
): Promise<void> {
539544
if (!quiet) {
540545
console.log("Nothing to compile");
541546
}
@@ -547,7 +552,7 @@ export async function taskCompileSolidityLogDownloadCompilerStart(
547552
solcVersion: string,
548553
isCompilerDownloaded: boolean,
549554
_quiet: boolean, // TODO: keep unused?
550-
) {
555+
): Promise<void> {
551556
if (isCompilerDownloaded) {
552557
return;
553558
}
@@ -560,7 +565,7 @@ export async function taskCompileSolidityLogDownloadCompilerEnd(
560565
_solcVersion: string, // TODO: keep unused?
561566
_isCompilerDownloaded: boolean, // TODO: keep unused?
562567
_quiet: boolean, // TODO: keep unused?
563-
) {
568+
): Promise<void> {
564569
return;
565570
}
566571

@@ -658,7 +663,7 @@ export async function taskCompileSolidityLogRunCompilerStart(
658663
_compilationJobs: CompilationJob[], // TODO: keep unused?
659664
_compilationJobIndex: number, // TODO: keep unused?
660665
_quiet: boolean, // TODO: keep unused?
661-
) {
666+
): Promise<void> {
662667
return;
663668
}
664669

@@ -715,7 +720,7 @@ export async function taskCompileSolidityLogRunCompilerEnd(
715720
_compilationJobIndex: number, // TODO: keep unused?
716721
_output: any, // TODO: keep unused?
717722
_quiet: boolean, // TODO: keep unused?
718-
) {
723+
): Promise<void> {
719724
return;
720725
}
721726

@@ -784,7 +789,10 @@ export async function taskCompileSolidityCompile(
784789
compilationJob: CompilationJob,
785790
compilationJobs: CompilationJob[],
786791
compilationJobIndex: number,
787-
) {
792+
): Promise<{
793+
output: CompilerOutput;
794+
solcBuild: taskTypes.SolcBuild;
795+
}> {
788796
return taskCompileSolidityCompileSolc(
789797
input,
790798
quiet,
@@ -804,7 +812,7 @@ export async function taskCompileSolidityCompile(
804812
export async function taskCompileSolidityLogCompilationErrors(
805813
output: any,
806814
_quiet: boolean, // TODO: keep unused?
807-
) {
815+
): Promise<void> {
808816
if (output?.errors === undefined) {
809817
return;
810818
}
@@ -882,7 +890,7 @@ function isConsoleLogError(error: any): boolean {
882890
export async function taskCompileSolidityCheckErrors(
883891
output: any,
884892
quiet: boolean,
885-
) {
893+
): Promise<void> {
886894
await taskCompileSolidityLogCompilationErrors(output, quiet);
887895

888896
if (hasCompilationErrors(output)) {
@@ -1000,7 +1008,13 @@ export async function taskCompileSolidityCompileJob(
10001008
quiet: boolean,
10011009
emitsArtifacts: boolean,
10021010
artifacts: Artifacts,
1003-
) {
1011+
): Promise<{
1012+
artifactsEmittedPerFile: taskTypes.ArtifactsEmittedPerFile;
1013+
compilationJob: taskTypes.CompilationJob;
1014+
input: CompilerInput;
1015+
output: CompilerOutput;
1016+
solcBuild: taskTypes.SolcBuild;
1017+
}> {
10041018
log(`Compiling job with version '${compilationJob.getSolcConfig().version}'`);
10051019
const input: CompilerInput =
10061020
await taskCompileSolidityGetCompilerInput(compilationJob);
@@ -1125,7 +1139,7 @@ export async function taskCompileSolidityCompileJobs(
11251139
export async function taskCompileSolidityLogCompilationResult(
11261140
compilationJobs: CompilationJob[],
11271141
_quiet?: boolean, // TODO: keep unused?
1128-
) {
1142+
): Promise<void> {
11291143
let count = 0;
11301144
const evmVersions = new Set<string>();
11311145
const unknownEvmVersions = new Set<string>();
@@ -1170,7 +1184,9 @@ export async function taskCompileSolidityLogCompilationResult(
11701184

11711185
// TASK_COMPILE_REMOVE_OBSOLETE_ARTIFACTS
11721186
// TESTED
1173-
export async function taskCompileRemoveObsoleteArtifacts(artifacts: Artifacts) {
1187+
export async function taskCompileRemoveObsoleteArtifacts(
1188+
artifacts: Artifacts,
1189+
): Promise<void> {
11741190
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
11751191
We know this is the actual implementation, so we use some non-public methods
11761192
here by downcasting */
@@ -1244,7 +1260,7 @@ export async function taskCompileSolidity(
12441260
quiet: boolean,
12451261
concurrency: number,
12461262
tasksOverrides: TasksOverrides | undefined,
1247-
) {
1263+
): Promise<void> {
12481264
const rootPath = config.paths.root;
12491265

12501266
const sourcePaths: string[] = await taskCompileSolidityGetSourcePaths(

v-next/hardhat-build-system/src/internal/utils/artifacts.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class Artifacts implements IArtifacts {
7676

7777
public addValidArtifacts(
7878
validArtifacts: Array<{ sourceName: string; artifacts: string[] }>,
79-
) {
79+
): void {
8080
this.#validArtifacts.push(...validArtifacts);
8181
}
8282

@@ -193,7 +193,7 @@ export class Artifacts implements IArtifacts {
193193
public async saveArtifactAndDebugFile(
194194
artifact: Artifact,
195195
pathToBuildInfo?: string,
196-
) {
196+
): Promise<void> {
197197
try {
198198
// artifact
199199
const fullyQualifiedName = getFullyQualifiedName(
@@ -347,7 +347,7 @@ export class Artifacts implements IArtifacts {
347347
/**
348348
* Remove all artifacts that don't correspond to the current solidity files
349349
*/
350-
public async removeObsoleteArtifacts() {
350+
public async removeObsoleteArtifacts(): Promise<void> {
351351
// We clear the cache here, as we want to be sure this runs correctly
352352
this.clearCache();
353353

@@ -402,7 +402,7 @@ export class Artifacts implements IArtifacts {
402402
return path.join(this.#artifactsPath, sourceName, `${contractName}.json`);
403403
}
404404

405-
public clearCache() {
405+
public clearCache(): void {
406406
// Avoid accidentally re-enabling the cache
407407
if (this.#cache === undefined) {
408408
return;
@@ -414,7 +414,7 @@ export class Artifacts implements IArtifacts {
414414
};
415415
}
416416

417-
public disableCache() {
417+
public disableCache(): void {
418418
this.#cache = undefined;
419419
}
420420

v-next/hardhat-build-system/src/internal/utils/download.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function resolveTempFileName(filePath: string): string {
2222
});
2323
}
2424

25-
export async function download(url: string, filePath: string) {
25+
export async function download(url: string, filePath: string): Promise<void> {
2626
const dispatcherOptions: DispatcherOptions = {};
2727
if (process.env.proxy !== undefined && shouldUseProxy(url)) {
2828
dispatcherOptions.proxy = process.env.proxy;

v-next/hardhat-build-system/src/internal/utils/global-dir.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from "node:path";
22

33
import { ensureDir } from "@ignored/hardhat-vnext-utils/fs";
44

5-
export async function getCompilersDir() {
5+
export async function getCompilersDir(): Promise<string> {
66
const cache = await getCacheDir();
77
// Note: we introduce `-v2` to invalidate all the previous compilers at once
88
const compilersCache = path.join(cache, "compilers-v2");

v-next/hardhat-build-system/src/internal/utils/source-names.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export async function isLocalSourceName(
171171
export async function validateSourceNameExistenceAndCasing(
172172
fromDir: string,
173173
sourceName: string,
174-
) {
174+
): Promise<void> {
175175
const trueCaseSourceName = await getSourceNameTrueCase(fromDir, sourceName);
176176

177177
if (trueCaseSourceName !== sourceName) {
@@ -188,7 +188,7 @@ export async function validateSourceNameExistenceAndCasing(
188188
* It throws if the format is invalid.
189189
* If it doesn't throw all you know is that the format is valid.
190190
*/
191-
export function validateSourceNameFormat(sourceName: string) {
191+
export function validateSourceNameFormat(sourceName: string): void {
192192
if (isAbsolutePathSourceName(sourceName)) {
193193
throw new HardhatError(
194194
HardhatError.ERRORS.SOURCE_NAMES.INVALID_SOURCE_NAME_ABSOLUTE_PATH,

0 commit comments

Comments
 (0)