Use named exports internally + update browser endpoints #145
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.
It's tricky to get multi-platform targeting libraries right these days. Currently,
yaml
supports:To achieve that, the ESM sources are transpiled first to CJS under
dist/
, with a Node 6.5 target (actually giving us 6.0 support), and then to ESM underbrowser/dist/
, with a Browserslist target that includes IE 11.CJS Node finds its sources by just automatically adding a
.js
file extension, and then finding a manually crafted re-exporter fromdist/
. ESM Node goes via the"exports"
object in the package.json, but does much the same. Both of these use the same CJS implementation internally.Bundlers find their target via the
"browser"
package.json object, which leads to similar re-exporters frombrowser/dist/
as for Node.Eventually, I'd really like to be able to consolidate all of those into one ESM build, but that'll take some time yet for earlier Node versions to go out of favor, and possibly IE 11 as well -- and require a semver-major update to this library. Meanwhile, this PR is about taking a couple of small steps towards a bit more sanity.
Internally, this switches all exports and imports to be named, rather than defaults. This allows us to drop Webpack's
_interopRequire*
wrappers forrequire()
calls, and not need an__esModule
prop in each module.The browser re-exporters are switched from CJS to ESM, as the implementation they're re-exporting is already ESM. This should be completely transparent to any normal users, but in the particular case of having a custom UMD build of just
yaml
, you may need to specify that you want itsdefault
export exposed. The Webpack option for this isoutput.libraryExport: 'default'
.