Skip to content

Commit 6a9b883

Browse files
committed
Make slow imports dynamic in hardhat-chai-matchers
1 parent c6f2e4a commit 6a9b883

File tree

5 files changed

+9
-5
lines changed

5 files changed

+9
-5
lines changed

config/eslint/constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports.slowImportsCommonIgnoredModules = [
77
"source-map-support/register",
88
"@nomicfoundation/hardhat-ethers",
99
"hardhat/common",
10+
"hardhat/common/bigInt",
1011
"hardhat/config",
1112
"hardhat/plugins",
1213
"hardhat/types",

packages/hardhat-chai-matchers/src/internal/addressable.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isAddress, isAddressable } from "ethers";
1+
import type EthersT from "ethers";
22

33
export function supportAddressable(
44
Assertion: Chai.AssertionStatic,
@@ -26,6 +26,7 @@ function override(
2626
// so we are looking for a sync way of getting the address. If an address was recovered, it is returned as a string,
2727
// otherwise undefined is returned.
2828
function tryGetAddressSync(value: any): string | undefined {
29+
const { isAddress, isAddressable } = require("ethers") as typeof EthersT;
2930
if (isAddress(value)) {
3031
return value;
3132
} else if (isAddressable(value)) {

packages/hardhat-chai-matchers/src/internal/changeEtherBalances.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type EthersT from "ethers";
22
import type { Addressable, BigNumberish, TransactionResponse } from "ethers";
33
import type { BalanceChangeOptions } from "./misc/balance";
4-
5-
import ordinal from "ordinal";
4+
import type OrdinalT from "ordinal";
65

76
import { buildAssert } from "../utils";
87
import { getAddressOf } from "./misc/account";
@@ -23,6 +22,7 @@ export function supportChangeEtherBalances(
2322
options?: BalanceChangeOptions
2423
) {
2524
const { toBigInt } = require("ethers") as typeof EthersT;
25+
const ordinal = require("ordinal") as typeof OrdinalT;
2626
// capture negated flag before async code executes; see buildAssert's jsdoc
2727
const negated = this.__flags.negate;
2828

packages/hardhat-chai-matchers/src/internal/emit.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type EthersT from "ethers";
22
import type { Contract, Transaction } from "ethers";
33
import type { AssertWithSsfi, Ssfi } from "../utils";
4+
import type OrdinalT from "ordinal";
45

56
import { AssertionError } from "chai";
67
import util from "util";
7-
import ordinal from "ordinal";
88

99
import { buildAssert } from "../utils";
1010
import { ASSERTION_ABORTED, EMIT_MATCHER } from "./constants";
@@ -156,6 +156,7 @@ function assertArgsArraysEqual(
156156
ssfi: Ssfi
157157
) {
158158
const ethers = require("ethers") as typeof EthersT;
159+
const ordinal = require("ordinal") as typeof OrdinalT;
159160
const parsedLog = (
160161
chaiUtils.flag(context, "contract").interface as Interface
161162
).parseLog(log);

packages/hardhat-chai-matchers/src/internal/reverted/revertedWithCustomError.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type EthersT from "ethers";
2+
import type OrdinalT from "ordinal";
23

34
import { AssertionError } from "chai";
4-
import ordinal from "ordinal";
55

66
import {
77
ASSERTION_ABORTED,
@@ -191,6 +191,7 @@ export async function revertedWithCustomErrorWithArgs(
191191
expectedArgs: any[],
192192
ssfi: Ssfi
193193
) {
194+
const ordinal = require("ordinal") as typeof OrdinalT;
194195
const negated = false; // .withArgs cannot be negated
195196
const assert = buildAssert(negated, ssfi);
196197

0 commit comments

Comments
 (0)