-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add cjs support #203
Add cjs support #203
Conversation
At a glance, looks good. |
@antongolub take a look, please. What do you think? |
@antonmedv, I,m 3* today, so I’m a little out of shape)) May I take a look tomorrow? |
Also, what about moving global pollution to zx.mjs in this version? And keep the library index.mjs free of global extension? |
Definitely agree: remove global side effects from |
How many people are going to actually do What about package - no globals, zx binary - with globals approach? Will create a separate PR for after this one. |
Thoughts about ESM&CJS duality:
But on other hand it will be definitely easier for projects still in CJS only modes. |
I see it this way:
|
Well, dual packages need some additional costs in building and testing. But this is the only way to provide a smooth transition from cjs to esm epoch. |
#198 avoids the dual package hazard. On the other hand, what dual package hazards do you expect to exist for zx? You could avoid it by taking the same approach here, writing an .mjs that exposes the .cjs bundle as named exports. |
global.mjs will not work with bundle everything cjs approach. |
@cspotcode how in your pr globby is required? How cjs will be able to export it? |
#198 does a bit of a hack for globby, which does have limitations. If you If you EDIT: the goal here was to preserve the experience for MJS consumers. They will still have a fully unchanged, native experience. CJS consumers will, at most, need to add As I understand it, anything that needs to be cjs compatible simply needs to load synchronously, so it needs to live in a cjs file. Then you can use a mjs shim to expose it as named exports for mjs consumers. The same philosophy should work for |
This is really odd limitation. I prefer dual package 📦 |
You can avoid that limitation and avoid dual package, right? |
Nope. And we want to develop package as esm for future. And drop cjs support in one/two tears. |
I'm saying if the .mjs provides named exports that come from the .cjs, then you avoid the dual-package hazards. mjs consumers get the same API they always have, and cjs support is added. And the code is still written as an ECMAScript module, meaning a clean drop of cjs in the future. Doesn't matter to me which way it's accomplished, but it's good to understand the issue. |
I didn’t get it. How?
|
The idea I'm thinking about is:
Usage is unchanged for ESM consumers:
Usage for TS consumers:
Usage for CommonJS consumers:
And It can reduce install size, too, since it ships only a single copy of the code and deps. Though I don't think install size is a concern for a tool like zx. EDIT fixed code in bullet point 3 at the top |
I got it. Cool idea. Let's me think it through. Will update PR. |
Got another problem with my PR. It reexports too much:
|
Not really good. :( Supporting both already seems complicated. |
I was not able to find a solution. So no cjs support, I guess. |
Why does it export too much? Is that a rollup issue? If so, I can take a
look.
…On Wed, Aug 25, 2021, 1:33 PM Anton Medvedev ***@***.***> wrote:
I was not able to find a solution. So no cjs support, I guess.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#203 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC35OGQKSNB5YXIFO3GMLLT6USOHANCNFSM5CVFHSZQ>
.
|
Yes, looks like it is rollup issue. |
Seems like esbuild handles this, and we can use a proper resolve plugin instead of find-and-replace for |
After lots of thinking 💭 🧐 I think this is the best compromise. Like one package inside another. So I'm ok with accepting dual package hazards. rollup produces a much nicer output and requires only Node.js to run (in this case is good, no need for speed here). And mjs is the future prove. |
Did you figure out a fix for #203 (comment)? |
Yes, same as you did. Just create and index.cjs file with "filtering". |
Fixes #197