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
Prepare for compiling Babel to native ESM #13414
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f0cc5a4:
|
20a73e6
to
7dd8220
Compare
870b982
to
b07070c
Compare
a7fcffb
to
58afb18
Compare
58afb18
to
5c3ad66
Compare
b631959
to
255521a
Compare
4c43ed7
to
f0cc5a4
Compare
This is now blocked on #14110, since the |
6e3344c
to
57b208c
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52480/ |
f6074d9
to
1e8474f
Compare
2c61f00
to
79a7664
Compare
952a629
to
9f151d4
Compare
9f151d4
to
ee6dca5
Compare
974872d
to
79e601b
Compare
672effe
to
8f36cb5
Compare
@@ -480,10 +488,15 @@ const libBundles = [ | |||
"packages/babel-plugin-bugfix-safari-id-destructuring-collision-in-function-expression", | |||
].map(src => ({ | |||
src, | |||
format: "cjs", | |||
format: USE_ESM ? "esm" : "cjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself: I should revive #14179.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like self-reviewing, but
- this doesn't affect published code, except for the very small change that now
packages/babel-core/src/config/files/import.cjs
is authored as CJS rather than as ESM compiled to CJS. - I re-checked all my changes, and I didn't find possible problems (it's been three weeks since I worked on this PR)
✔️
Did you revert these changes in this force push for some reason? |
@liuxingbaoyu I had to revert them because |
Disclaimer: This looks good to me, but I'm really completely new to ESM😰 (which is why I haven't reviewed this PR for a long time). |
You have already used ESM for a while, since our tests are not transpiled 😉 (jokes aside, with this PR you won't probably notice any difference when developing with |
dest: "lib", | ||
})); | ||
|
||
const cjsBundles = [ | ||
// This is used by Prettier, @babel/register and @babel/eslint-parser | ||
{ src: "packages/babel-parser" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We(Prettier) don't need cjs, our code base has migrate to esm, and we can do both static and dynamic import in parser, we support async parser now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll update the comment!
Having a dual "compiled to CJS"-"compiled to ESM" codebase is not as easy as having a dual "Babel 7"-"Babel 8" codebase, because it must be determined at compile time and cannot rely on a potentially-runtime flag. This PR adds two new commands,
make use-esm
andmake use-cjs
, to toggle between the two modes: the current mode is stored in the.module-type
file, and it affects both the output type and the compile-time removal of a newUSE_ESM
flag.This PR also adds two new GitHub action tests: a "Test ESM" CI job that runs
yarn jest
on the ESM build, and an ESM e2e test (only with React Native, which is the only one working so far) to make sure that the publishing process works.The ESM migration is not finished yet, but I have updated the "To Do" column in https://github.com/babel/babel/projects/16 to track the next steps that I'll do. This PR can be merged, and I suggest reviewing it commit-by-commit since I tried to keep them as much self-contained as possible.