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
Move to ESM #5291
Comments
@jeddy3 Should we create a long-lived branch such as |
Yep. I've created a
We can use https://github.com/knowbee/rona for this.
Find and replace should suffice for this.
This is probably the trickiest aspect of this issue. |
Shall we wait with ESM until Jest has non-experimental support for it? |
Let's transpile for Jest for now (Method B or C): So that we can update our growing list of dependencies that require ESM. We can move from transpiling to native ESM Jest when it's available. |
This issue is now unblocked and can be started on. We can use putout to do the bulk of the Putting a {
"rules": {
"convert-commonjs-to-esm/require": "on",
"convert-commonjs-to-esm/exports": "on",
"convert-commonjs-to-esm/commons": "off",
"apply-destructuring/array": "off",
"convert-to-arrow-function": "off",
"apply-destructuring/object": "off",
"remove-iife": "off",
"simplify-ternary": "off",
"merge-if-statements": "off",
"apply-optional-chaining": "off",
"remove-boolean-from-assertions": "off",
"convert-for-each-to-for-of": "off",
"regexp/optimize": "off",
"regexp/remove-useless-regexp": "off",
"convert-equal-to-strict-equal": "off",
"regexp/remove-useless-group": "off",
"convert-array-copy-to-slice": "off",
"remove-useless-variables/rename": "off",
"remove-useless-operand": "off",
"remove-useless-array-constructor": "off",
"remove-useless-type-convertion/named": "off",
"convert-assignment-to-comparison": "off",
"convert-for-to-for-of/length": "off",
"apply-numeric-separators": "off",
"remove-useless-variables/remove": "off",
"remove-console": "off",
"remove-useless-spread/object": "off",
"convert-template-to-string": "off",
"remove-unused-variables": "off",
"nodejs/convert-promisify-to-fs-promises": "off",
"remove-useless-await": "off"
},
"processors": [
["markdown", "off"],
["css", "off"],
["yaml", "off"],
["ignore", "off"]
]
} And running:
I suggest we tackle this in stages. First, we move to I may have time to get the ball rolling with the move to |
Maybe we should wait with this until PostCSS 8 migration is done #4942? The reason is PostCSS 8 has ESM exports, but PostCSS 7 — not. |
Another important thing that maybe important to postpone ESM migration for a while. With PostCSS 8 there is a big chance, that stylelint plugins should be a little bit different and use PostCSS 8 visitors API. That could be challenging for plugin developers. If stylelint would be ESM, plugins also have to be ESM, because every plugin imports stylelint. And CommonJS can't import ESM. Combining this two big changes at the same time could be very problematic for plugin author. Maybe for v14 let's stay on CommonJS. And in v15 we move to ESM. We could do v15 right after v14. It will allow plugin authors first to migrate to PostCSS 8 and new plugin format. Test it, and then migrate to ESM. |
FYI. There is a way of "Conditional exports" for that.
We can generate CJS files via a transpiler like rollup.js. |
@hudochenkov Those are all good points.
I originally thought that, in the long run, it'll be better for users if we draw a clean line in the sand:
That'd help users navigate compatible and incompatible plugins and tasks runners. However, I agree that this may be too much to ask of plugin and task runner authors in the short term. @ybiquitous' suggestion of conditional exports may be the appropriate middle ground. Going pure ESM is probably more suitable for libraries (like the ones we import) than tools like Stylelint at this point. We can take a dual approach for the next year and then see how the dust settles. This would allow us to move to ESM ourselves in
The good news is that this is a lot more viable now with the removal of syntax (#5289), autoprefixer (#5293) and the If we decide to dual publish and add the infrastructure to bundle commonjs, then it's sensible to repurpose that infrastructure to bundle ESM. While investigating #2454, I found bundling to give comparable or even better performance than using lazy-import. It's likely other issues and opportunities will emerge when we begin to more fully explore the move to ESM once all the other It's exciting to think what |
Yeah, let's see what we'll have at that time. In a good new I have my own plugin, so could get first-hand experience with PostCSS 8 and ESM before final release :) I wish I had smaller plugin :)
Sounds like new iPhone announcement :) |
Ditto.
Ha 😃 . Building the excitement :) |
I was curious if this was true. The results of a quick test are promising. It looks like ESBuild can bundle the npx esbuild ./lib/index.js --bundle --outfile=out/index.js --format=cjs --platform=node --minify --metafile=lib.json Will result in a 900kb bundle with 100ms require times. Custom syntaxes and plugins worked fine. If you like, you can upload the generated metafile to https://www.bundle-buddy.com to see a breakdown. The |
We have big problem with https://github.com/stylelint/stylelint/blob/master/bin/stylelint.js#L6 ( |
Can we do without the package (at least until it's compatible), especially as we'll probably be bundling in |
It reduces startup time (after first running) around 20-40%, especial for custom plugins/rules/etc We are working on https://github.com/sokra/node-voo (maybe make sense to add es modules cache support too), in near future I want to migrate webpack (i.e. webpack-cli) on this, so we will get big feedback. Honestly, maybe we should continue to be in CJS, and use https://github.com/ai/dual-publish, the ecosystem is not quite ready yet, a lot low-level utils/packages is still on CJS, therefore, in fact, it does not bring any huge benefits. Don't forget many developers (especial boilerplates) have
I personally make no small effort in ESM migrations and really look forward to it. So Node.js 12 is transitional stage, in this stage low level tools/pages should migrate on ESM, top level projects rewrite code with thoughts future ESM using (i.e. Don't forget about cosmiconfig/cosmiconfig#224, JSON files should be read using Just my onion. Again, I'm not against ESM, I love ESM ⭐ |
We are moving to ESM on the `stylelint/stylelint` repo: stylelint/stylelint#5291
I think our hand is forced as 8 of our dependencies are ESM-only already. We'll need to weigh up performance costs against keeping our dependencies up to date.
The tentative plan is to author in ESM and dual publish a CJS bundle so that users can still use There's still a lot of other |
Sounds good, with bundler it will be easy |
We have the following tasks left:
|
Progress reportI believe the migration to ESM is about to be done. Remaining work:
I'd appreciate it if you could take a look at them. |
We'll need to:
The text was updated successfully, but these errors were encountered: