Skip to content

Commit ff6311d

Browse files
authored
Merge branch 'main' into add-hardhat-markup-plugin-docs
2 parents 8cae245 + 29c3be1 commit ff6311d

File tree

227 files changed

+2670
-1647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2670
-1647
lines changed

.changeset/brave-steaks-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": minor
3+
---
4+
5+
Hardhat's task runner now allows you to override the arguments passed to subtasks.

.changeset/chilly-papayas-dance.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Reduce the amount of ETH sent to the Lock contract in the sample project's deploy script (Thanks @mutedSpectre!)

.changeset/early-parrots-attend.md

-6
This file was deleted.

.changeset/empty-suns-kick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nomiclabs/hardhat-vyper": patch
3+
---
4+
5+
Keep the parent exception when throwing because the compiler list download failed.

.changeset/few-sheep-drive.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Stop colorizing the entire message when an error is printed

.changeset/kind-humans-grow.md

-5
This file was deleted.

.changeset/plenty-comics-bow.md

-5
This file was deleted.

.changeset/slimy-plums-reply.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@nomicfoundation/hardhat-toolbox": patch
3+
"hardhat": minor
4+
---
5+
6+
Added support for writing scripts and tests as ES modules.
7+
8+
To learn how to start using ESM with Hardhat read [this guide](https://hardhat.org/hardhat-runner/docs/advanced/using-esm).

.changeset/stale-garlics-mate.md

-5
This file was deleted.

.github/workflows/hardhat-waffle-ci.yml

-82
This file was deleted.

config/eslint/eslintrc.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports = {
9191
},
9292
{
9393
selector: ["objectLiteralProperty"],
94-
format: null
94+
format: null,
9595
},
9696
{
9797
selector: ["objectLiteralMethod"],
@@ -137,9 +137,12 @@ module.exports = {
137137
"@typescript-eslint/prefer-function-type": "error",
138138
"@typescript-eslint/prefer-namespace-keyword": "error",
139139
"@typescript-eslint/restrict-plus-operands": "error",
140-
"@typescript-eslint/restrict-template-expressions": ["error", {
141-
allowAny: true,
142-
}],
140+
"@typescript-eslint/restrict-template-expressions": [
141+
"error",
142+
{
143+
allowAny: true,
144+
},
145+
],
143146
"@typescript-eslint/strict-boolean-expressions": [
144147
"error",
145148
{
@@ -219,8 +222,11 @@ module.exports = {
219222
},
220223
],
221224
"use-isnan": "error",
222-
"no-restricted-imports": ["error", {
223-
patterns: ["hardhat/src", "@nomiclabs/*/src"]
224-
}],
225+
"no-restricted-imports": [
226+
"error",
227+
{
228+
patterns: ["hardhat/src", "@nomiclabs/*/src"],
229+
},
230+
],
225231
},
226232
};

docs/redirects.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const customRedirects = [
7878
},
7979
{
8080
source: "/migrate-from-waffle",
81-
destination: "/hardhat-chai-matchers/docs/migrate-from-waffle",
81+
destination: "/hardhat-runner/docs/guides/migrating-from-hardhat-waffle",
8282
permanent: false
8383
},
8484
{

docs/src/content/hardhat-chai-matchers/docs/migrate-from-waffle.md

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Migrating from Waffle
22

3-
This page explains how to migrate from Waffle to Hardhat Chai Matchers, and the advantages of doing it. Migrating should only take a few minutes.
3+
If you want to replace Waffle with Hardhat Chai Matchers, we recommend you [migrate to the Hardhat Toolbox](/hardhat-runner/docs/guides/migrating-from-hardhat-waffle). If for some reason you want to migrate without using the Toolbox, read on.
44

55
## How to migrate
66

@@ -90,38 +90,8 @@ The `@nomicfoundation/hardhat-chai-matchers` plugin is meant to be a drop-in rep
9090

9191
::::
9292

93-
4. If you were not importing the `@nomiclabs/hardhat-ethers` plugin explicitly (because the Hardhat Waffle plugin already imported it), then add it to your config:
94-
95-
::::tabsgroup{options=TypeScript,JavaScript}
96-
97-
:::tab{value=TypeScript}
98-
99-
```ts
100-
import "@nomiclabs/hardhat-ethers";
101-
```
102-
103-
:::
104-
105-
:::tab{value=JavaScript}
106-
107-
```js
108-
require("@nomiclabs/hardhat-ethers");
109-
```
110-
111-
:::
112-
113-
::::
114-
11593
:::tip
11694

117-
Looking for a replacement of Waffle's `loadFixture`? You can find our version of it in [Hardhat Network Helpers](/hardhat-network-helpers/docs/reference#fixtures).
95+
Looking for a replacement for Waffle's `loadFixture`? You can find our version of it in [Hardhat Network Helpers](/hardhat-network-helpers/docs/reference#fixtures).
11896

11997
:::
120-
121-
## Why migrate?
122-
123-
The Hardhat Chai Matchers are compatible with Waffle's API and offer several advantages:
124-
125-
- **More features**: the Hardhat Chai Matchers include new matchers, like [`.revertedWithCustomError`](./reference#.revertedwithcustomerror) and [`.revertedWithPanic`](/chai-matchers/reference.md#.revertedwithpanic), which let you perform better assertions of a transaction's revert reason.
126-
- **Support for native BigInts**: Besides numbers and ethers’s BigNumbers, you can also use JavaScript's native BigInts in your assertions, which means being able to do things like `expect(await token.totalSupply()).to.equal(10n**18n)` instead of `expect(await token.totalSupply()).to.equal(ethers.BigNumber.from("1000000000000000000"))`.
127-
- **More reliable**: Several problems and minor bugs in Waffle's matchers are fixed in the Hardhat Chai Matchers.

docs/src/content/hardhat-runner/docs/advanced/_dirinfo.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ order:
1111
- /flattening
1212
- href: /vscode-tests
1313
title: Running tests in VS Code
14+
- /using-esm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Using ES modules
2+
3+
Node.js projects can use one of two module systems: CommonJS and ES Modules (ESM). Hardhat was designed mainly with CommonJS in mind, but in the last years adoption of ESM has been growing.
4+
5+
This guide explains where you can use ESM in your Hardhat project and how to do it.
6+
7+
## Hardhat support for ES modules
8+
9+
You can write your scripts and tests as both CommonJS and ES modules. However, your Hardhat config, and any file imported by it, **must** be CommonJS modules.
10+
11+
If your package uses ESM by default (that is, you have [`"type": "module"`](https://nodejs.org/api/packages.html#type) in your `package.json`), then your Hardhat config file must be named `hardhat.config.cjs`.
12+
13+
Hardhat doesn't support [ESM in TypeScript projects](#esm-and-typescript-projects).
14+
15+
## Using ES Modules in Hardhat
16+
17+
The following sections explain how to use ES modules in new or existing Hardhat projects.
18+
19+
### Starting an ESM-first Hardhat project
20+
21+
If you want to start a Hardhat project that uses ES modules by default, first you have to initialize a Node.js project:
22+
23+
::::tabsgroup{options="npm 7+,npm 6,yarn"}
24+
25+
:::tab{value="npm 7+"}
26+
27+
```
28+
npm init -y
29+
```
30+
31+
:::
32+
33+
:::tab{value="npm 6"}
34+
35+
```
36+
npm init -y
37+
```
38+
39+
:::
40+
41+
:::tab{value="yarn"}
42+
43+
```
44+
yarn init -y
45+
```
46+
47+
:::
48+
49+
::::
50+
51+
Open the `package.json` that was created and add a `"type": "module"` entry. This will make the project use ESM by default.
52+
53+
After that, install Hardhat:
54+
55+
::::tabsgroup{options="npm 7+,npm 6,yarn"}
56+
57+
:::tab{value="npm 7+"}
58+
59+
```
60+
npm install --save-dev hardhat
61+
```
62+
63+
:::
64+
65+
:::tab{value="npm 6"}
66+
67+
```
68+
npm install --save-dev hardhat
69+
```
70+
71+
:::
72+
73+
:::tab{value="yarn"}
74+
75+
```
76+
yarn add --dev hardhat
77+
```
78+
79+
:::
80+
81+
::::
82+
83+
and run `npx hardhat` to create a Hardhat project:
84+
85+
```
86+
888 888 888 888 888
87+
888 888 888 888 888
88+
888 888 888 888 888
89+
8888888888 8888b. 888d888 .d88888 88888b. 8888b. 888888
90+
888 888 "88b 888P" d88" 888 888 "88b "88b 888
91+
888 888 .d888888 888 888 888 888 888 .d888888 888
92+
888 888 888 888 888 Y88b 888 888 888 888 888 Y88b.
93+
888 888 "Y888888 888 "Y88888 888 888 "Y888888 "Y888
94+
95+
Welcome to Hardhat v2.13.0
96+
97+
? What do you want to do? …
98+
▸ Create a JavaScript project
99+
Create a TypeScript project (not available for ESM projects)
100+
Create an empty hardhat.config.cjs
101+
Quit
102+
```
103+
104+
Select the `Create a JavaScript project` option. This will initialize a Hardhat project where the scripts and tests are ES modules, and where the configuration has a `.cjs` extension.
105+
106+
### Migrating a project to ESM
107+
108+
If you have an existing Hardhat project and you want to convert it into an ESM project, follow these steps:
109+
110+
1. Edit your `package.json` and add a `"type": "module"` entry.
111+
2. Rename your `hardhat.config.js` file to `hardhat.config.cjs`.
112+
3. Migrate all your scripts and tests from CommonJS to ESM. Alternatively, you can rename them to have a `.cjs` extension instead of `.js`.
113+
114+
### Adding ESM files to an existing Hardhat project
115+
116+
It's also possible to write ESM scripts and tests without making your whole project ESM by default. To do this, just create your scripts and tests with an `.mjs` extension.
117+
118+
## ESM and TypeScript projects
119+
120+
At the moment, it's not possible to use ESM in TypeScript projects.
121+
122+
Hardhat uses [`ts-node`](https://typestrong.org/ts-node/) to run TypeScript projects, which in turn relies on Node's loader hooks. This is all experimental and the current functionality is not enough for Hardhat's needs.
123+
124+
If you need this feature, please let us know in [this issue](https://github.com/NomicFoundation/hardhat/issues/3385).
125+
126+
## Learn more
127+
128+
To learn more about ES modules in general, check these resources:
129+
130+
- [Node.js docs](https://nodejs.org/api/packages.html)
131+
- [ES modules: A cartoon deep-dive](https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/)
132+
- The [Modules chapter](https://exploringjs.com/impatient-js/ch_modules.html) of "JavaScript for impatient programmers"

0 commit comments

Comments
 (0)