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
Use native ESM for dev scripts #12296
Conversation
karansapolia
commented
Nov 2, 2020
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #12137 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
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.
@karansapolia My bad, I did not notice that this PR is still in draft.
e01a693
to
921d0ab
Compare
@karansapolia Do you need any help with this? 😄 If you don't have time/interest, I could finish your commits. (I'm sorry to ping you, but this PR is super exciting for me) |
bc950bd
to
ecd8dcd
Compare
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.
- Since
packages/babel-types/scripts
only contain native modules, we can put apackage.json
file there like this one:and use the{ "type": "module" }
.js
extension rather than.mjs
. Gulpfile.js
doesn't need to be renamed toGulpfile.mjs
babel.config.js
must be renamed tobabel.config.cjs
- We can rename the files in the
test/esm
folder to.js
, and update the path in the"test:esm"
script of the top-levelpackage.json
ecd8dcd
to
5baa49b
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/38935/ |
d4f0317
to
416a667
Compare
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 58046b4:
|
c21c558
to
b6877c8
Compare
# Yarn PnP does not support native ESM yet (https://github.com/yarnpkg/berry/issues/638) | ||
# env: | ||
# YARN_NODE_LINKER: pnp # use pnp linker for better linking performance and stricter checks |
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.
PnP doesn't support ESM yet, but they are working on it: yarnpkg/berry#2161
(:frowning_face: since we only enabled PnP for this CI Job yesterday)
I personally wouldn't expect them to introduce support for ESM by default until Node.js' loader API becomes stable (currently it's --experimental-loader
), but:
- We could decide to use feat(pnp): experimental esm support yarnpkg/berry#2161 instead of their last release: Yarn is committed into our repo, so it will not "suddently break" anyway.
- They could release ESM support even if loaders are still experimental, maybe behind an
experimentalESM
config option (cc @merceyz, just in case you like this suggestion 😛) - They already use our repository in their E2E tests for
node_modules
: also giving them a real-world repository that use Yarn 2 to test their ESM support might help with getting ESM support sooner and/or make it more stable!
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.
All that PR needs is someone to test it but none of the maintainers actually use ESM in our projects so we can't dogfood it, would be great if a project like Babel could test it 👍
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'll try using it this week and report feedback!
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've added the config enableExperimentalESMLoader
to that PR so it can be turned on without setting the root package.json
s type
field to module
.
I'll try using it this week and report feedback!
Thanks, if you got any questions or anything I'm usually active on Discord 👍
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.
Any updates on ESM support in Yarn 2? IMO the PnP check is important in case we forget declaring dependencies. We could add a new build job which transpiles Gulpfile.mjs and then build with PnP.
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.
Because we only lint src/
files with that rule 😬
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.
It's less important to lint other things since they will never affect our users, but we can lint everything if you prefer.
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.
👍 to lint everything except git-ignored.
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.
Any updates on ESM support in Yarn 2?
@JLHwung It works as far as I can tell, @nicolo-ribaudo was testing it on the Babel repo but I don't know the result of that test. All the issues that were brought up was fixed as far as I can tell
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.
Yup, in this repo it's working (or at least, it was a few weeks ago).
However, I didn't want to put any pressure on yarn since the ESM loader API is far from being stable.
I rebased and fixed the remaining build errors. Thanks @karansapolia for starting this PR! 🧡 |
@nicolo-ribaudo Thank you to the babel team for the opportunity. This has stretched a lot and needed a lot of reviews and work from you. Lot to learn from you all. Thank you. |
b6877c8
to
b401a58
Compare
b401a58
to
0d45a2a
Compare
0d45a2a
to
3a4405e
Compare
3a4405e
to
58046b4
Compare
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.
LGTM as long as CI is green.
I restarted the failing job, it was a network error. |