Replace CommonJS-only dependencies with inline ESM code
- Dominant language
- JavaScript
- Stars
- 15.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
## Problem
When using mathjs in an Angular project (and likely other modern ESM-first bundlers), the following warnings are emitted during the build:
```
▲ [WARNING] Module 'seedrandom' used by 'node_modules/mathjs/lib/esm/function/probability/util/seededRNG.js' is not ESM
▲ [WARNING] Module 'escape-latex' used by 'node_modules/mathjs/lib/esm/utils/latex.js' is not ESM
▲ [WARNING] Module 'javascript-natural-sort' used by 'node_modules/mathjs/lib/esm/function/relational/compareNatural.js' is not ESM
▲ [WARNING] Module 'tiny-emitter' used by 'node_modules/mathjs/lib/esm/utils/emitter.js' is not ESM
```
> CommonJS or AMD dependencies can cause optimization bailouts.
> For more information see: https://angular.dev/tools/cli/build#configuring-commonjs-dependencies
## Proposal
All four of these dependencies are tiny libraries that haven't been updated in 7+ years:
| Package | Last publish | Size |
|---|---|---|
| `seedrandom` | 7 years ago | small |
| `escape-latex` | 7 years ago | small |
| `javascript-natural-sort` | 9 years ago | small |
| `tiny-emitter` | 7 years ago | small |
Since they are unmaintained and unlikely to ever ship ESM builds, I'd suggest inlining their code directly into mathjs as proper ESM modules. This would:
1. Eliminate the CommonJS warnings for Angular/esbuild/Vite users
2. Allow tree-shaking to work properly on this code
3. Remove external dependencies that are effectively abandoned
I'll follow up with PRs to inline each of these.
Contributor guide
Assessment
This issue has not been assessed yet.