Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 849772e

Browse files
authored
Reapply "refactor!: Synchronize dev toolchain with module template and core monorepo (#420)" (#423) (#426)
This reverts commit c591a5f (Reapplies 5391380) <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? Are there any issues or other links reviewers should consult to understand this pull request better? For instance: * Fixes #12345 * See: #67890 --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Overhauls the dev toolchain: upgrades ESLint to v9 with new configs/plugins, moves to TypeScript 5.x, adds TypeDoc/depcheck/ts-bridge/ATTW tooling, updates Prettier to v3, and refreshes dependencies. > > - **Dev toolchain sync/upgrade** > - **ESLint 9**: Bump core and configs (MetaMask v14), migrate plugins/resolvers (e.g., `eslint-plugin-import-x`, `eslint-import-resolver-typescript`), and update related utilities. > - **TypeScript 5.x**: Update TypeScript, `typescript-eslint` (v8), `ts-node`, and supporting packages. > - **Formatting & docs**: Upgrade **Prettier** to v3 and `prettier-plugin-packagejson`; add **TypeDoc**. > - **New tooling**: Add `@arethetypeswrong/cli`, `@ts-bridge/cli`, and **depcheck** for dependency hygiene. > - **Dependencies**: Broad dependency updates and lockfile refresh to align with core template. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5ef56a4. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 1f26857 commit 849772e

28 files changed

+4501
-3757
lines changed

.depcheckrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"ignores": [
3+
"@lavamoat/allow-scripts",
4+
"@lavamoat/preinstall-always-fail",
5+
"@metamask/auto-changelog",
6+
"@metamask/eslint-config",
7+
"@metamask/eslint-config-*",
8+
"@types/*",
9+
"@yarnpkg/types",
10+
"eslint-config-*",
11+
"eslint-import-resolver-typescript",
12+
"eslint-plugin-*",
13+
"prettier-plugin-packagejson",
14+
"ts-node",
15+
"typedoc",
16+
"typescript-eslint"
17+
]
18+
}

.eslintrc.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
dist/
33
coverage/
4+
docs/
45

56
# Logs
67
logs

.yarnrc.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
compressionLevel: mixed
2+
3+
enableGlobalCache: false
4+
15
enableScripts: false
26

3-
enableTelemetry: 0
7+
enableTelemetry: false
48

