-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: ES Module entry point #1452
Conversation
It is going to break a lot of stuff if our main entry point isn't Would it be possible to just add |
This PR doesn't change the main entry point -
Not exactly - ES Module syntax is not a superset of (CommonJS + ES Module), it's just ES Module syntax. So if /lib/marked.js was CommonJS and was included with |
since it is in .gitignore it won't show up on any site using marked on the client side with: <script src="https://cdn.jsdelivr.net/gh/markedjs/marked/lib/marked.js"></script> |
That is the reason |
Okay, ignoring generated files is my custom but isn't a requirement. I've pushed an update that re-includes lib/marked.js. |
Could we make |
Not with any out-of-the-box solution, as far as I can tell. Detecting & transforming a UMD export is a lot less certain than detecting & transforming an ES Module. |
mjs in module field is broken in webpack. Webpack is quite opinionated about it. Since it's not a requirement for esm in node I would suggest to not use mjs at all and go with |
BREAKING CHANGE: some module loaders will automatically take the module entry point when they previously loaded main. This adds a rollup dependency to produce a UMD bundle, like in previous marked releases, and allows marked to be written and consumed as an ES Module.
Webpack has such unique opinions. Switched to .esm.js. |
I say we wait until Node gets ESM. Right now, the API is in flux and its best to wait until things settle down. Then we can actually run tests in CI against the ESM code. |
|
I think I still stand by these comments from a previous PR: #1349 (comment) |
Okay - it's up to the project maintainers for a final decision, but I should point out that this PR addresses many of the concerns. It doesn't switch to ES6 syntax everywhere, it requires one additional dev dependency (instead of 7), there's one build target and rollup is super fast, there's net zero size change (instead of 5kb), and it'll run in a browser everywhere and unmodified (because it's a single-file source, so module specifiers don't matter). |
Unfortunately, after I've analyzed the exported module shape I've come to the conclusion that this cannot be done without breaking change because of webpack's broken interop between cjs/esm formats - webpack/webpack#7973 I would very much see this refactored to ESM and to a tree-shakeable form of exports, but that's up to Marked team. Just 2 add my 2 cents - while changes around this might be "breaking" they are not functional changes, the only way that would have to change is the exported shape. Bumping a minor (as marked still is in its 0.x versions) should be sufficient to introduce any breaking changes - instead of stalling forever it's IMHO better to push such things forwards for the greater good. |
BREAKING CHANGE: some module loaders will automatically take the
module entry point when they previously loaded main.
This adds a rollup dependency to produce a UMD bundle, like in previous
marked releases, and allows marked to be written and consumed as an ES
Module.
Fixes #1288
This does the same thing as #1349, but:
.mjs
to let Node with--experimental-modules
work for now. This could be changed if folks don't care too much about Node compatibility.lib/marked.js
is now a generated file and is regenerated when you test or publish.Note that this requires a major version bump, or at least a big warning. I wrote about this here, and it's essentially unavoidable because of Webpack's rather… questionable… choice of behavior.
Description
Contributor
Committer
In most cases, this should be a different person than the contributor.