Skip to content

Commit 8df6839

Browse files
committed
refactor: apply isolated declarations across v-next
Turn on the isolated declarations flag for the typescript compiler.
1 parent 08c5b8e commit 8df6839

File tree

48 files changed

+224
-101
lines changed

Some content is hidden

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

48 files changed

+224
-101
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
@@ -1,6 +1,6 @@
11
import { task, HardhatUserConfig } from "@ignored/hardhat-vnext/config";
22

3-
export default {
3+
const config: HardhatUserConfig = {
44
tasks: [
55
task("hello", "Prints a greeting")
66
.addOption({
@@ -13,4 +13,6 @@ export default {
1313
})
1414
.build(),
1515
],
16-
} satisfies HardhatUserConfig;
16+
};
17+
18+
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
@@ -174,7 +174,10 @@ export async function taskCompileSolidityGetCompilationJobs(
174174
config: BuildConfig,
175175
dependencyGraph: taskTypes.DependencyGraph,
176176
solidityFilesCache?: SolidityFilesCache,
177-
) {
177+
): Promise<{
178+
jobs: taskTypes.CompilationJob[];
179+
errors: taskTypes.CompilationJobCreationError[];
180+
}> {
178181
const connectedComponents = dependencyGraph.getConnectedComponents();
179182

180183
log(
@@ -218,7 +221,7 @@ export async function taskCompileSolidityGetCompilationJobs(
218221
*/
219222
export async function taskCompileSolidityHandleCompilationJobsFailures(
220223
compilationJobsCreationErrors: CompilationJobCreationError[],
221-
) {
224+
): Promise<void> {
222225
const hasErrors = compilationJobsCreationErrors.length > 0;
223226

224227
if (hasErrors) {
@@ -536,7 +539,9 @@ export async function taskCompileSolidityMergeCompilationJobs(
536539
/**
537540
* Prints a message when there's nothing to compile.
538541
*/
539-
export async function taskCompileSolidityLogNothingToCompile(quiet: boolean) {
542+
export async function taskCompileSolidityLogNothingToCompile(
543+
quiet: boolean,
544+
): Promise<void> {
540545
if (!quiet) {
541546
console.log("Nothing to compile");
542547
}
@@ -548,7 +553,7 @@ export async function taskCompileSolidityLogDownloadCompilerStart(
548553
solcVersion: string,
549554
isCompilerDownloaded: boolean,
550555
_quiet: boolean, // TODO: keep unused?
551-
) {
556+
): Promise<void> {
552557
if (isCompilerDownloaded) {
553558
return;
554559
}
@@ -561,7 +566,7 @@ export async function taskCompileSolidityLogDownloadCompilerEnd(
561566
_solcVersion: string, // TODO: keep unused?
562567
_isCompilerDownloaded: boolean, // TODO: keep unused?
563568
_quiet: boolean, // TODO: keep unused?
564-
) {
569+
): Promise<void> {
565570
return;
566571
}
567572

@@ -659,7 +664,7 @@ export async function taskCompileSolidityLogRunCompilerStart(
659664
_compilationJobs: CompilationJob[], // TODO: keep unused?
660665
_compilationJobIndex: number, // TODO: keep unused?
661666
_quiet: boolean, // TODO: keep unused?
662-
) {
667+
): Promise<void> {
663668
return;
664669
}
665670

@@ -716,7 +721,7 @@ export async function taskCompileSolidityLogRunCompilerEnd(
716721
_compilationJobIndex: number, // TODO: keep unused?
717722
_output: any, // TODO: keep unused?
718723
_quiet: boolean, // TODO: keep unused?
719-
) {
724+
): Promise<void> {
720725
return;
721726
}
722727

@@ -785,7 +790,10 @@ export async function taskCompileSolidityCompile(
785790
compilationJob: CompilationJob,
786791
compilationJobs: CompilationJob[],
787792
compilationJobIndex: number,
788-
) {
793+
): Promise<{
794+
output: CompilerOutput;
795+
solcBuild: taskTypes.SolcBuild;
796+
}> {
789797
return taskCompileSolidityCompileSolc(
790798
input,
791799
quiet,
@@ -805,7 +813,7 @@ export async function taskCompileSolidityCompile(
805813
export async function taskCompileSolidityLogCompilationErrors(
806814
output: any,
807815
_quiet: boolean, // TODO: keep unused?
808-
) {
816+
): Promise<void> {
809817
if (output?.errors === undefined) {
810818
return;
811819
}
@@ -883,7 +891,7 @@ function isConsoleLogError(error: any): boolean {
883891
export async function taskCompileSolidityCheckErrors(
884892
output: any,
885893
quiet: boolean,
886-
) {
894+
): Promise<void> {
887895
await taskCompileSolidityLogCompilationErrors(output, quiet);
888896

889897
if (hasCompilationErrors(output)) {
@@ -1001,7 +1009,13 @@ export async function taskCompileSolidityCompileJob(
10011009
quiet: boolean,
10021010
emitsArtifacts: boolean,
10031011
artifacts: Artifacts,
1004-
) {
1012+
): Promise<{
1013+
artifactsEmittedPerFile: taskTypes.ArtifactsEmittedPerFile;
1014+
compilationJob: taskTypes.CompilationJob;
1015+
input: CompilerInput;
1016+
output: CompilerOutput;
1017+
solcBuild: taskTypes.SolcBuild;
1018+
}> {
10051019
log(`Compiling job with version '${compilationJob.getSolcConfig().version}'`);
10061020
const input: CompilerInput =
10071021
await taskCompileSolidityGetCompilerInput(compilationJob);
@@ -1128,7 +1142,7 @@ export async function taskCompileSolidityCompileJobs(
11281142
export async function taskCompileSolidityLogCompilationResult(
11291143
compilationJobs: CompilationJob[],
11301144
_quiet?: boolean, // TODO: keep unused?
1131-
) {
1145+
): Promise<void> {
11321146
let count = 0;
11331147
const evmVersions = new Set<string>();
11341148
const unknownEvmVersions = new Set<string>();
@@ -1173,7 +1187,9 @@ export async function taskCompileSolidityLogCompilationResult(
11731187

11741188
// TASK_COMPILE_REMOVE_OBSOLETE_ARTIFACTS
11751189
// TESTED
1176-
export async function taskCompileRemoveObsoleteArtifacts(artifacts: Artifacts) {
1190+
export async function taskCompileRemoveObsoleteArtifacts(
1191+
artifacts: Artifacts,
1192+
): Promise<void> {
11771193
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
11781194
We know this is the actual implementation, so we use some non-public methods
11791195
here by downcasting */
@@ -1247,7 +1263,7 @@ export async function taskCompileSolidity(
12471263
quiet: boolean,
12481264
concurrency: number,
12491265
tasksOverrides: TasksOverrides | undefined,
1250-
) {
1266+
): Promise<void> {
12511267
const rootPath = config.paths.root;
12521268

12531269
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

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

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

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

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

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
@@ -173,7 +173,7 @@ export async function isLocalSourceName(
173173
export async function validateSourceNameExistenceAndCasing(
174174
fromDir: string,
175175
sourceName: string,
176-
) {
176+
): Promise<void> {
177177
const trueCaseSourceName = await getSourceNameTrueCase(fromDir, sourceName);
178178

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

0 commit comments

Comments
 (0)