flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.01k stars 87 forks source link

feat: support cjs & esm #293

Closed schulzf closed 6 days ago

schulzf commented 2 weeks ago

Add Support for CommonJS via ESM & CJS Builds

Summary

This pull request implements dual builds for the SuperJSON library, adding support for both ECMAScript Modules (ESM) and CommonJS modules (CJS). This enhancement ensures compatibility with various JavaScript environments and module loaders, particularly focusing on improving integration with the NestJS framework.

Changes

Motivation

This enhancement aims to facilitate seamless integration with the NestJS framework, which benefits from CommonJS module support.

Testing

Please review the changes and provide any feedback. Thank you!

Skn0tt commented 6 days ago

Hi Felipe! Thanks for going ahead and opening this PR, but this is not the kind of contribution that's fit for a drive-by PR. Moving to ESM-only was a conscious decision, and there's enough workarounds for using SuperJSON from CommonJS. I appreciate your effort though!