MetaMask / MetaMask/metamask-module-template

Consider preventing the use of Node.js built-in modules and globals by default

Open
#127 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
31
Forks
18
Avg merge
11h 39m
Merged PRs (30d)
1

Description

Most modules we develop need to be browser-compatible. The use of Node.js built-in modules means that some kind of polyfill is required for those modules. Usually this means using polyfills like `crypto-browserify` (hasn't been updated in years, and [the bundle is quite large](https://bundlephobia.com/package/crypto-browserify@3.12.0)), `buffer`, etc., while there are often better alternatives available that have a much smaller bundle size (e.g., the `noble` and `scure` libraries), which offer compatibility with both Node.js and browsers by default.

Working with `Uint8Array` and `bigint` instead of `Buffer` and `BN.js` is quite easy now, since we have a lot of util functions in `@metamask/utils`. Most other `Buffer`-specific functions, like `writeUint...()` can be replaced with a `DataView` (available on browsers and Node.js). See MetaMask/key-tree#83 for example.

For that reason I propose we add some ESLint rules that prevent the use of built-in Node.js modules (mainly `crypto`), and Node.js-specific globals (mainly `Buffer`).

There are some valid use-cases for using Node.js built-in modules (like Node.js-only modules interacting with the file system), but projects needing it can simply remove or disable those rules.

Contributor guide

No contributing guide indexed for this repository

Research direction

No specific files or tests are named. Start by locating the template's ESLint configuration and reviewing how modules and globals are currently checked; determine how Node.js-only projects can disable the rules. Done means the default configuration rejects the proposed built-ins and globals while documenting the valid-use escape hatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, node.js
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.