From 6dd959bc3f6bc95cb709238f95854cd494912c13 Mon Sep 17 00:00:00 2001 From: Patricio Palladino Date: Sun, 3 Nov 2024 16:59:07 +0000 Subject: [PATCH] Print the Node.js warning before loading main --- v-next/hardhat/src/cli.ts | 7 +++++++ v-next/hardhat/src/internal/cli/main.ts | 3 --- v-next/hardhat/src/internal/cli/node-version.ts | 10 ++++------ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/v-next/hardhat/src/cli.ts b/v-next/hardhat/src/cli.ts index d369d11f0f..3666905bed 100644 --- a/v-next/hardhat/src/cli.ts +++ b/v-next/hardhat/src/cli.ts @@ -1,9 +1,16 @@ #!/usr/bin/env node +import { printNodeJsVersionWarningIfNecessary } from "./internal/cli/node-version.js"; + // We enable the sourcemaps before loading main, so that everything except this // small file is loaded with sourcemaps enabled. process.setSourceMapsEnabled(true); +// We also print this warning before loading main, so that if there is some +// unsupported js syntax or Node API elsewhere, we get to print it before +// crashing. +printNodeJsVersionWarningIfNecessary(); + // eslint-disable-next-line no-restricted-syntax -- Allow top-level await here const { main } = await import("./internal/cli/main.js"); diff --git a/v-next/hardhat/src/internal/cli/main.ts b/v-next/hardhat/src/internal/cli/main.ts index 6a7552c353..668737267e 100644 --- a/v-next/hardhat/src/internal/cli/main.ts +++ b/v-next/hardhat/src/internal/cli/main.ts @@ -35,7 +35,6 @@ import { createHardhatRuntimeEnvironment } from "../hre-intialization.js"; import { printErrorMessages } from "./error-handler.js"; import { getGlobalHelpString } from "./helpers/getGlobalHelpString.js"; import { getHelpString } from "./helpers/getHelpString.js"; -import { printNodeJsVersionWarningIfNecessary } from "./node-version.js"; import { ensureTelemetryConsent } from "./telemetry/telemetry-permissions.js"; import { printVersionMessage } from "./version.js"; @@ -51,8 +50,6 @@ export async function main( ): Promise { const print = options.print ?? console.log; - printNodeJsVersionWarningIfNecessary(print); - const log = debug("hardhat:core:cli:main"); let builtinGlobalOptions; diff --git a/v-next/hardhat/src/internal/cli/node-version.ts b/v-next/hardhat/src/internal/cli/node-version.ts index 87a21f474b..83eb5cd747 100644 --- a/v-next/hardhat/src/internal/cli/node-version.ts +++ b/v-next/hardhat/src/internal/cli/node-version.ts @@ -32,17 +32,15 @@ function isNodeVersionSupported(): boolean { return true; } -export function printNodeJsVersionWarningIfNecessary( - print: (message: string) => void, -): void { +export function printNodeJsVersionWarningIfNecessary(): void { if (isNodeVersionSupported()) { return; } - print(""); - print( + console.log(""); + console.log( chalk.bold(`${chalk.yellow("WARNING:")} You are using Node.js ${process.versions.node} which is not supported by Hardhat. Please upgrade to ${MIN_SUPPORTED_NODE_VERSION.join(".")} or a later version.`), ); - print(""); + console.log(""); }