mozilla / addons-linter

🔍 Firefox Add-ons linter, written in JavaScript. 👁
Mozilla Public License 2.0
318 stars 144 forks source link

Switch to ES modules #3842

Open willdurand opened 3 years ago

willdurand commented 3 years ago

Note: this is an issue for the addons-linter code itself and not about web extension features. AMO and FF already support ES modules in web extensions/add-ons.


More and more dependencies are going to be "pure ESM" packages in the near future because the support in most maintained Node versions is built-in and ESM is a much better fit than CommonJS. The following Node.js versions are able to load ES modules without any specific flags: 12.20, 14.14, or 16.0.

From: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

I would strongly recommend moving to ESM. ESM can still import CommonJS packages, but CommonJS packages cannot import ESM packages synchronously.

From: https://blog.sindresorhus.com/hello-modules-d1010b4e777b

What are the benefits of JavaScript Modules over CommonJS?

Unified syntax. Helps with teaching.
Browser compatibility.
Top-level await. Nice for scripts and command-line tools.
Import both default export and named exports in the same statement.
Re-export syntax.
Potentially faster import step.
Official loader hooks (still draft).

We should consider switching to ESM in the near future as well and this issue is about planning for that. It's recommended to switch to pure ESM rather than trying to package ESM + CommonJS within a same package (and that seems a bit simpler). This will also be a good time to refresh our Babel/Webpack configs.

┆Issue is synchronized with this Jira Task

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this bug should stay open, please comment on the issue with further details. Thank you for your contributions.

willdurand commented 2 years ago

One thing we'll have to find out is how the l10n extraction will be performed.. It's using webpack currently, which we removed in other projects that got converted to ESM recently.