diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts index bae37b94061..d41cdfa6844 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts @@ -6,7 +6,7 @@ import type { import { execFile } from "node:child_process"; import os from "node:os"; import path from "node:path"; -import { fileURLToPath } from "node:url"; +import { fileURLToPath, pathToFileURL } from "node:url"; import { HardhatError, @@ -37,7 +37,8 @@ export class SolcJsCompiler implements Compiler { ) {} public async compile(input: CompilerInput): Promise { - const scriptPath = fileURLToPath(import.meta.resolve("./solcjs-runner.js")); + const scriptFileUrl = import.meta.resolve("./solcjs-runner.js"); + const scriptPath = fileURLToPath(scriptFileUrl); // If the script is a TypeScript file, we need to pass the --import tsx/esm // which is available, as we are running the tests @@ -45,11 +46,22 @@ export class SolcJsCompiler implements Compiler { ? ["--import", "tsx/esm"] : []; + const args = [...nodeOptions]; + + // NOTE: We're using file URLs on Windows instead of paths because only URLs + // with a scheme are supported by the default ESM loader there. + if (os.platform() === "win32" && scriptPath.endsWith(".ts")) { + const compilerFileUrl = pathToFileURL(this.compilerPath); + args.push(scriptFileUrl, compilerFileUrl.href); + } else { + args.push(scriptPath, this.compilerPath); + } + const output: string = await new Promise((resolve, reject) => { try { const subprocess = execFile( process.execPath, - [...nodeOptions, scriptPath, this.compilerPath], + args, { maxBuffer: COMPILATION_SUBPROCESS_IO_BUFFER_SIZE, }, diff --git a/v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/compiler/index.ts b/v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/compiler/index.ts index 9f7791bceac..0142b72b306 100644 --- a/v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/compiler/index.ts +++ b/v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/compiler/index.ts @@ -17,7 +17,7 @@ import { spawn } from "../../../../../../src/internal/cli/init/subprocess.js"; const solcVersion = "0.6.6"; -describe( +describe.only( "Compiler", { skip: process.env.HARDHAT_DISABLE_SLOW_TESTS === "true",