-
-
Notifications
You must be signed in to change notification settings - Fork 903
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
ECMAScript Module / Browser Support #330
Comments
@broofa I have worked a bit more on #331 and I believe it is in a shape now that could be reviewed. So what we could get with the current code is the following (almost as already described above):
Regarding 1.
Regarding 2.
Should we rename the imports from Regarding 3.
Regarding 4.
I personally believe that we definitely want 1. & 2. and could wait a bit to see if anybody is asking for 3. & 4. Based on your feedback I will make sure the README reflects all changes and will polish up the code. Would be great to get this out soon! I think this should be released with a new major version number and we should also take this opportunity to finally resolve #173. |
Hi Christoph, this is great work! More comments to come here and in the PR, but given the wholesale rewrite nature of this change, I wanted to make sure we acknowledge this for what it is: A de-facto changing of the guard. Moving forward, I expect you'd be doing most of the heavy lifting maintaining this. I'll still help out as time allows and review/approve PRs as needed, but I'll probably look to you to lead when it comes to dealing with issues related to the new code. Once this goes out, we should make you an Admin here, and an Owner in NPM. Cc: @defunctzombie - You okay with this? |
My personal feeling is to favor a typescript port rather than mjs - but I also am not invested time wise into this project so if you are ok with this and phasing it over that's fine by me. |
@broofa thanks for being so open to the changes I have been suggesting! I do have enough spare time in the foreseeable future to maintain this repository and I'm happy to do so! However, while I'm willing to do the heavy lifting, I will be relying on your feedback in order to find suitable design decisions. @defunctzombie thanks for your support! I'd be curious in your thoughts on the benefits of a TypeScript. I personally do not have a lot of hands on experience with TypeScript so I would be happy to learn from you. I have created a separate issue (#334) for this where you may want to elaborate a bit more on the benefits of a TypeScript rewrite? |
If we do anything with the API, I would suggest we move in whatever direction https://github.com/tc39/proposal-uuid is going. So... start by having v4 as the default export, I guess? There's surprisingly little guidance to be found in other languages, btw. Python has "uuid1".."uuid5" (which I dislike because it's ambiguous if it's a different version of uuid library or uuid format). Java and C# only support v4 uuids, so no help there. Golang is a bit of a clusterfuck. If I had to make an argument for the current scheme, it's that it's concise and backward-compatible. It's also not that bad. If someone wants to be as explicit as "v4uuid", then
This isn't ideal, but it may be the least-obnoxious approach for the time being. What are you thinking? Have a script that builds and publishes ESM-specific packages? I'd be okay with that. |
Yes, I was thinking about having a script that automatically publishes an esm-specific package for node (similary to how lodash is doing it). However given that this really still seems to be experimental in node and that it's still unclear, if/how node will support npm packages that contain CommonJS and ESM, we might as well just wait a bit for the fog to vanish before releasing yet another package to npm that might be difficult to get rid of later. Given the experimental nature I doubt that esm in node is commonly used yet (and for the brave who want to try we can even still provide a deep-importable build). I believe the canonical use cases for node (=CommonJS) and the browser (=ESM for webpack/rollup) are covered with the current state of the code, so maybe let's postpone the advanced ESM stuff a bit? |
Will also stick with the current API surface and rather focus on making the documentation even more helpful (e.g. emphasizing v4 in the Quickstart). |
After digging deep into the current state of es modules in node I finally found https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md#phase-4-further-improvements-after-unflagging which states:
I will therefore, for now, not include any support form ESM in node and only keep the ESM browser-build that bundlers will pick up given the living standard of the |
Tracking progress for ESM in Node.js in #342 |
This is in the next branch since #337. |
I've spent some time continuing the work started in #317
I have the following high-level objectives:
(Provide an ESM build for direct use in node 12 <-- Still unclear if/when Node.js will remove the experimental flag)Won't do as of Oct. 2019So far I have tried to build a hybrid npm package that contains both, a CommonJS build and an esm build. I followed the pattern, that https://date-fns.org/v2.2.1/docs/ECMAScript-Modules uses.
This works fine for CommonJS-usage in Node.js and esm-usage with bundlers like webpack for the browser.
However it does not play nice with pure esm usage:
"module": "esm/index.js"
property inpackage.json
, so far so good.type: module
inpackage.json
and have themain
property point directly to the esm build, themodule
property as mentioned above does not seem to work. This could be something likeuuid-es
similar to https://www.npmjs.com/package/lodash-es"browser"
map inpackage.json
to overwrite certain libraries in the browser context. This is again respected by webpack and other bundlers but obviously not by the browsers themselves. So here we'd maybe have to release anotheruuid-es-browser
package with rng/sha1/md5 libraries swapped by the respective browser counterparts?At this point I'm not 100% certain how to move forward and any feedback would be highly appreciated @broofa @defunctzombie.
The text was updated successfully, but these errors were encountered: