Skip to content

Commit

Permalink
Merge pull request #5929 from NomicFoundation/move-node-version-warning
Browse files Browse the repository at this point in the history
Print the Node.js warning before loading main
  • Loading branch information
alcuadrado authored Nov 5, 2024
2 parents efe1b97 + 6dd959b commit 83befbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
7 changes: 7 additions & 0 deletions v-next/hardhat/src/cli.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
3 changes: 0 additions & 3 deletions v-next/hardhat/src/internal/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -51,8 +50,6 @@ export async function main(
): Promise<void> {
const print = options.print ?? console.log;

printNodeJsVersionWarningIfNecessary(print);

const log = debug("hardhat:core:cli:main");

let builtinGlobalOptions;
Expand Down
10 changes: 4 additions & 6 deletions v-next/hardhat/src/internal/cli/node-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}

0 comments on commit 83befbc

Please sign in to comment.