-
Notifications
You must be signed in to change notification settings - Fork 68
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
feat: distribute an ESM version #57
Conversation
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.
a) this creates two sources of truth for the library - there's nothing in this PR that enforces they're in sync, and it condemns all future changes to this library to be made twice.
b) if vite and snowpack can't consume CJS directly, they will literally never be useful in a professional setting, because the vast majority of the world's JS is not and will never be distributed in ESM.
c) the ESM file is not being tested at all in this PR.
d) Any browser that understands ESM has Object.assign
and object spread syntax, which covers almost every use case of this library.
@@ -3,7 +3,8 @@ | |||
"author": "Stefan Thomas <justmoon@members.fsf.org> (http://www.justmoon.net)", | |||
"version": "3.0.2", | |||
"description": "Port of jQuery.extend for node.js and the browser", | |||
"main": "index", | |||
"main": "index.cjs", | |||
"module": "index.mjs", |
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.
this is not a standard field, and should not exist in any package. the proper way to distribute ESM is with the "exports" field, and adding that is a breaking change.
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 was reading this https://2ality.com/2019/10/hybrid-npm-packages.html from Dr. Axel... what do you think to add moth module
and export
to have a bit of backwards compatibility with rollup, webpack, etc? 🤔
Unless I add a build tooling like rollup, I don't see a way of doing that. 🤔 If we're open for this option, I can easily add it.
That's a debate I cannot afford. For me, It seems we're trying to moving towards the ESM standard and (IMO) we as community should help as much as we can to help this out.
Valid point, I'll add unit tests for that
You're right... @ChristianMurphy Maybe |
Thanks @ljharb for reviewing that. I think my only 2 big questions here would be the package.json exports and how we can do a single source of truth. As I said, the only way I can see that working is by just adding a very minimal rollup config but maybe you have another suggestion |
I definitely wouldn't want to use rollup; it tends to violate the spec in a number of ways. imo the best help the community can provide is pushing back against attempts to deny the existence of the largest repository of code in any language on the entire planet being in CJS format. |
esbuild is a very, very young tool, and I'm still not clear on the benefits. node itself can import CJS, and any tool that can't do that is imo a flawed one. |
I hear you.. but I think this train has already left :/ As I said before, this is a debate I can't afford even though I've read a bunch of explanation we're moving away from CJS (which isn't ES standard even though it's consolidate with node packages). |
It may have left for some, but in no way is it a foregone conclusion, or even a significant percentage of npm packages that have made this kind of change. The tooling needs to adapt, not the ecosystem. To be concrete, I maintain over 300 packages, and this question has come up maybe on one other package before this PR. |
Look, We're talking about having an hybrid package which uses 2 different ways of export modules. If you don't want to use rollup, esbuild, webpack seems an overkill, maybe I'd give a step back and ask if you're open for supporting this or not. It's totally fine if you don't want to, unless you said this explicit and I can bring that point to |
I'm still trying to understand why it's necessary, and why anyone would be trying to use vite or snowpack if the only packages they can use with it are ones that ship a native ESM build, that depends on only packages with a native ESM build. |
Unfortunately I cannot answer this question, since I'm not involved on vite's architecture discussions 😕 |
In most cases |
This appears to be a bug which the vite team considers a priority: vitejs/vite#3024 I think snowpack already supports mixed CJS and ESM https://www.snowpack.dev/concepts/how-snowpack-works#using-npm-dependencies but I could be wrong. |
Given that vite and snowpack should thus be able to handle CJS dependencies perfectly fine (without which they'd be useless), there doesn't seem to be any need to make changes in this package. |
Hello there.
Just open this PR to also distribute an
ESM
version ofextend
so it can be used byvite
andsnowpack
.You can follow this discussion to see more details.
unifiedjs/unified#153
Summary
index.js
toindex.cjs
package.json.main
referenceindex.mjs
version fromindex.js
module.exports
withexport
package.json.module
propResource