-
-
Notifications
You must be signed in to change notification settings - Fork 926
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
output mithril, stream and ospec esm versions on build - fixes #2112 #2194
Conversation
@porsager thanks for the PR! @spacejack how does this jive with the TS typings? |
Ah... good question. I guess it depends on what the bundler does, I'm not sure how they will all behave. |
@spacejack what kind of configuration variables should we be looking at? |
Quick overview. Mithril's types currently describe it as a commonjs module. Since TS 2.7 you can use If bundlers pick up the new The separate modules - render, request, hyperscript, etc. look like they'd remain commonjs? Should they have esm versions as well? |
@spacejack I expected it would be a headache, and I have absolutely no idea of how to make it all fit together :-) |
So I've run a quick test with browserify, installing posager's esm-output branch. As far as I can tell, it doesn't affect or break old builds. I'm guessing this is because I've specified commonjs modules in typescript's tsconfig (which 99.999% of TS projects likely do.) I'm hoping that changes to the d.ts could be deferred until later, falling back on commonjs until we add support for esm in the typedefs. (i.e., Typescript use cases wouldn't hold up this change.) Ideally this would be tested with webpack, rollup, parcel, etc. Unfortunately using esm is something I haven't looked into at all yet. @porsager might be helpful to provide a branch with pre-built esm files we could easily install. EDIT: Thinking about this... I wonder if this affects any projects that aren't attempting to use ESM across the board when bundling. Do any bundlers conditionally check each module and attempt to use esm when present? |
Typescript issues aside, should we maybe wait on converting all the modules to esm before going ahead? As it is, you'd be able to do |
Yeah, this PR was exactly to have a point inbetween now, and converting the entire thing to esm. My point on gitter wrt. the various parts being exposed at some point was just to have it included in the considerations if removing I've added the bundled files now, so we should be able to test various setups fairly easily.
|
@porsager Yeah I've converted it at least twice. Probably time to do it for real (& switch to rollup because the tiny filesize benefit to bundler isn't worth the maintenance/brain-space cost), but I'm not even currently using mithril so my available time is pretty limited for that work. The good news is that the process isn't too hard, the tricky part is the way that all the current tests depend on using bundler in the browser. That'd need to change to only testing the bundle which is gonna mean not using mithril internals within tests. |
@tivac Yeah I just wanted to make a PR to make hyperscript merge Would you have m as default export and stream as a named export when you did the conversion too? @spacejack has also done some testing to see how this PR works with typescript here https://github.com/spacejack/mithril-esm-tests |
@porsager I've been there already. The way Diffing from The normalization could be made while diffing attrs, but it would have a perf impact, even for folks who use @tivac I actually like the way testing is set up, especially for the core router. If we end up ditching the module polyfill, I think we should expose the factories. |
Ran through some tests with browserify, webpack, rollup and parcel. All still appear to build ok using the current type defs. All but browserify use the .esm files in the bundle; browserify ignores them. webpack and parcel include stream in the bundle even if you're not using it (as do browsers apparently, when using the modules in script tags.) So I think I'd prefer not to have stream exported from the main mithril bundle. |
I made |
Ok goodie :) I'm fine with removing |
* Fix MithrilJS#1714 conditionally halting stream * Add note in changelog
Also curious if this wouldn't be nice to have included for the 2.0 release? |
@porsager Maybe. It's non-breaking in its current form, so it doesn't have to ship with v2.0.0 to make it in v2. I do have a few requests:
|
Certainly. Sounds good. I'll do it first thing tomorrow morning. |
@isiahmeadows Was these changes wrt. |
@porsager Yes. Basically, separating it out into this: var hyperscript = require("./hyperscript.js")
function m(elem, attrs) { return hyperscript.apply(this, arguments) }
m.m = hyperscript Three more nits that I forgot to mention:
|
|
Webpack, Rollup, and Parcel all three expect Worst case scenario, we just ship a few more files and/or
The bundler currently renames locals as necessary so they don't conflict with similarly-named variables in other modules. But since exporting them like that creates new bindings (whose names are actually significant), the bundler needs to rename all existing locals with their names so you don't have weird issues like Could you modify the bundler to rename locals with those export names, so we can still use them elsewhere? |
With regards to 1, I've already spent too much time trying to get to grips with it, and it's not a thing I want to get further into, so I've changed it now ;) Wrt. 2, I'm afraid trying to fix it in the bundler might be a timesink. How would you feel about something like this instead?
|
@porsager Could you revert/remove the generated files from your diff? Travis will auto-generate them after your patch anyways, and they have a tendency to generate conflicts in PRs.
What you've got is fine now. So no worries here. 😄
I'd be fine with that; just make sure to leave a comment why, so it doesn't get incorrectly "optimized" out. |
- I missed that part when reviewing MithrilJS#2194
BTW, I forgot to prompt you to add a changelog entry, so I did it for you. Sorry about that. Also, I'm at a complete loss as to why Travis didn't think to trigger a build when I merged this... 😕 |
This adds an extra build step which will create esm builds of mithril, stream and ospec.
It also adds a "module" field to package.json's such that eg. module use through unpkg.com will work, and bundling with rollup won't require
rollup-plugin-commonjs
.For instance flems usage would work like this:
The reason it's done simply by rewriting the output is because my understanding is that mithril would change the src to esm eventually, so I didn't want to spend too much time getting caught up in the mithril bundler.
Motivation and Context
fixes #2112
How Has This Been Tested?
Manually
Types of changes
Checklist:
docs/change-log.md