Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update vnext to typescript 5.5 #5453

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config-v-next/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declarationMap": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"isolatedDeclarations": true,
"noEmitOnError": true,
"noImplicitOverride": true,
"skipDefaultLibCheck": true,
Expand Down
492 changes: 136 additions & 356 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v-next/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"prettier": "3.2.5",
"rimraf": "^5.0.5",
"tsx": "^4.11.0",
"typescript": "~5.4.0",
"typescript": "~5.5.0",
"typescript-eslint": "7.7.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion v-next/core/src/internal/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ParameterType } from "../types/common.js";
/**
* Names that can't be used as global- nor task-parameter names.
*/
export const RESERVED_PARAMETER_NAMES = new Set([
export const RESERVED_PARAMETER_NAMES: Set<string> = new Set([
"config",
"help",
"showStackTraces",
Expand Down
2 changes: 1 addition & 1 deletion v-next/core/test/internal/fixture-plugins/config-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
HardhatUserConfigValidationError,
} from "../../../src/types/hooks.js";

export default async () => {
export default async (): Promise<Partial<ConfigHooks>> => {
const handlers: Partial<ConfigHooks> = {
validateUserConfig: async (
_config: HardhatUserConfig,
Expand Down
2 changes: 1 addition & 1 deletion v-next/core/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createTestEnvManager() {
});

return {
setEnvVar(name: string, value: string) {
setEnvVar(name: string, value: string): void {
// Before setting a new value, save the original value if it hasn't been saved yet
if (!changes.has(name)) {
originalValues.set(name, process.env[name]);
Expand Down
6 changes: 4 additions & 2 deletions v-next/example-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const greeting = task("hello", "Prints a greeting")
})
.build();

export default {
const config: HardhatUserConfig = {
tasks: [
exampleTaskOverride,
testTask,
Expand Down Expand Up @@ -130,4 +130,6 @@ export default {
},
],
privateKey: configVariable("privateKey"),
} satisfies HardhatUserConfig;
};

export default config;
2 changes: 1 addition & 1 deletion v-next/example-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"@ignored/hardhat-vnext": "workspace:^3.0.0-next.3",
"@types/node": "^20.14.9",
"prettier": "3.2.5",
"typescript": "~5.4.0"
"typescript": "~5.5.0"
}
}
2 changes: 1 addition & 1 deletion v-next/hardhat-build-system/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"rimraf": "^5.0.5",
"sinon": "^9.0.0",
"tsx": "^4.11.0",
"typescript": "~5.4.0",
"typescript": "~5.5.0",
"typescript-eslint": "7.7.1"
}
}
5 changes: 3 additions & 2 deletions v-next/hardhat-build-system/src/internal/build-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Artifacts,
CompilationJobCreationError,
BuildConfig,
DependencyGraph,
} from "./types/index.js";

import {
Expand Down Expand Up @@ -71,7 +72,7 @@ export class BuildSystem {
// TODO: TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS_FAILURE_REASONS - naming? Do we want to keep it?
public async solidityGetCompilationJobsFailureReasons(
errors: CompilationJobCreationError[],
) {
): Promise<string> {
return taskCompileSolidityGetCompilationJobsFailureReasons(errors);
}

Expand All @@ -80,7 +81,7 @@ export class BuildSystem {
public async solidityGetDependencyGraph(
sourceNames: string[],
config: BuildConfig,
) {
): Promise<DependencyGraph> {
return taskCompileSolidityGetDependencyGraph(sourceNames, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class SolidityFilesCache {
this.#cache = _cache;
}

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

public async writeToFile(solidityFilesCachePath: string) {
public async writeToFile(solidityFilesCachePath: string): Promise<void> {
await writeJsonFile(solidityFilesCachePath, this.#cache);
}

public addFile(absolutePath: string, entry: CacheEntry) {
public addFile(absolutePath: string, entry: CacheEntry): void {
this.#cache.files[absolutePath] = entry;
}

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

public removeEntry(file: string) {
public removeEntry(file: string): void {
delete this.#cache.files[file];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class CompilationJob implements taskTypes.CompilationJob {

constructor(public solidityConfig: SolcConfig) {}

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

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

public isEmpty() {
public isEmpty(): boolean {
return this.#filesToCompile.size === 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class CompilerDownloader implements ICompilerDownloader {
constructor(
_platform: CompilerPlatform,
_compilersDir: string,
_compilerListCachePeriodMs = CompilerDownloader.defaultCompilerListCachePeriod,
_compilerListCachePeriodMs: number = CompilerDownloader.defaultCompilerListCachePeriod,
_downloadFunction: typeof download = download,
) {
this.#platform = _platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Compiler implements ICompiler {
this.#pathToSolcJs = pathToSolcJs;
}

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

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

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

// Logic to make sure that solc default import callback is not being used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ResolvedFile implements IResolvedFile {
}
}

public getVersionedName() {
public getVersionedName(): string {
return (
this.sourceName +
(this.library !== undefined ? `@v${this.library.version}` : "")
Expand Down
44 changes: 30 additions & 14 deletions v-next/hardhat-build-system/src/internal/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ export async function taskCompileSolidityGetCompilationJobs(
config: BuildConfig,
dependencyGraph: taskTypes.DependencyGraph,
solidityFilesCache?: SolidityFilesCache,
) {
): Promise<{
jobs: taskTypes.CompilationJob[];
errors: taskTypes.CompilationJobCreationError[];
}> {
const connectedComponents = dependencyGraph.getConnectedComponents();

log(
Expand Down Expand Up @@ -217,7 +220,7 @@ export async function taskCompileSolidityGetCompilationJobs(
*/
export async function taskCompileSolidityHandleCompilationJobsFailures(
compilationJobsCreationErrors: CompilationJobCreationError[],
) {
): Promise<void> {
const hasErrors = compilationJobsCreationErrors.length > 0;

if (hasErrors) {
Expand Down Expand Up @@ -535,7 +538,9 @@ export async function taskCompileSolidityMergeCompilationJobs(
/**
* Prints a message when there's nothing to compile.
*/
export async function taskCompileSolidityLogNothingToCompile(quiet: boolean) {
export async function taskCompileSolidityLogNothingToCompile(
quiet: boolean,
): Promise<void> {
if (!quiet) {
console.log("Nothing to compile");
}
Expand All @@ -547,7 +552,7 @@ export async function taskCompileSolidityLogDownloadCompilerStart(
solcVersion: string,
isCompilerDownloaded: boolean,
_quiet: boolean, // TODO: keep unused?
) {
): Promise<void> {
if (isCompilerDownloaded) {
return;
}
Expand All @@ -560,7 +565,7 @@ export async function taskCompileSolidityLogDownloadCompilerEnd(
_solcVersion: string, // TODO: keep unused?
_isCompilerDownloaded: boolean, // TODO: keep unused?
_quiet: boolean, // TODO: keep unused?
) {
): Promise<void> {
return;
}

Expand Down Expand Up @@ -658,7 +663,7 @@ export async function taskCompileSolidityLogRunCompilerStart(
_compilationJobs: CompilationJob[], // TODO: keep unused?
_compilationJobIndex: number, // TODO: keep unused?
_quiet: boolean, // TODO: keep unused?
) {
): Promise<void> {
return;
}

Expand Down Expand Up @@ -715,7 +720,7 @@ export async function taskCompileSolidityLogRunCompilerEnd(
_compilationJobIndex: number, // TODO: keep unused?
_output: any, // TODO: keep unused?
_quiet: boolean, // TODO: keep unused?
) {
): Promise<void> {
return;
}

Expand Down Expand Up @@ -784,7 +789,10 @@ export async function taskCompileSolidityCompile(
compilationJob: CompilationJob,
compilationJobs: CompilationJob[],
compilationJobIndex: number,
) {
): Promise<{
output: CompilerOutput;
solcBuild: taskTypes.SolcBuild;
}> {
return taskCompileSolidityCompileSolc(
input,
quiet,
Expand All @@ -804,7 +812,7 @@ export async function taskCompileSolidityCompile(
export async function taskCompileSolidityLogCompilationErrors(
output: any,
_quiet: boolean, // TODO: keep unused?
) {
): Promise<void> {
if (output?.errors === undefined) {
return;
}
Expand Down Expand Up @@ -882,7 +890,7 @@ function isConsoleLogError(error: any): boolean {
export async function taskCompileSolidityCheckErrors(
output: any,
quiet: boolean,
) {
): Promise<void> {
await taskCompileSolidityLogCompilationErrors(output, quiet);

if (hasCompilationErrors(output)) {
Expand Down Expand Up @@ -1000,7 +1008,13 @@ export async function taskCompileSolidityCompileJob(
quiet: boolean,
emitsArtifacts: boolean,
artifacts: Artifacts,
) {
): Promise<{
artifactsEmittedPerFile: taskTypes.ArtifactsEmittedPerFile;
compilationJob: taskTypes.CompilationJob;
input: CompilerInput;
output: CompilerOutput;
solcBuild: taskTypes.SolcBuild;
}> {
log(`Compiling job with version '${compilationJob.getSolcConfig().version}'`);
const input: CompilerInput =
await taskCompileSolidityGetCompilerInput(compilationJob);
Expand Down Expand Up @@ -1125,7 +1139,7 @@ export async function taskCompileSolidityCompileJobs(
export async function taskCompileSolidityLogCompilationResult(
compilationJobs: CompilationJob[],
_quiet?: boolean, // TODO: keep unused?
) {
): Promise<void> {
let count = 0;
const evmVersions = new Set<string>();
const unknownEvmVersions = new Set<string>();
Expand Down Expand Up @@ -1170,7 +1184,9 @@ export async function taskCompileSolidityLogCompilationResult(

// TASK_COMPILE_REMOVE_OBSOLETE_ARTIFACTS
// TESTED
export async function taskCompileRemoveObsoleteArtifacts(artifacts: Artifacts) {
export async function taskCompileRemoveObsoleteArtifacts(
artifacts: Artifacts,
): Promise<void> {
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions --
We know this is the actual implementation, so we use some non-public methods
here by downcasting */
Expand Down Expand Up @@ -1244,7 +1260,7 @@ export async function taskCompileSolidity(
quiet: boolean,
concurrency: number,
tasksOverrides: TasksOverrides | undefined,
) {
): Promise<void> {
const rootPath = config.paths.root;

const sourcePaths: string[] = await taskCompileSolidityGetSourcePaths(
Expand Down
10 changes: 5 additions & 5 deletions v-next/hardhat-build-system/src/internal/utils/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Artifacts implements IArtifacts {

public addValidArtifacts(
validArtifacts: Array<{ sourceName: string; artifacts: string[] }>,
) {
): void {
this.#validArtifacts.push(...validArtifacts);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ export class Artifacts implements IArtifacts {
public async saveArtifactAndDebugFile(
artifact: Artifact,
pathToBuildInfo?: string,
) {
): Promise<void> {
try {
// artifact
const fullyQualifiedName = getFullyQualifiedName(
Expand Down Expand Up @@ -347,7 +347,7 @@ export class Artifacts implements IArtifacts {
/**
* Remove all artifacts that don't correspond to the current solidity files
*/
public async removeObsoleteArtifacts() {
public async removeObsoleteArtifacts(): Promise<void> {
// We clear the cache here, as we want to be sure this runs correctly
this.clearCache();

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

public clearCache() {
public clearCache(): void {
// Avoid accidentally re-enabling the cache
if (this.#cache === undefined) {
return;
Expand All @@ -414,7 +414,7 @@ export class Artifacts implements IArtifacts {
};
}

public disableCache() {
public disableCache(): void {
this.#cache = undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion v-next/hardhat-build-system/src/internal/utils/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function resolveTempFileName(filePath: string): string {
});
}

export async function download(url: string, filePath: string) {
export async function download(url: string, filePath: string): Promise<void> {
const dispatcherOptions: DispatcherOptions = {};
if (process.env.proxy !== undefined && shouldUseProxy(url)) {
dispatcherOptions.proxy = process.env.proxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "node:path";

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

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