Skip to content

Commit ba50e62

Browse files
fix: browser compatibility checks (#5288)
### Description This PR enhances the ESLint configuration to restrict the usage of Node.js built-in modules across the codebase. This is particularly important for the SDK package which needs to maintain browser compatibility for frontend integrations. Key changes: - Added comprehensive ESLint rules to prevent usage of Node.js specific modules (fs, path, crypto, etc.) - Updated error messages to guide developers towards environment-agnostic alternatives. (alternatives can be mentioned later on) - Created a separate ESLint config for the Solidity package - Excluded test files and AWS-related code from these restrictions ### Drive-by changes - Added ESLint dependency to solidity/package.json - Removed redundant eslint-disable comments from test files - Updated lint script in solidity/package.json to use the new config ### Related issues #5277 ### Backward compatibility Yes. These changes only affect development-time linting and do not impact runtime behavior. ### Testing Manual testing: - Verified ESLint rules correctly flag Node.js built-in module imports - Confirmed test files in excluded directories are not affected - Validated lint commands work as expected in both root and solidity packages --------- Co-authored-by: Morteza Shojaei <[email protected]>
1 parent bed81f7 commit ba50e62

File tree

8 files changed

+114
-7
lines changed

8 files changed

+114
-7
lines changed

.changeset/red-games-agree.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperlane-xyz/sdk': patch
3+
'@hyperlane-xyz/core': patch
4+
---
5+
6+
Added ESLint configuration and dependency to enforce Node.js module restrictions

eslint.config.mjs

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ export default [
8282
name: 'console',
8383
message: 'Please use a logger and/or the utils package assert',
8484
},
85-
{
86-
name: 'fs',
87-
message: 'Avoid use of node-specific libraries',
88-
},
8985
],
9086

9187
'@typescript-eslint/ban-ts-comment': ['off'],
@@ -112,4 +108,98 @@ export default [
112108
'jest/valid-expect': 'error',
113109
},
114110
},
111+
112+
{
113+
files: ['**/*.ts', '**/*.js', '**/*.mjs'],
114+
ignores: ['**/aws/**/*', '**/test/**/*', '**/*.test.ts'],
115+
rules: {
116+
'no-restricted-imports': [
117+
'error',
118+
{
119+
paths: [
120+
{
121+
name: 'fs',
122+
message:
123+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
124+
},
125+
{
126+
name: 'path',
127+
message:
128+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
129+
},
130+
{
131+
name: 'child_process',
132+
message:
133+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
134+
},
135+
{
136+
name: 'os',
137+
message:
138+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
139+
},
140+
{
141+
name: 'process',
142+
message:
143+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
144+
},
145+
{
146+
name: 'http',
147+
message:
148+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
149+
},
150+
{
151+
name: 'https',
152+
message:
153+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
154+
},
155+
{
156+
name: 'net',
157+
message:
158+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
159+
},
160+
{
161+
name: 'dgram',
162+
message:
163+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
164+
},
165+
{
166+
name: 'dns',
167+
message:
168+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
169+
},
170+
{
171+
name: 'crypto',
172+
message:
173+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
174+
},
175+
{
176+
name: 'tls',
177+
message:
178+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
179+
},
180+
{
181+
name: 'cluster',
182+
message:
183+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
184+
},
185+
{
186+
name: 'stream',
187+
message:
188+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
189+
},
190+
{
191+
name: 'vm',
192+
message:
193+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
194+
},
195+
{
196+
name: 'readline',
197+
message:
198+
'Avoid Node.js built-in modules in cross-platform code. Use environment-agnostic alternatives.',
199+
},
200+
],
201+
},
202+
],
203+
},
204+
},
115205
];

solidity/eslint.config.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import MonorepoDefaults from '../eslint.config.mjs';
2+
3+
export default [
4+
...MonorepoDefaults,
5+
{
6+
ignores: [
7+
'./test/**/*',
8+
'./dist/**/*',
9+
'.solcover.js',
10+
],
11+
},
12+
];

solidity/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@typechain/hardhat": "^9.1.0",
2121
"@types/node": "^18.14.5",
2222
"chai": "^4.5.0",
23+
"eslint": "^9.15.0",
2324
"ethereum-waffle": "^4.0.10",
2425
"ethers": "^5.7.2",
2526
"hardhat": "^2.22.2",

typescript/sdk/src/ism/metadata/aggregation.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-restricted-imports */
21
import { expect } from 'chai';
32
import { ethers } from 'ethers';
43
import { existsSync, readFileSync, readdirSync } from 'fs';

typescript/sdk/src/ism/metadata/multisig.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-restricted-imports */
21
import { expect } from 'chai';
32
import { existsSync, readFileSync, readdirSync } from 'fs';
43

typescript/sdk/src/warp/WarpCore.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-restricted-imports */
21
import { expect } from 'chai';
32
import fs from 'fs';
43
import sinon from 'sinon';

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7379,6 +7379,7 @@ __metadata:
73797379
"@typechain/hardhat": "npm:^9.1.0"
73807380
"@types/node": "npm:^18.14.5"
73817381
chai: "npm:^4.5.0"
7382+
eslint: "npm:^9.15.0"
73827383
ethereum-waffle: "npm:^4.0.10"
73837384
ethers: "npm:^5.7.2"
73847385
fx-portal: "npm:^1.0.3"

0 commit comments

Comments
 (0)