diff --git a/.changeset/viem-resolution-mode-imports.md b/.changeset/viem-resolution-mode-imports.md new file mode 100644 index 00000000000..8f1a73450c8 --- /dev/null +++ b/.changeset/viem-resolution-mode-imports.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/hardhat-viem": patch +--- + +Added a `resolution-mode` import attribute to `viem`'s type-only imports, fixing a build failure against newer `viem` releases. diff --git a/packages/hardhat-viem/src/internal/accounts.ts b/packages/hardhat-viem/src/internal/accounts.ts index 479cd4942e2..59be3530c63 100644 --- a/packages/hardhat-viem/src/internal/accounts.ts +++ b/packages/hardhat-viem/src/internal/accounts.ts @@ -1,5 +1,5 @@ import type { EthereumProvider } from "hardhat/types"; -import type { Address } from "viem"; +import type { Address } from "viem" with { "resolution-mode": "import" }; import memoize from "lodash.memoize"; diff --git a/packages/hardhat-viem/src/internal/bytecode.ts b/packages/hardhat-viem/src/internal/bytecode.ts index a516a0e1fb0..5674c48734b 100644 --- a/packages/hardhat-viem/src/internal/bytecode.ts +++ b/packages/hardhat-viem/src/internal/bytecode.ts @@ -1,4 +1,4 @@ -import type * as viemT from "viem"; +import type * as viemT from "viem" with { "resolution-mode": "import" }; import type { Artifact } from "hardhat/types/artifacts"; import { @@ -22,7 +22,9 @@ export async function linkBytecode( artifact: Artifact, libraries: Link[] ): Promise { - const { isHex } = require("viem") as typeof import("viem"); + const { isHex } = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); let bytecode = artifact.bytecode; // TODO: measure performance impact diff --git a/packages/hardhat-viem/src/internal/chains.ts b/packages/hardhat-viem/src/internal/chains.ts index 8c2e2d2a140..1b5d58703e8 100644 --- a/packages/hardhat-viem/src/internal/chains.ts +++ b/packages/hardhat-viem/src/internal/chains.ts @@ -1,5 +1,5 @@ import type { EthereumProvider } from "hardhat/types"; -import type { Chain } from "viem"; +import type { Chain } from "viem" with { "resolution-mode": "import" }; import type { TestClientMode } from "../types"; import memoize from "lodash.memoize"; @@ -7,8 +7,12 @@ import memoize from "lodash.memoize"; import { UnknownDevelopmentNetworkError, NetworkNotFoundError } from "./errors"; export async function getChain(provider: EthereumProvider): Promise { - const { extractChain } = require("viem") as typeof import("viem"); - const chainsModule = require("viem/chains") as typeof import("viem/chains"); + const { extractChain } = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); + const chainsModule = require("viem/chains") as typeof import("viem/chains", { + with: { "resolution-mode": "import" }, + }); const chains = Object.values(chainsModule) as Chain[]; const chainId = await getChainId(provider); diff --git a/packages/hardhat-viem/src/internal/clients.ts b/packages/hardhat-viem/src/internal/clients.ts index 56d75a64df3..b1ad96b1d71 100644 --- a/packages/hardhat-viem/src/internal/clients.ts +++ b/packages/hardhat-viem/src/internal/clients.ts @@ -5,7 +5,7 @@ import type { PublicClientConfig, WalletClientConfig, TestClientConfig, -} from "viem"; +} from "viem" with { "resolution-mode": "import" }; import type { PublicClient, TestClient, @@ -56,7 +56,9 @@ export async function innerGetPublicClient( chain: Chain, publicClientConfig?: Partial ): Promise { - const viem = require("viem") as typeof import("viem"); + const viem = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); const { clientParameters, transportParameters } = await getParameters( chain, publicClientConfig @@ -97,7 +99,9 @@ export async function innerGetWalletClients( accounts: Address[], walletClientConfig?: Partial ): Promise { - const viem = require("viem") as typeof import("viem"); + const viem = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); const { clientParameters, transportParameters } = await getParameters( chain, walletClientConfig @@ -161,7 +165,9 @@ export async function innerGetTestClient( mode: TestClientMode, testClientConfig?: Partial ): Promise { - const viem = require("viem") as typeof import("viem"); + const viem = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); const { clientParameters, transportParameters } = await getParameters( chain, testClientConfig diff --git a/packages/hardhat-viem/src/internal/contracts.ts b/packages/hardhat-viem/src/internal/contracts.ts index 905c6e52717..18a8c467f07 100644 --- a/packages/hardhat-viem/src/internal/contracts.ts +++ b/packages/hardhat-viem/src/internal/contracts.ts @@ -2,7 +2,9 @@ import type { EthereumProvider, HardhatRuntimeEnvironment, } from "hardhat/types"; -import type { Abi, Address, Hex } from "viem"; +import type { Abi, Address, Hex } from "viem" with { + "resolution-mode": "import", +}; import type { DeployContractConfig, GetContractAtConfig, @@ -191,7 +193,9 @@ async function innerSendDeploymentTransaction( hash: deploymentTxHash, }); - const { getContractAddress } = require("viem") as typeof import("viem"); + const { getContractAddress } = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); const contractAddress = getContractAddress({ from: walletClient.account.address, nonce: BigInt(deploymentTx.nonce), @@ -234,7 +238,9 @@ async function innerGetContractAt( contractAbi: Abi, address: Address ): Promise { - const viem = require("viem") as typeof import("viem"); + const viem = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, + }); const contract = viem.getContract({ address, client: { diff --git a/packages/hardhat-viem/src/types.ts b/packages/hardhat-viem/src/types.ts index 6253f19ba4d..b12d29a82e5 100644 --- a/packages/hardhat-viem/src/types.ts +++ b/packages/hardhat-viem/src/types.ts @@ -1,4 +1,4 @@ -import type * as viemT from "viem"; +import type * as viemT from "viem" with { "resolution-mode": "import" }; import type { ArtifactsMap } from "hardhat/types/artifacts"; import type { Libraries } from "./internal/bytecode"; diff --git a/packages/hardhat-viem/test/chains.ts b/packages/hardhat-viem/test/chains.ts index 7bff3b631ea..f78432a7b15 100644 --- a/packages/hardhat-viem/test/chains.ts +++ b/packages/hardhat-viem/test/chains.ts @@ -2,7 +2,6 @@ import type { EthereumProvider } from "hardhat/types"; import { expect, assert } from "chai"; import sinon from "sinon"; -import * as chains from "viem/chains"; import { getChain, @@ -11,6 +10,10 @@ import { } from "../src/internal/chains"; import { EthereumMockedProvider } from "./mocks/provider"; +const chains = require("viem/chains") as typeof import("viem/chains", { + with: { "resolution-mode": "import" }, +}); + describe("chains", () => { describe("getChain", () => { afterEach(sinon.restore); diff --git a/packages/hardhat-viem/test/clients.ts b/packages/hardhat-viem/test/clients.ts index 50129b60ec8..095eac00dd7 100644 --- a/packages/hardhat-viem/test/clients.ts +++ b/packages/hardhat-viem/test/clients.ts @@ -1,7 +1,6 @@ import type { EthereumProvider } from "hardhat/types"; import { assert, expect } from "chai"; -import * as chains from "viem/chains"; import { innerGetPublicClient, @@ -10,6 +9,10 @@ import { } from "../src/internal/clients"; import { EthereumMockedProvider } from "./mocks/provider"; +const chains = require("viem/chains") as typeof import("viem/chains", { + with: { "resolution-mode": "import" }, +}); + describe("clients", () => { describe("innerGetPublicClient", () => { it("should return a public client", async () => { diff --git a/packages/hardhat-viem/test/integration.ts b/packages/hardhat-viem/test/integration.ts index 274b95d63bc..ca3c05053ed 100644 --- a/packages/hardhat-viem/test/integration.ts +++ b/packages/hardhat-viem/test/integration.ts @@ -1,16 +1,21 @@ -import type { Hex, TransactionReceipt } from "viem"; +import type { Hex, TransactionReceipt } from "viem" with { + "resolution-mode": "import", +}; import type { EthereumProvider } from "hardhat/types"; import path from "path"; import { assert, expect } from "chai"; import sinon from "sinon"; -import { getAddress, parseEther } from "viem"; import { TASK_CLEAN, TASK_COMPILE } from "hardhat/builtin-tasks/task-names"; import { deployContract, innerDeployContract } from "../src/internal/contracts"; import { EthereumMockedProvider } from "./mocks/provider"; import { assertSnapshotMatch, sleep, useEnvironment } from "./helpers"; +const { getAddress, parseEther } = require("viem") as typeof import("viem", { + with: { "resolution-mode": "import" }, +}); + describe("Integration tests", function () { afterEach(function () { sinon.restore();