Skip to content

Commit b63714e

Browse files
authored
Convert packages from CJS to ESM (#3531)
### Description - Reconfigure tsconfig and package.json for the utils, core, sdk, and helloworld packages - Update imports to use ESM syntax - Add patch for typechain to address [issue 898](dethcrypto/TypeChain#898) ### Drive-by changes Improve package Readme content ### Related issues Fixes #1354 ### Backward compatibility No: package consumers using CJS will need to modify their imports or update to ESM. See [this popular gist](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package) for details. ### Testing - [x] CI test coverage which invokes a lot of code via the CLI e2e - [x] Manually test in Warp UI by copying packages - [x] Publish beta packages and test in a few popular bundlers
1 parent 040641b commit b63714e

File tree

327 files changed

+2558
-2187
lines changed

Some content is hidden

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

327 files changed

+2558
-2187
lines changed

.changeset/kind-panthers-clap.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@hyperlane-xyz/helloworld': minor
3+
'@hyperlane-xyz/utils': minor
4+
'@hyperlane-xyz/cli': minor
5+
'@hyperlane-xyz/sdk': minor
6+
'@hyperlane-xyz/core': minor
7+
---
8+
9+
Convert all public hyperlane npm packages from CJS to pure ESM

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
dist
3-
coverage
3+
coverage
4+
*.cts

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"importOrder": ["^@hyperlane-xyz/(.*)$", "^../(.*)$", "^./(.*)$"],
1818
"importOrderSeparation": true,
1919
"importOrderSortSpecifiers": true,
20+
"importOrderParserPlugins": ["importAssertions", "typescript", "jsx"],
2021
"plugins": ["prettier-plugin-solidity", "@trivago/prettier-plugin-sort-imports"]
2122
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/dist/codegen/createBarrelFiles.js b/dist/codegen/createBarrelFiles.js
2+
index 4bf574d7f6701bc5a8fcb2c281b5c63f31923e79..7f9cbdbd0491d4fa6338a10b23d06c2665c9d968 100644
3+
--- a/dist/codegen/createBarrelFiles.js
4+
+++ b/dist/codegen/createBarrelFiles.js
5+
@@ -38,15 +38,13 @@ function createBarrelFiles(paths, { typeOnly, postfix = '', moduleSuffix = '' })
6+
const namespacesExports = nestedDirs
7+
.map((p) => {
8+
const namespaceIdentifier = (0, normalizeDirName_1.normalizeDirName)(p);
9+
+ const fromFilePath = moduleSuffix ? `'./${p}/index${moduleSuffix}'` : `'./${p}'`
10+
if (typeOnly)
11+
return [
12+
- `import type * as ${namespaceIdentifier} from './${p}';`,
13+
+ `import type * as ${namespaceIdentifier} from ${fromFilePath};`,
14+
`export type { ${namespaceIdentifier} };`,
15+
].join('\n');
16+
- if (moduleSuffix) {
17+
- return `export * as ${namespaceIdentifier} from './${p}/index${moduleSuffix}';`;
18+
- }
19+
- return `export * as ${namespaceIdentifier} from './${p}';`;
20+
+ return `export * as ${namespaceIdentifier} from ${fromFilePath};`;
21+
})
22+
.join('\n');
23+
const contracts = (fileReexports[path] || []).sort();

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ WORKDIR /hyperlane-monorepo
44

55
RUN apk add --update --no-cache git g++ make py3-pip jq
66

7-
RUN yarn set version 4.0.1
7+
RUN yarn set version 4.0.2
88

99
# Copy package.json and friends
1010
COPY package.json yarn.lock .yarnrc.yml ./
1111
COPY .yarn/plugins ./.yarn/plugins
1212
COPY .yarn/releases ./.yarn/releases
13+
COPY .yarn/patches ./.yarn/patches
1314
COPY typescript/utils/package.json ./typescript/utils/
1415
COPY typescript/sdk/package.json ./typescript/sdk/
1516
COPY typescript/helloworld/package.json ./typescript/helloworld/

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"version": "0.0.0",
55
"devDependencies": {
66
"@trivago/prettier-plugin-sort-imports": "^4.2.1",
7-
"@typescript-eslint/eslint-plugin": "^5.62.0",
8-
"@typescript-eslint/parser": "^5.62.0",
9-
"eslint": "^8.43.0",
10-
"eslint-config-prettier": "^8.8.0",
7+
"@typescript-eslint/eslint-plugin": "^7.4.0",
8+
"@typescript-eslint/parser": "^7.4.0",
9+
"eslint": "^8.57.0",
10+
"eslint-config-prettier": "^9.1.0",
1111
"husky": "^8.0.0",
1212
"lint-staged": "^12.4.3",
13-
"prettier": "^2.8.8"
13+
"prettier": "^2.8.8",
14+
"tsx": "^4.7.1"
1415
},
1516
"dependencies": {
1617
"@changesets/cli": "^2.26.2"
@@ -42,6 +43,8 @@
4243
"recursive-readdir": "^2.2.3",
4344
"underscore": "^1.13",
4445
"undici": "^5.11",
45-
"@trivago/prettier-plugin-sort-imports/@babel/parser": "^7.22.7"
46+
"@trivago/prettier-plugin-sort-imports/@babel/parser": "^7.22.7",
47+
"@typechain/ethers-v5": "11.1.2",
48+
"typechain@npm:^8.0.0": "patch:typechain@npm%3A8.3.2#~/.yarn/patches/typechain-npm-8.3.2-b02e27439e.patch"
4649
}
4750
}

