Use native ESM for dev scripts#12296
Conversation
AjayPoshak
left a comment
There was a problem hiding this comment.
@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.
- Since
packages/babel-types/scriptsonly contain native modules, we can put apackage.jsonfile there like this one:and use the{ "type": "module" }
.jsextension rather than.mjs. Gulpfile.jsdoesn't need to be renamed toGulpfile.mjsbabel.config.jsmust be renamed tobabel.config.cjs- We can rename the files in the
test/esmfolder 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.
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
experimentalESMconfig 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.
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.
I'll try using it this week and report feedback!
There was a problem hiding this comment.
I've added the config enableExperimentalESMLoader to that PR so it can be turned on without setting the root package.jsons 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.
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.
Because we only lint src/ files with that rule 😬
There was a problem hiding this comment.
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.
👍 to lint everything except git-ignored.
There was a problem hiding this comment.
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.
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
JLHwung
left a comment
There was a problem hiding this comment.
LGTM as long as CI is green.
|
I restarted the failing job, it was a network error. |
Uh oh!
There was an error while loading. Please reload this page.