-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Convert project to us ECMAScript modules #1905
Conversation
Related: #1429 Thanks for dedicating the time to perform the migration. This is something we knew had to be done eventually and was even one of the goals for SVGO v3, but was never prioritized. I'd also been putting it off. I'll actually put the performance/test work on-hold to review these incoming pull requests (I can still execute them locally anyway). We're starting to get a lot of pull requests piling up now, plus it'll be great to work with modules instead. Reference: Progress on performance and expanded regression testing. I would like to do one more release with CommonJS with the improvements we've been making recently, and some optimizations for existing plugins Kendell R has been working on. We'll get this reviewed and merged after that, Meanwhile, I'd be happy to assist you with rebasing as we merge other pull requests. 👍🏽 |
Sounds great. Thanks! |
9c48964
to
03db121
Compare
I've made the following changes:
I've seen many package maintainers drop CJS support when they move to ESM, so I assumed that maintaining both would be a challenge. After looking into it, it's actually not a problem at all as we're a stateless package. It does come with the downside of increasing the package size, but that's worth it to support a still substantial portion of the Node.js ecosystem. 🤔
For now, I'd like to support both CJS and ESM. With this in mind, it's probably better to save SVGO v4 for another time, as this isn't the breaking change I was expecting it to be. I'd like to continue resolving bugs in the current version. Later this week I'll skim over the changes again, verify that it's working properly in both ESM, CJS, CLI, and browser, and potential add tests specific to the CJS module similar to what we have with the browser bundle. Then I'll be glad to merge this! Please let me know if you think there are any issues with my changes. |
7c04efb
to
0346c7e
Compare
ECMAScript modules are the official standard format to package JavaScript code for reuse. Modules are defined using a variety of import and export statements. Node fully supports ECMAScript modules as they are currently specified and provides interoperability between them and its original module format, CommonJS.
More and more Node packages are switching from CommonJS to ESM, including SVGO dependencies such as csso.
Node documentation on ESM is available at:
https://nodejs.org/api/esm.html