solidity/README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# Hyperlane Solidity
1+
# Hyperlane Core
22

3-
On-chain implementations of Hyperlane in Solidity.
3+
Hyperlane Core contains the contracts and typechain artifacts for the Hyperlane implementation for EVM.
44

5-
## Setup
5+
## Install
66

7-
- `yarn install`
7+
```bash
8+
# Install with NPM
9+
npm install @hyperlane-xyz/utils
810

9-
## Build
11+
# Or with Yarn
12+
yarn add @hyperlane-xyz/utils
13+
```
1014

11-
- `yarn build`
15+
Note, this package uses [ESM Modules](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package)
1216

13-
## Test
17+
## License
1418

15-
- `yarn test`
19+
Apache 2.0

solidity/hardhat.config.ts renamed to solidity/hardhat.config.cts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ module.exports = {
2424
outDir: './types',
2525
target: 'ethers-v5',
2626
alwaysGenerateOverloads: true,
27+
node16Modules: true,
2728
},
2829
mocha: {
2930
bail: true,
31+
import: 'tsx',
3032
},
3133
};

solidity/package.json

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,57 +11,68 @@
1111
},
1212
"devDependencies": {
1313
"@layerzerolabs/solidity-examples": "^1.1.0",
14-
"@nomiclabs/hardhat-ethers": "^2.2.1",
14+
"@nomiclabs/hardhat-ethers": "^2.2.3",
1515
"@nomiclabs/hardhat-waffle": "^2.0.6",
16-
"@typechain/ethers-v5": "^10.0.0",
17-
"@typechain/hardhat": "^6.0.0",
16+
"@typechain/ethers-v5": "^11.1.2",
17+
"@typechain/hardhat": "^9.1.0",
1818
"chai": "^4.3.6",
1919
"ethereum-waffle": "^4.0.10",
2020
"ethers": "^5.7.2",
21-
"hardhat": "^2.19.0",
21+
"hardhat": "^2.22.2",
2222
"hardhat-gas-reporter": "^1.0.9",
2323
"prettier": "^2.8.8",
2424
"prettier-plugin-solidity": "^1.1.3",
2525
"solhint": "^4.0.0",
2626
"solhint-plugin-prettier": "^0.0.5",
2727
"solidity-coverage": "^0.8.3",
2828
"ts-generator": "^0.1.1",
29-
"typechain": "^8.3.2",
30-
"typescript": "5.1.6"
29+
"ts-node": "^10.8.0",
30+
"typechain": "patch:typechain@npm%3A8.3.2#~/.yarn/patches/typechain-npm-8.3.2-b02e27439e.patch",
31+
"typescript": "5.3.3"
3132
},
3233
"directories": {
3334
"test": "test"
3435
},
36+
"type": "module",
37+
"exports": {
38+
".": "./dist/index.js",
39+
"./mailbox": "./dist/contracts/Mailbox.js",
40+
"./buildArtifact.json": "./buildArtifact.json",
41+
"./contracts": "./contracts"
42+
},
43+
"types": "./dist/index.d.ts",
3544
"files": [
3645
"/buildArtifact.json",
3746
"/dist",
38-
"/contracts",
39-
"/interfaces",
40-
"/docs"
47+
"/contracts"
4148
],
49+
"engines": {
50+
"node": ">=16"
51+
},
4252
"homepage": "https://www.hyperlane.xyz",
53+
"repository": "https://github.com/hyperlane-xyz/hyperlane-monorepo",
4354
"keywords": [
4455
"Hyperlane",
4556
"Solidity"
4657
],
4758
"license": "Apache-2.0",
48-
"main": "dist/index.js",
49-
"repository": "https://github.com/hyperlane-xyz/hyperlane-monorepo",
5059
"scripts": {
51-
"build": "hardhat compile && ./exportBuildArtifact.sh && tsc",
60+
"build": "yarn hardhat-esm compile && ./exportBuildArtifact.sh && tsc",
5261
"lint": "solhint contracts/**/*.sol",
53-
"clean": "hardhat clean && rm -rf ./dist ./cache ./types ./coverage",
62+
"clean": "yarn hardhat-esm clean && rm -rf ./dist ./cache ./types ./coverage ./out ./forge-cache",
5463
"coverage": "./coverage.sh",
5564
"docs": "forge doc",
56-
"storage": "./storage.sh",
65+
"hardhat-esm": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts",
5766
"prettier": "prettier --write ./contracts ./test",
58-
"test": "hardhat test && forge test -vvv",
59-
"test:ci": "hardhat test && forge test --no-match-test testFork -vvv",
67+
"test": "yarn hardhat-esm test && yarn test:forge",
68+
"test:hardhat": "yarn hardhat-esm test",
69+
"test:forge": "forge test -vvv",
70+
"test:ci": "yarn test:hardhat && yarn test:forge --no-match-test testFork",
6071
"gas": "forge snapshot",
6172
"gas-ci": "yarn gas --check --tolerance 2 || (echo 'Manually update gas snapshot' && exit 1)",
62-
"slither": "slither ."
73+
"slither": "slither .",
74+
"storage": "./storage.sh"
6375
},
64-
"types": "dist/index.d.ts",
6576
"peerDependencies": {
6677
"@ethersproject/abi": "*",
6778
"@ethersproject/providers": "*",

solidity/test/merkle.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { expect } from 'chai';
2-
import { ethers } from 'hardhat';
2+
import { utils } from 'ethers';
33

4-
import merkleTestCases from '../../vectors/merkle.json';
4+
import merkleTestCases from '../../vectors/merkle.json' assert { type: 'json' };
55
import { TestMerkle, TestMerkle__factory } from '../types';
66

7+
import { getSigner } from './signer';
8+
79
describe('Merkle', async () => {
810
for (const testCase of merkleTestCases) {
911
const { testName, leaves, expectedRoot, proofs } = testCase;
@@ -12,14 +14,14 @@ describe('Merkle', async () => {
1214
let merkle: TestMerkle;
1315

1416
before(async () => {
15-
const [signer] = await ethers.getSigners();
17+
const signer = await getSigner();
1618

1719
const merkleFactory = new TestMerkle__factory(signer);
1820
merkle = await merkleFactory.deploy();
1921

2022
//insert the leaves
2123
for (const leaf of leaves) {
22-
const leafHash = ethers.utils.hashMessage(leaf);
24+
const leafHash = utils.hashMessage(leaf);
2325
await merkle.insert(leafHash);
2426
}
2527
});

0 commit comments

Comments
 (0)