-
Notifications
You must be signed in to change notification settings - Fork 199
Description
Is your feature request related to a problem? Please describe.
Currently (as of v0.19.0), the maxGraph npm package only provides ES modules.
CommonJS support was removed in v0.5.0. At that time, it was only provided as a single bundle file (UMD).
But several users have reported issues when using maxGraph in environments where CommonJS is still the default. For example:
- #790: Jest doesn't use ESM out of the box and requires extra setup:
In applications with large Jest-based test suites written in CommonJS, just adding maxGraph forces a full migration to ESM, which can be a major blocker.
➡️ Example: In bpmn-visualization, migrating from mxGraph to maxGraph required updating 3,000+ test and helper files. See PR #3098.
Another use case: headless SVG rendering using Node.js and jsdom (see #761). While Node supports ESM, some apps are still built in CommonJS — which currently prevents using maxGraph at all.
Describe the solution you'd like
Publish a dual ESM + CJS build in the npm package, including types if necessary.
This would help:
- Use
maxGraphin test environments like Jest (viats-jestor pure JS) - Use
maxGraphheadlessly in Node.js (e.g., SVG export)
Additional context
Here are some dual-build strategies used in the community:
- Anthony Fu: Publishing ESM and CJS
tsup(based on esbuild):
tsup src/index.ts --format cjs,esm --dts --clean
https://github.com/egoist/tsupunbuild(based on rollup):
https://github.com/unjs/unbuild- Manual Rollup config example: https://github.com/toss/es-toolkit/blob/main/rollup.config.mjs
- Run
tsctwice: once for ESM (output tolib/esm), once for CJS (lib/cjs). See https://medium.com/ekino-france/supporting-dual-package-for-cjs-and-esm-in-typescript-library-b5feabac1357
Suggested tasks
Important
We should verify that type definitions work in both cases.
- Create a minimal Jest + CommonJS reproduction example using
ts-jest - Check that types are correctly resolved with that setup
- Create a Node.js example providing a script that uses
maxGraphwith CommonJS +jsdom(see ideas in Running maxgraph headlessly #761) - Validate that there is no impact on the bundle size of the existing examples
- In the node.js example, add link to the issue explaining why this is currently not working with ESM