-
-
Notifications
You must be signed in to change notification settings - Fork 40
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 build setup (ES5 & ES6, minified & unminified) #33
Open
jhildenbiddle
wants to merge
8
commits into
juliangruber:master
Choose a base branch
from
jhildenbiddle:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b39db28
Add build setup (ES5 & ES6, Un- andn Minifed)
jhildenbiddle 7108076
Reformat via prettier-standard
jhildenbiddle 326bb7a
Update tests and examples to use /dist
jhildenbiddle 194c47b
Add prepare and version scripts
jhildenbiddle d9a3983
Update dist path in prepare script
jhildenbiddle a71722b
Add node 16 to CI tests
jhildenbiddle c434ecc
Fix missing rollup dependency
jhildenbiddle 927aa9d
Update example wtih ES module syntax
jhildenbiddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# Folders | ||
dist | ||
node_modules | ||
|
||
# Files | ||
*.log | ||
|
||
# OS | ||
._* | ||
.cache | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ node_js: | |
- 12 | ||
- 14 | ||
- 15 | ||
- 16 | ||
|
||
arch: | ||
- amd64 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const balanced = require('./') | ||
const balanced = require('./dist/balanced-match.js') | ||
|
||
console.log(balanced('{', '}', 'pre{in{nested}}post')) | ||
console.log(balanced('{', '}', 'pre{first}between{second}post')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
node comes with native support in recent versions, I wonder if we need to add a bundler, or can just bump the major and make it an ESM only module, as @sindresorhus has recently done with many modules (eg sindresorhus/p-queue@8c7325a)
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.
That's certainly an option and sindresorhus has made a case for doing so on his blog, but I don't think moving to ESM only is the right decision for every project. For server-side libraries, sure. For projects that may run in a browser, it makes sense to continue offering an ES5 version a bit longer.
A few issues I think are worth considering:
The package you linked to (p-queue) is better positioned to go "ESM only" because the library requires
Promise
support. Practically speaking, this means that if the library is run in a browser it will almost certainly do so in environments that support ESM modules.Is this library able to run client-side? If so, then I believe the library should offer legacy-compatible code at least until MS officially ends support for IE11 (August 17, 2021).
The alternative is to force library consumers to wrestle with webpack, rollup, parcel, etc. Even if these tools are already being used in a project, they have to be (re)configured to transpile some-but-not-all dependencies in
/node_modules
to avoid accidentally accidentally shipping ES6 code in ES5 bundles when they update to ESM-only versions of a library. This is what happened to me when updatingbalance-match
to v2 in css-vars-ponyfill: I was already using babel, but it was configured to ignore files in/node_modules
. As a result, rollup+babel created an ES5 bundle that contained properly transpired code (my source) and untranspiled ES6 code (balance-match v2). See v2.4.4 no longer transpiles to pure ECMAScript 5 jhildenbiddle/css-vars-ponyfill#158 for details.Is this a library consumers may want to load from a CDN? If so, then I believe the library should offer minified as well as unminifed versions:
Just my $0.02. :)
If you prefer going "ESM only", I'm happy to made those changes and update the docs accordingly. Given that previous versions of balanced-match were written in ES5, I think it's important to let consumers know that the current version requires transpilation if used in legacy environments.
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.
Hi @juliangruber.
To add some context for the desire to provide an ES5-friendly version: css-vars-ponyfill is a library I maintain that is used primarily to make life easier for projects that are forced to support IE11. It is downloaded over 100k per week from npm and over 110m per month from just one CDN (jsdelivr). As devs we're all anxious to move past legacy browsers, but not everyone has the luxury to do so.
Happy to make changes if requested.
Thanks!
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.
Interesting, in my experience it's the opposite. All of my client side projects are transpiled, none of my server side projects are, so I've been using ESM in the browser for a while. Is it the opposite for you?
If you were to consume and not have a bundler set up, how would you do it? Is that a realistic use case for this library?
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 think that for "entry point" libraries, like jQuery this makes sense, but for this library I anticipate it will be consumed in conjunction with others, where then using a bundler makes a lot more sense.
Thank you for all this work on this so far, however I'm not convinced this is the right way, and am still in favor of going ESM only (if anything).
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 asked for community input in https://twitter.com/juliangruber/status/1391336252096516098
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.
The poll is interesting, but it misses the point of the PR. A better poll would be "should library authors pre-transpile distributable files to ES5 or are library consumers responsible for transpiling their dependencies to ES5?" I would expect the answer to be different for new libraries that have never offered ES5 versions versus well-established libraries that have always been ES5.
I think in 2021 there is a strong argument for moving to ES modules only, but the code in that module should still be ES5 if there is a reasonable chance it will be run in a legacy browser. Give the age and popularity of this library, I think that is a reasonable assumption.
Again, just my $0.02. 😄
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 think we should just move to ESM