From 655006d7f113dc9d4ac8dcfce9d09ede48a57410 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Sat, 14 Dec 2024 17:49:30 +0900 Subject: [PATCH 1/3] Fix tsx.register() crash on Deno --- v-next/hardhat/src/internal/cli/main.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/v-next/hardhat/src/internal/cli/main.ts b/v-next/hardhat/src/internal/cli/main.ts index 3345ac3d2c..c35845446a 100644 --- a/v-next/hardhat/src/internal/cli/main.ts +++ b/v-next/hardhat/src/internal/cli/main.ts @@ -45,6 +45,10 @@ export interface MainOptions { rethrowErrors?: true; } +declare global { + const Deno: any; +} + export async function main( cliArguments: string[], options: MainOptions = {}, @@ -98,8 +102,10 @@ export async function main( return; } - if (options.registerTsx) { - register(); + if (typeof Deno === "undefined") { + if (options.registerTsx) { + register(); + } } const userConfig = await importUserConfig(configPath); From 6c44ea15a2f514c1d0bac1071f72c632fdec895e Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Wed, 18 Dec 2024 22:40:41 +0900 Subject: [PATCH 2/3] Remove need for Deno global type --- v-next/hardhat/src/cli.ts | 11 ++++++++++- v-next/hardhat/src/internal/cli/main.ts | 13 ++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/v-next/hardhat/src/cli.ts b/v-next/hardhat/src/cli.ts index 3666905bed..e8bbded8e9 100644 --- a/v-next/hardhat/src/cli.ts +++ b/v-next/hardhat/src/cli.ts @@ -14,6 +14,15 @@ printNodeJsVersionWarningIfNecessary(); // eslint-disable-next-line no-restricted-syntax -- Allow top-level await here const { main } = await import("./internal/cli/main.js"); -main(process.argv.slice(2), { registerTsx: true }).catch(() => { +function isTsxRequired(): boolean { + const tsNativeRuntimes = ["Deno"]; + // environments that support typescript natively don't need tsx + if (tsNativeRuntimes.some((env) => env in globalThis)) { + return false; + } + return true; +} + +main(process.argv.slice(2), { registerTsx: isTsxRequired() }).catch(() => { process.exitCode = 1; }); diff --git a/v-next/hardhat/src/internal/cli/main.ts b/v-next/hardhat/src/internal/cli/main.ts index c35845446a..943579a2f8 100644 --- a/v-next/hardhat/src/internal/cli/main.ts +++ b/v-next/hardhat/src/internal/cli/main.ts @@ -41,14 +41,10 @@ import { printVersionMessage } from "./version.js"; export interface MainOptions { print?: (message: string) => void; - registerTsx?: true; + registerTsx?: boolean; rethrowErrors?: true; } -declare global { - const Deno: any; -} - export async function main( cliArguments: string[], options: MainOptions = {}, @@ -102,10 +98,9 @@ export async function main( return; } - if (typeof Deno === "undefined") { - if (options.registerTsx) { - register(); - } + + if (options.registerTsx) { + register(); } const userConfig = await importUserConfig(configPath); From 5941b2154125f9519634546bd39a84d9270abc6d Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Wed, 18 Dec 2024 22:42:21 +0900 Subject: [PATCH 3/3] fix lint --- v-next/hardhat/src/internal/cli/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/v-next/hardhat/src/internal/cli/main.ts b/v-next/hardhat/src/internal/cli/main.ts index 943579a2f8..6f460db73c 100644 --- a/v-next/hardhat/src/internal/cli/main.ts +++ b/v-next/hardhat/src/internal/cli/main.ts @@ -98,8 +98,7 @@ export async function main( return; } - - if (options.registerTsx) { + if (options.registerTsx === true) { register(); }