59
logFilters:
610
- code: YN0004
@@ -11,5 +15,3 @@ nodeLinker: node-modules
1115
plugins:
1216
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
1317
spec: "https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js"
14-
15-
yarnPath: .yarn/releases/yarn-3.2.1.cjs

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- **BREAKING:** Distribute separate CommonJS and ESM files ([#420](https://github.com/MetaMask/eth-json-rpc-middleware/pull/420))
13+
- Use the `exports` field of `package.json`, breaking some previously valid imports.
14+
1015
## [19.0.1]
1116

1217
### Changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Ethereum-related middleware for [`json-rpc-engine`](https://github.com/MetaMask/
44

55
See tests for usage details.
66

7+
## Installation
8+
9+
`yarn add @metamask/eth-json-rpc-middleware`
10+
11+
or
12+
13+
`npm install @metamask/eth-json-rpc-middleware`
14+
715
## Running Tests
816

917
```bash

eslint.config.mjs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import base, { createConfig } from '@metamask/eslint-config';
2+
import jest from '@metamask/eslint-config-jest';
3+
import nodejs from '@metamask/eslint-config-nodejs';
4+
import typescript from '@metamask/eslint-config-typescript';
5+
6+
const config = createConfig([
7+
{
8+
ignores: ['dist/', 'docs/', '.yarn/'],
9+
},
10+
11+
{
12+
extends: base,
13+
14+
languageOptions: {
15+
sourceType: 'module',
16+
parserOptions: {
17+
tsconfigRootDir: import.meta.dirname,
18+
project: ['./tsconfig.json'],
19+
},
20+
},
21+
22+
settings: {
23+
'import-x/extensions': ['.js', '.mjs'],
24+
},
25+
},
26+
27+
{
28+
files: ['**/*.ts'],
29+
extends: typescript,
30+
rules: {
31+
// TODO: resolve warnings and remove to make into errors
32+
'@typescript-eslint/consistent-type-definitions': 'off',
33+
'@typescript-eslint/explicit-function-return-type': 'warn',
34+
'@typescript-eslint/naming-convention': 'off',
35+
'@typescript-eslint/prefer-nullish-coalescing': 'warn',
36+
'@typescript-eslint/prefer-optional-chain': 'warn',
37+
'@typescript-eslint/restrict-template-expressions': 'off',
38+
'id-denylist': 'off',
39+
'id-length': 'off',
40+
'import/no-nodejs-modules': 'off',
41+
'jsdoc/match-description': 'warn',
42+
'jsdoc/no-types': 'warn',
43+
'jsdoc/require-hyphen-before-param-description': 'warn',
44+
'jsdoc/require-jsdoc': 'off',
45+
'jsdoc/require-param-description': 'warn',
46+
'no-restricted-globals': 'off',
47+
'no-restricted-syntax': 'warn',
48+
},
49+
},
50+
51+
{
52+
files: ['**/*.js', '**/*.cjs'],
53+
extends: nodejs,
54+
55+
languageOptions: {
56+
sourceType: 'script',
57+
},
58+
},
59+
60+
{
61+
files: ['./test/**/*', '**/*.test.ts', '**/*.test.js'],
62+
extends: [jest, nodejs],
63+
rules: {
64+
'@typescript-eslint/no-floating-promises': 'warn',
65+
'@typescript-eslint/unbound-method': 'off',
66+
'jest/expect-expect': [
67+
'error',
68+
{
69+
assertFunctionNames: [
70+
'expect',
71+
'expectProviderRequestNotToHaveBeenMade',
72+
],
73+
},
74+
],
75+
'jsdoc/check-param-names': 'off',
76+
'jsdoc/require-jsdoc': 'off',
77+
'jsdoc/require-param': 'off',
78+
},
79+
},
80+
]);
81+
82+
export default config;

package.json

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,51 @@
11
{
22
"name": "@metamask/eth-json-rpc-middleware",
33
"version": "19.0.1",
4-
"description": "Ethereum-related json-rpc-engine middleware.",
4+
"description": "Ethereum-related json-rpc-engine middleware",
5+
"homepage": "https://github.com/MetaMask/eth-json-rpc-middleware#readme",
6+
"bugs": {
7+
"url": "https://github.com/MetaMask/eth-json-rpc-middleware/issues"
8+
},
59
"repository": {
610
"type": "git",
711
"url": "https://github.com/MetaMask/eth-json-rpc-middleware.git"
812
},
913
"license": "ISC",
10-
"main": "./dist/index.js",
11-
"browser": {
12-
"btoa": false,
13-
"node-fetch": false
14+
"sideEffects": false,
15+
"exports": {
16+
".": {
17+
"import": {
18+
"types": "./dist/index.d.mts",
19+
"default": "./dist/index.mjs"
20+
},
21+
"require": {
22+
"types": "./dist/index.d.cts",
23+
"default": "./dist/index.cjs"
24+
}
25+
},
26+
"./package.json": "./package.json"
1427
},
15-
"types": "./dist/index.d.ts",
28+
"main": "./dist/index.cjs",
29+
"module": "./dist/index.mjs",
30+
"types": "./dist/index.d.cts",
1631
"files": [
17-
"dist/"
32+
"dist"
1833
],
1934
"scripts": {
20-
"build": "tsc --project tsconfig.build.json",
35+
"build": "ts-bridge --project tsconfig.build.json --clean",
2136
"build:clean": "rimraf dist && yarn build",
22-
"lint": "yarn lint:eslint && yarn lint:misc --check",
23-
"lint:eslint": "eslint . --cache --ext js,ts",
24-
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
25-
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
37+
"build:docs": "typedoc",
38+
"lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
39+
"lint:changelog": "auto-changelog validate --prettier",
40+
"lint:constraints": "yarn constraints",
41+
"lint:dependencies": "depcheck && yarn dedupe --check",
42+
"lint:dependencies:fix": "depcheck && yarn dedupe",
43+
"lint:eslint": "eslint . --cache",
44+
"lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies:fix && yarn lint:changelog",
45+
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
2646
"prepack": "./scripts/prepack.sh",
2747
"test": "jest && yarn build:clean && yarn test:types",
28-
"test:types": "tsd --files 'src/**/*.test-d.ts'",
48+
"test:types": "tsd --files 'src/**/*.test-d.ts' && attw --pack",
2949
"test:watch": "jest --watch"
3050
},
3151
"dependencies": {
@@ -36,46 +56,47 @@
3656
"@metamask/rpc-errors": "^7.0.2",
3757
"@metamask/superstruct": "^3.1.0",
3858
"@metamask/utils": "^11.7.0",
39-
"@types/bn.js": "^5.1.5",
40-
"bn.js": "^5.2.1",
4159
"klona": "^2.0.6",
4260
"pify": "^5.0.0",
4361
"safe-stable-stringify": "^2.4.3"
4462
},
4563
"devDependencies": {
46-
"@jest/globals": "^27.5.1",
64+
"@arethetypeswrong/cli": "^0.15.3",
4765
"@lavamoat/allow-scripts": "^3.0.4",
48-
"@metamask/auto-changelog": "^3.1.0",
66+
"@metamask/auto-changelog": "^3.4.4",
4967
"@metamask/error-reporting-service": "^2.0.0",
50-
"@metamask/eslint-config": "^12.1.0",
51-
"@metamask/eslint-config-jest": "^12.1.0",
52-
"@metamask/eslint-config-nodejs": "^12.1.0",
53-
"@metamask/eslint-config-typescript": "^12.1.0",
68+
"@metamask/eslint-config": "^14.0.0",
69+
"@metamask/eslint-config-jest": "^14.0.0",
70+
"@metamask/eslint-config-nodejs": "^14.0.0",
71+
"@metamask/eslint-config-typescript": "^14.0.0",
5472
"@metamask/network-controller": "^24.2.1",
55-
"@types/btoa": "^1.2.3",
73+
"@ts-bridge/cli": "^0.6.3",
5674
"@types/jest": "^27.4.1",
57-
"@types/node": "^18.16",
75+
"@types/node": "^18.18",
5876
"@types/pify": "^5.0.2",
59-
"@typescript-eslint/eslint-plugin": "^5.42.1",
60-
"@typescript-eslint/parser": "^5.42.1",
61-
"eslint": "^8.44.0",
62-
"eslint-config-prettier": "^8.1.0",
63-
"eslint-plugin-import": "^2.27.5",
64-
"eslint-plugin-jest": "^27.1.5",
65-
"eslint-plugin-jsdoc": "^39.6.2",
66-
"eslint-plugin-n": "^15.7.0",
67-
"eslint-plugin-prettier": "^4.2.1",
68-
"eslint-plugin-promise": "^6.1.1",
77+
"@yarnpkg/types": "^4.0.1",
78+
"depcheck": "^1.4.3",
79+
"eslint": "^9.11.0",
80+
"eslint-config-prettier": "^9.1.0",
81+
"eslint-import-resolver-typescript": "^3.6.3",
82+
"eslint-plugin-import-x": "^4.3.0",
83+
"eslint-plugin-jest": "^28.8.3",
84+
"eslint-plugin-jsdoc": "^50.2.4",
85+
"eslint-plugin-n": "^17.10.3",
86+
"eslint-plugin-prettier": "^5.2.1",
87+
"eslint-plugin-promise": "^7.1.0",
6988
"jest": "^27.5.1",
70-
"prettier": "^2.2.1",
71-
"prettier-plugin-packagejson": "^2.2.11",
89+
"prettier": "^3.3.3",
90+
"prettier-plugin-packagejson": "^2.5.8",
7291
"rimraf": "^3.0.2",
7392
"ts-jest": "^27.1.4",
74-
"ts-node": "^10.7.0",
93+
"ts-node": "^10.9.1",
7594
"tsd": "^0.31.2",
76-
"typescript": "~4.8.4"
95+
"typedoc": "^0.24.8",
96+
"typescript": "~5.2.2",
97+
"typescript-eslint": "^8.7.0"
7798
},
78-
"packageManager": "yarn@3.2.1",
99+
"packageManager": "yarn@4.1.1",
79100
"engines": {
80101
"node": "^18.16 || ^20 || >=22"
81102
},
@@ -87,7 +108,8 @@
87108
"allowScripts": {
88109
"@lavamoat/preinstall-always-fail": false,
89110
"@metamask/eth-sig-util>ethereumjs-util>ethereum-cryptography>keccak": false,
90-
"@metamask/eth-sig-util>ethereumjs-util>ethereum-cryptography>secp256k1": false
111+
"@metamask/eth-sig-util>ethereumjs-util>ethereum-cryptography>secp256k1": false,
112+
"eslint-plugin-import-x>unrs-resolver": false
91113
}
92114
}
93115
}

src/block-cache.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ class BlockCacheStrategy {
110110
)
111111
) {
112112
if (
113-
!result ||
114-
!result.blockHash ||
113+
!result?.blockHash ||
115114
result.blockHash ===
116115
'0x0000000000000000000000000000000000000000000000000000000000000000'
117116
) {
@@ -215,7 +214,6 @@ export function createBlockCacheMiddleware({
215214
'No cache stored under block number %o, carrying request forward',
216215
requestedBlockNumber,
217216
);
218-
// eslint-disable-next-line n/callback-return
219217
await next();
220218

221219
// add result to cache

src/block-ref-rewrite.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export function createBlockRefRewriteMiddleware({
4040
// rewrite blockRef to block-tracker's block number
4141
const latestBlockNumber = await blockTracker.getLatestBlock();
4242
if (Array.isArray(req.params)) {
43-
// eslint-disable-next-line require-atomic-updates
4443
req.params[blockRefIndex] = latestBlockNumber;
4544
}
4645
return next();

0 commit comments

Comments
 (0)