-
Notifications
You must be signed in to change notification settings - Fork 78
Revisit Compatibility #435
Copy link
Copy link
Open
Description
(Previous discussions: #133, #269)
Summary
I'd like to start a long-term clean-up project which aims at the following:
- Simplify the build pipeline and reduce the number of dev dependencies.
- Focus on natively supporting ES modules in browsers and in Node.
- Increase the usefulness of CI testing.
- Don't break the current compatibility of
compat.jsbuilds.
The Status Quo and Its Problems
- We currently don't support ES modules in Node.js.
- As of Node.js 13.2, only files ending in
.mjsor files under a folder hierarchy with apackage.jsonwith{"type": "module"}can beimportedrather thanrequired. - We have neither.
- As of Node.js 13.2, only files ending in
- Our build pipeline is complex.
- We use Rollup to bundle our files.
- It's not really needed for using Fluent in Node.js and as a dependency for larger projects with their own build pipelines.
- OTOH, a single-file package is easy to include Fluent in jsfiddle, codepen etc.
- Then again, all of modern browsers support
<script type="module">.
- Then again, all of modern browsers support
- We use Babel to transpile the
compat.jsbuild.- We use
preset-envto define what should be transpiled. The browser matrix was chosen not based on usage data, but based on the JS features we didn't want to transpile. That's kind of backwards of howpreset-envshould work.
- We use
- In Migrate to TypeScript? #376 we're talking about adding TypeScript to the mix, which would further complicate the pipeline, testing, debugging etc.
- We use Rollup to bundle our files.
- We write tests using ES modules and make them work in Node by patching
require.- This is done using
@babel/plugin-transform-es2015-modules-commonjsoresm.
- This is done using
- We test code in different version of Node (good), but we do it by transpiling our unit tests with a Babel setup which is different from the one which we use for shipping (bad).
Short and Mid-Term Ideas
I'd like the clean-up to be careful and incremental. In no particular order:
- Add integration tests.
- Create a new test suite using our
compat.jsbuilds and run it in different versions of Node and older browsers without any further transpilation. - Switch our unit tests to only run in the currently active version of Node.js.
- Create a new test suite using our
- Drop
preset-envand transpile toES2017which we effectively do right now anyways. - Ship ES modules next to CommonJS files.
- Maybe drop Rollup?
- Once we fully support ES modules, will there still be a strong case of bundling our files in a UMD package?
- Maybe migrate to TypeScript?
- See Migrate to TypeScript? #376 for the discussion about TypeScript.
- One more tool in the pipeline, but..
- ...we could possibly drop Babel thanks to TypeScript's
targetcompiler flag.
Long-Term Ideas
Some further ideas for when all Node LTS versions support ES Modules without flags (from mid-2022 forward).
- Drop CommonJS
- Node 12 will be EOLed in April 2022.
- Drop
esmand@babel/plugin-transform-es2015-modules-commonjswhen running tests.- This requires that we use a test runner which natively supports ES modules. Work is underway in both mocha (which we currently use) and jest to enable this.
- It might still be months away today, as it likely requires the "custom loaders" API to stabilize in Node.js. See the bottom of this blog post.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels