-
-
Notifications
You must be signed in to change notification settings - Fork 907
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
ES-Module support #331
ES-Module support #331
Conversation
Node.js 6 has reached end-of-life at 2019-04-30 so there's little use of supporting this for future releases of uuid, see https://github.com/nodejs/Release#end-of-life-releases
BREAKING CHANGE: CommonJS what?
@43081j @DarylThayil since you have commented on #317: Would you mind testing out my development branch from this PR by installing the following package directly from github:
You can have a look at some examples of how this development version can be used with esmodules in https://github.com/kelektiv/node-uuid/tree/c1307d3fde47d2191bee36d5ea2f42310c63fef8/examples Would be curious about your feedback! |
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.
Should the esm-* directories include CLI files (uuid-bin.*
and bin
dir)? esm-browser/bin/uuid
doesn't really make sense.
Naming nit: Having a "src/lib" directory is a little weird. "src" and "lib" are typically peer directories. Not sure what this should get renamed to but... something. Maybe "src/common"? Or maybe just pull the "lib" files up into "src" at this point? The main reason those were in "lib" was so we could put just the top-tier dependencies (v1/v3/v4/v5.js) at the top level. But if all the JS is getting pushed down into "src", then just having a single dir is probably fine.
Not approving yet, as I think we need to resolve how we want to publish browser-esm .v node-esm .v node-commonjs versions of this library, and I need to actually do my day job right now. Just want to push these comments up, otherwise I'll just sit on this indefinitely. 😛
@@ -0,0 +1,3 @@ | |||
<!DOCTYPE html> | |||
<title>UUID esmodule example</title> | |||
<script type="module" src="example.js"></script> |
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.
'Should probably have some verbiage in the BODY to inform readers where the actual code output is. E.g. "Please open Developer Console to view output"... something like that.
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.
Will add explanation to the files.
How do you feel about adding these examples at all? Helpful or not?
|
||
console.log('uuidv1: ', uuidv1()); | ||
|
||
|
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.
Style nit: Avoid multiple newlines
Consider adding no-multiple-empty-lines
to eslintrc.json?
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 would even consider to add prettier
to get rid of any formatting discussion. However since this PR is already getting really big I wanted to push these kinds of tooling changes and refactorings to a different PR. Fine for you?
scripts/package.sh
Outdated
rm -rf "$DIR" | ||
mkdir -p "$DIR" | ||
|
||
# Traspile CommonJS versions of files |
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.
# Traspile CommonJS versions of files | |
# Transpile CommonJS versions of files |
scripts/package.sh
Outdated
# Traspile CommonJS versions of files | ||
env TARGET='commonjs' babel src --source-root src --out-dir "$DIR" --copy-files --quiet | ||
|
||
# Traspile ESM versions of files for node |
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.
# Traspile ESM versions of files for node | |
# Transpile ESM versions of files for node |
scripts/package.sh
Outdated
for FILE in "$DIR"/esm-browser/lib/*-browser.js | ||
do |
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.
for FILE in "$DIR"/esm-browser/lib/*-browser.js; do
Style nit: Prefer one line for declaring for-loops in Bash.
src/lib/v35.js
Outdated
generateUUID.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; | ||
// For CommonJS default export support | ||
generateUUID.DNS = DNS; | ||
generateUUID.URL = URL; |
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.
Maybe have the v3/v5.js files explicitly export DNS, URL from './lib/v35.js'
rather than bodging it in here? (Would that work?)
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 tried that but it does not seem to work.
I'm using https://www.npmjs.com/package/babel-plugin-add-module-exports to add module.exports
to the transpiled CommonJS modules so people can continue to do
const uuidv4 = require('uuid/v4');
instead of having to do ugly workarounds like
const uuidv4 = require('uuid/v4').default;
or
const { default: uuidv4 } = require('uuid/v4');
As soon as there is more than export default …
this module.exports
approach will no longer work.
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.
@broofa thanks for the review, I will push changes as suggested.
Not approving yet, as I think we need to resolve how we want to publish browser-esm .v node-esm .v node-commonjs versions of this library, and I need to actually do my day job right now. Just want to push these comments up, otherwise I'll just sit on this indefinitely. 😛
As this PR has already grown almost too big to review I wanted to propose to create a new next
branch from master and I would then post all my PRs against this next
branch. That way we can take a bit more time and focus to flesh things out (also potentially publishing some prereleases) without putting master into a broken state.
I would then also make sure to keep PRs smaller so there's a more realistic chance for you to review.
Fine for you?
@broofa since I pushed so many fixups I decided to squash all my fixups together again. Quick summary of my changes:
Here's what the contents of the npm tarball would look like: https://github.com/ctavan/uuid-esm (you can also check out the updated README there) Feature-wise I would love to merge this state into a I would then like to make some more tooling improvements (like publishing changelog to the Github releases page), maybe add browser tests (now that we have code specifically targeting the browser) and remove some outdated code like pre-node-4 Buffer code, but all of that in smaller, separate PRs. |
This all sounds good. I like the idea of a I'd like to keep whatever we're doing here in sync with https://github.com/tc39/proposal-uuid, whatever that means. At a minimum, try to have some agreement on how the two projects interrelate would be prudent. E.g. Do we treat this module as the "experimental" sandbox for whatever API(s) might come later there? Dunno. Note that your work here supersedes much of my I'm traveling this week and next, but I'll try to review again ASAP. |
👍 I would need publish access for the npm module at some point though to publish Will make sure to update the master README.
👍 However as discussed in #330 I will focus on ESModule interoperability and tooling changes for now and I will not introduce any API changes for the time being. Should we decide to change the API of this module though, I totally agree that we should keep it in sync with https://github.com/tc39/proposal-uuid.
In fact I cherry-picked your commit from the other branch, I see value in leaving the other branch open for a while until we have made decisions around the API changes (which I intentionally left out here). |
Closing in favor of #337 337 |
Discussion: #330