Skip to content

Commit

Permalink
move decorator to utils package and remove extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Jul 30, 2024
1 parent 83bcc42 commit cc6975b
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 42 deletions.
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions v-next/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@microsoft/api-extractor": "^7.43.4",
"@nomicfoundation/hardhat-test-utils": "workspace:^",
"@types/debug": "^4.1.4",
"@types/node": "^20.14.9",
"@types/semver": "^7.5.8",
"@typescript-eslint/eslint-plugin": "^7.7.1",
Expand All @@ -80,7 +79,6 @@
"@ignored/hardhat-vnext-errors": "workspace:^3.0.0-next.2",
"@ignored/hardhat-vnext-utils": "workspace:^3.0.0-next.2",
"chalk": "^5.3.0",
"debug": "^4.1.1",
"env-paths": "^2.2.0",
"semver": "^7.6.2"
}
Expand Down
5 changes: 0 additions & 5 deletions v-next/core/src/internal/hook-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
assertHardhatInvariant,
} from "@ignored/hardhat-vnext-errors";

import { withDebugLogs } from "./debug.js";

export class HookManagerImplementation implements HookManager {
readonly #pluginsInReverseOrder: HardhatPlugin[];

Expand Down Expand Up @@ -101,7 +99,6 @@ export class HookManagerImplementation implements HookManager {
);
}

@withDebugLogs("HookManager:runHandlerChain")
public async runHandlerChain<
HookCategoryNameT extends keyof HardhatHooks,
HookNameT extends keyof HardhatHooks[HookCategoryNameT],
Expand Down Expand Up @@ -140,7 +137,6 @@ export class HookManagerImplementation implements HookManager {
return next(...handlerParams);
}

@withDebugLogs("HookManager:runSequentialHandlers")
public async runSequentialHandlers<
HookCategoryNameT extends keyof HardhatHooks,
HookNameT extends keyof HardhatHooks[HookCategoryNameT],
Expand Down Expand Up @@ -174,7 +170,6 @@ export class HookManagerImplementation implements HookManager {
return result;
}

@withDebugLogs("HookManager:runParallelHandlers")
public async runParallelHandlers<
HookCategoryNameT extends keyof HardhatHooks,
HookNameT extends keyof HardhatHooks[HookCategoryNameT],
Expand Down
2 changes: 0 additions & 2 deletions v-next/core/src/internal/hre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type { UserInterruptionManager } from "../types/user-interruptions.js";
import { HardhatError } from "@ignored/hardhat-vnext-errors";

import { ResolvedConfigurationVariableImplementation } from "./configuration-variables.js";
import { withDebugLogs } from "./debug.js";
import {
buildGlobalOptionDefinitions,
resolveGlobalOptions,
Expand All @@ -30,7 +29,6 @@ import { UserInterruptionManagerImplementation } from "./user-interruptions.js";
export class HardhatRuntimeEnvironmentImplementation
implements HardhatRuntimeEnvironment
{
@withDebugLogs("HardhatRuntimeEnvironment:create")
public static async create(
inputUserConfig: HardhatUserConfig,
userProvidedGlobalOptions: Partial<GlobalOptions>,
Expand Down
4 changes: 0 additions & 4 deletions v-next/core/src/internal/tasks/resolved-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from "@ignored/hardhat-vnext-errors";
import { ensureError } from "@ignored/hardhat-vnext-utils/error";

import { withDebugLogs } from "../debug.js";
import { detectPluginNpmDependencyProblems } from "../plugins/detect-plugin-npm-dependency-problems.js";

import { formatTaskId } from "./utils.js";
Expand All @@ -27,7 +26,6 @@ import { validateTaskArgumentValue } from "./validations.js";
export class ResolvedTask implements Task {
readonly #hre: HardhatRuntimeEnvironment;

@withDebugLogs("ResolvedTask:createEmptyTask")
public static createEmptyTask(
hre: HardhatRuntimeEnvironment,
id: string[],
Expand All @@ -46,7 +44,6 @@ export class ResolvedTask implements Task {
);
}

@withDebugLogs("ResolvedTask:createNewTask")
public static createNewTask(
hre: HardhatRuntimeEnvironment,
id: string[],
Expand Down Expand Up @@ -95,7 +92,6 @@ export class ResolvedTask implements Task {
* @throws HardhatError if the task is empty, a required argument is missing,
* a argument has an invalid type, or the file actions can't be resolved.
*/
@withDebugLogs("ResolvedTask:run")
public async run(taskArguments: TaskArguments): Promise<any> {
if (this.isEmpty) {
throw new HardhatError(HardhatError.ERRORS.TASK_DEFINITIONS.EMPTY_TASK, {
Expand Down
3 changes: 0 additions & 3 deletions v-next/core/src/internal/tasks/task-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from "@ignored/hardhat-vnext-errors";

import { TaskDefinitionType } from "../../types/tasks.js";
import { withDebugLogs } from "../debug.js";

import { ResolvedTask } from "./resolved-task.js";
import { formatTaskId, getActorFragment } from "./utils.js";
Expand Down Expand Up @@ -63,7 +62,6 @@ export class TaskManagerImplementation implements TaskManager {
return this.#rootTasks;
}

@withDebugLogs("TaskManager:getTask")
public getTask(taskId: string | string[]): Task {
taskId = Array.isArray(taskId) ? taskId : [taskId];
if (taskId.length === 0) {
Expand Down Expand Up @@ -101,7 +99,6 @@ export class TaskManagerImplementation implements TaskManager {
return task;
}

@withDebugLogs("TaskManager:insertTask")
#insertTask(taskId: string[], task: Task, pluginId?: string) {
if (taskId.length === 0) {
throw new HardhatError(
Expand Down
3 changes: 3 additions & 0 deletions v-next/hardhat-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"./common-errors": "./dist/src/common-errors.js",
"./crypto": "./dist/src/crypto.js",
"./date": "./dist/src/date.js",
"./debug": "./dist/src/debug.js",
"./error": "./dist/src/error.js",
"./eth": "./dist/src/eth.js",
"./fs": "./dist/src/fs.js",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
"@ignored/hardhat-vnext-node-test-reporter": "workspace:^3.0.0-next.2",
"@types/bn.js": "^5.1.5",
"@types/debug": "^4.1.4",
"@types/keccak": "^3.0.4",
"@types/node": "^20.14.9",
"@typescript-eslint/eslint-plugin": "^7.7.1",
Expand All @@ -74,6 +76,7 @@
"typescript-eslint": "7.7.1"
},
"dependencies": {
"debug": "^4.1.1",
"fast-equals": "^5.0.1",
"keccak": "^3.0.4",
"rfdc": "^1.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import debugLib from "debug";
/**
* A simple decorator that adds debug logging for when a method is entered and exited.
*
* This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code.
*
* Example usage:
*
* ```
Expand All @@ -22,7 +24,7 @@ export function withDebugLogs<This, Args extends any[], Return>(
(this: This, ...args: Args) => Return
>,
): (this: This, ...args: Args) => Return {
const log = debugLib(`hardhat:core${tag === "" ? "" : `:${tag}`}`);
const log = debugLib(`hardhat:dev:core${tag === "" ? "" : `:${tag}`}`);

function replacementMethod(this: This, ...args: Args): Return {
log(`Entering method with args:`, args);
Expand Down
26 changes: 7 additions & 19 deletions v-next/hardhat/src/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,19 @@ export async function main(

let builtinGlobalOptions;

log("Hardhat CLI started with arguments:", cliArguments);
log("Hardhat CLI started");

try {
const usedCliArguments: boolean[] = new Array(cliArguments.length).fill(
false,
);

log("Parsing builtin global options");

builtinGlobalOptions = await parseBuiltinGlobalOptions(
cliArguments,
usedCliArguments,
);

log("Parsed builtin global options:", builtinGlobalOptions);
log("Parsed builtin global options");

if (builtinGlobalOptions.version) {
return await printVersionMessage(print);
Expand All @@ -74,26 +72,20 @@ export async function main(
return await initHardhat();
}

log("Checking telemetry consent");

// TODO: the consent will be enabled in the other PRs related to telemetry
const _telemetryConsent = await getTelemetryConsent();

log("Telemetry consent:", _telemetryConsent);
log("Retrieved telemetry consent");

if (builtinGlobalOptions.configPath === undefined) {
log("Config path not provided, attempting to resolve it");

builtinGlobalOptions.configPath = await resolveHardhatConfigPath();

log("Resolved config path:", builtinGlobalOptions.configPath);
log("Resolved config path");
}

log("Importing user config");

const userConfig = await importUserConfig(builtinGlobalOptions.configPath);

log("User config imported:", userConfig);
log("User config imported");

const configPlugins = Array.isArray(userConfig.plugins)
? userConfig.plugins
Expand All @@ -104,7 +96,7 @@ export async function main(
builtinGlobalOptions.configPath,
);

log("Resolved plugins:", resolvedPlugins);
log("Resolved plugins");

const pluginGlobalOptionDefinitions =
buildGlobalOptionDefinitions(resolvedPlugins);
Expand All @@ -118,8 +110,6 @@ export async function main(
usedCliArguments,
);

log("User provided global options:", userProvidedGlobalOptions);

log("Creating Hardhat Runtime Environment");

const hre = await createHardhatRuntimeEnvironment(
Expand All @@ -133,8 +123,6 @@ export async function main(

const taskOrId = parseTask(cliArguments, usedCliArguments, hre);

log("Parsed task:", taskOrId);

if (Array.isArray(taskOrId)) {
if (taskOrId.length === 0) {
const globalHelp = await getGlobalHelpString(
Expand Down Expand Up @@ -167,7 +155,7 @@ export async function main(
task,
);

log(`Running task "${task.id.join(" ")}" with arguments:`, taskArguments);
log(`Running task "${task.id.join(" ")}"`);

await task.run(taskArguments);
} catch (error) {
Expand Down

0 comments on commit cc6975b

Please sign in to comment.