Skip to content

Commit

Permalink
fix: compilation with solcjs on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
galargh committed Dec 18, 2024
1 parent b85b358 commit 70d8632
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -37,19 +37,31 @@ export class SolcJsCompiler implements Compiler {
) {}

public async compile(input: CompilerInput): Promise<any> {
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
const nodeOptions = scriptPath.endsWith(".ts")
? ["--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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { spawn } from "../../../../../../src/internal/cli/init/subprocess.js";

const solcVersion = "0.6.6";

describe(
describe.only(

Check failure on line 20 in v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/compiler/index.ts

View workflow job for this annotation

GitHub Actions / [hardhat] lint

describe.only not permitted
"Compiler",
{
skip: process.env.HARDHAT_DISABLE_SLOW_TESTS === "true",
Expand Down

0 comments on commit 70d8632

Please sign in to comment.