diff --git a/v-next/hardhat-errors/src/descriptors.ts b/v-next/hardhat-errors/src/descriptors.ts index 14adb2a885..027cca11c6 100644 --- a/v-next/hardhat-errors/src/descriptors.ts +++ b/v-next/hardhat-errors/src/descriptors.ts @@ -1189,6 +1189,12 @@ This happens when your files require incompatible versions of solc or you haven' Please check Hardhat's output for more details.`, }, + INVALID_SOLCJS_COMPILER: { + number: 1231, + messageTemplate: `A wasm version of solc {version} is invalid. The compile function is not available.`, + websiteTitle: "Invalid solcjs compiler", + websiteDescription: `Hardhat successfully downloaded a WASM version of solc {version} but it is invalid. The compile function is missing.`, + }, }, VIEM: { NETWORK_NOT_FOUND: { diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.ts index 0809495537..69370ec5e0 100644 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-runner.ts @@ -1,7 +1,9 @@ +import type { SolcWrapper } from "./solcjs-wrapper.js"; + async function readStream( stream: NodeJS.ReadStream, encoding: BufferEncoding = "utf8", -) { +): Promise { stream.setEncoding(encoding); return new Promise((resolve, reject) => { @@ -13,7 +15,7 @@ async function readStream( }); } -async function getSolcJs(solcJsPath: string) { +async function getSolcJs(solcJsPath: string): Promise { const { default: solcWrapper } = await import("./solcjs-wrapper.js"); const { default: solc } = await import(solcJsPath); @@ -26,8 +28,7 @@ async function main() { const solcjsPath = process.argv[2]; const solc = await getSolcJs(solcjsPath); - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- the input read from the stdin should be a string - const output = solc.compile(input as string); + const output = solc.compile(input); console.log(output); } diff --git a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-wrapper.ts b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-wrapper.ts index d9ad11c039..6cbb3f1fc5 100755 --- a/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-wrapper.ts +++ b/v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/solcjs-wrapper.ts @@ -1,6 +1,7 @@ // This wrapper was created by extracting the parts of the solc-js package // (https://github.com/ethereum/solc-js) that we need to perform compilation. +import { HardhatError } from "@ignored/hardhat-vnext-errors"; import * as semver from "semver"; interface Solc { @@ -34,14 +35,17 @@ export type CompileWrapper = (input: string) => string; export default function wrapper(solc: Solc): SolcWrapper { const version = bindVersion(solc); - const isVersion6OrNewer = semver.gte(versionToSemver(version()), "0.6.0"); + const semverVersion = versionToSemver(version()); + const isVersion6OrNewer = semver.gte(semverVersion, "0.6.0"); const reset = bindReset(solc); const compile = bindCompile(solc, isVersion6OrNewer); if (compile === undefined) { - // eslint-disable-next-line no-restricted-syntax -- should we use a HardhatError here? - throw new Error( - 'Could not find the "compile" function in the solc library', + throw new HardhatError( + HardhatError.ERRORS.SOLIDITY.INVALID_SOLCJS_COMPILER, + { + version: version(), + }, ); }