Skip to content
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

[WIP Do not merge yet] Build bundle using rollup #55

Closed
wants to merge 1 commit into from
Closed

[WIP Do not merge yet] Build bundle using rollup #55

wants to merge 1 commit into from

Conversation

faergeek
Copy link
Contributor

It's the solution for #14 which I proposed. It's far from being ready.

I'd like some guidelines on what to do and what not to do:

  1. What about code style? Is it somehow enforced? What about setting up prettier in separate PR?
  2. Flow in comments is just for convenience or for distribution too? What if I setup stripping types into separate files and get rid of comments in source?
  3. What about separating source into many files? Are there any preference on how to structure it?
  4. Is there some way to test all needed distribution formats? It looks like slightly modified UMD. Is UMD enough or something specific is also needed?

@ariabuckles
Copy link
Owner

Hi @faergeek,

Thanks for your interest in contributing!

Before investigating this more thoroughly, I'd like to better understand the problems you're trying to solve. Do you have a specific scenario you're running into where the current build is a problem?

As to the specific questions, I can answer those:

  1. Code style roughly follows Khan Academy's style guide. I say roughly because since simple-markdown was originally written, that style guide has changed a bit, and I've left Khan Academy, so while I do my best to match that style guide, there may be parts I'm behind on. I'm generally open to PRs fixing style issues from that guide, as long as they're compatible with the rest of simple-markdown's philosophy (mostly, using es5 only). Unfortunately, last time I checked, simple-markdown can't use prettier, since it breaks the flow comments.

  2. The flow comments are both for external flow type definitions, and for flow checking the project itself. simple-markdown uses comments rather than standard flow declarations because it has no compile step (other than optional minification), and is intended to run in any environment supporting es5 or later. As far as I know, separating types into a different file would work for external definitions, but not check that those definitions are consistent with the source internally.

  3. One of the design philosophies of simple-markdown is that it's a single file that can be easily included in a project regardless of that project's module system or lack thereof. It should be simple to use and generally require zero config to get started. So except for compelling technical reasons (most notably, file size, as mentioned in Move defaultRules to a separate module? #14, is a compelling reason), I'd like to keep simple markdown primarily as a single file. I'd also be okay with a simple build system for creating this file, but would prefer a build system with readable output, or a build system which creates the smaller files from the original single source file. And since some build systems have issues with bundled code that includes requires, I'd prefer to avoid a complete require-based bundling system if possible.

  4. UMD is fine. I'd like it to work in webpack, node, and browsers with es5 support (can't use es6 modules yet, unfortunately). I wouldn't mind adding support for amd/requirejs (but I'm also fine with not adding that; I haven't had anyone need that yet).

In conclusion, I think some changes here are feasible, but I'd prefer them to be as small as possible, and focus on solving a specific problem (such as allowing clients to require the engine without the default rules), rather than trying to match more modern code/module style, which isn't a project goal. So I'd like to hear what problems you're running into trying to use simple-markdown, and see how we could best solve those together. (Or if you're not running into a specific problem but looking to contribute generally, I'd be happy to talk about some less-radical changes that the project could use help with!)

@faergeek
Copy link
Contributor Author

The main problem with the build is that there's no build system right now. With rollup I plan to use es modules syntax, which will be compiled to UMD (for node and browser, including AMD) and es modules (in fact almost nothing will change from source in that case). ES modules allow tree shaking, so that's mostly just about bundle size.

On prettier and flow comments. I'm not sure yet about extracting types for external consumption, but there is a plugin for rollup which can strip flow types, so we don't have to use comments. Build step is needed anyway. So I think it solves problems with prettier, project-wide checking and probably external checking (if rollup plugin does not extract types, then we need a separate tool may be).

About single file. It will be distributed as a single file anyway. But which single file depends on module support :-) There are two formats (see first paragraph) which will be enough for at least all cases I know. And when talking about separating into multiple files I mean only source, distributed files are single bundles, just different formats for different purposes.

If less radical changes mean less to review, I'm not sure it will be possible if I need to get rid of flow comments, replacing them with the usual syntax. So may be separating into multiple files here is a good idea, may be not. I think I will do it as a last step anyway and everything will be in separate commits, so that we can discuss what to accept and what not.

@ariabuckles
Copy link
Owner

Hi @faergeek,

Thanks for the response.

I think you may have misunderstood me—I know that the output would be a single file, but I'm concerned that that single file might be less readable or useable than the current one, and before committing to a specific build system I'd need to investigate its effects on the various environments I expect simple-markdown to run in, and whether the default single file build would get larger due to module headers or such. I know rollup is good and reasonably common, but I haven't investigated its output and I'd want to be confident of the results here before committing.

Second, it adds a dependency. This means that if someone needs to make a small tweak, they must run the build system themselves, and that if the landscape changes in the future—rollup becomes less popular, or has major changes, or future builds become incompatible with files built with prior versions—then there is a maintenance burden in upgrading.

I think these prices are potentially small, but they add complexity, and I don't want to add that complexity unless there's a compelling reason. If users of the library really need smaller bundles, then I'd like to consider how to deliver that to them, whether via tree-shaking or some other build system, depending on what exactly they need and how best to address it. And I would like to hear from users having trouble with this directly to fully understand their issues first. Until that's the case, though, committing to something early locks us into whatever that decision is, and adds a maintenance burden that may not have an immediate benefit.

(As an aside, there's a variety of reasons why tree-shaking doesn't seem to me to have a lot of potential benefit on this particular project. From my understanding, most users of simple-markdown currently use almost all of the code, and therefore wouldn't gain much benefit from tree-shaking. I do know of one large user that doesn't use many of the default rules, but I don't know what their build system is or how it works, so I don't know that building tree-shaking would necessarily benefit them. In addition, much of the code that is only conditionally used is nested inside objects, which would be challenging to pull out into modules themselves. For these reasons, I'm not sure that tree-shaking support would be the best way to provide smaller bundles to users, and I'd want to know exactly what problems they're having, how much savings they need, and what their build system is, before committing to a solution. simple-markdown is a relatively tiny markdown parser already – 5 KB compared to marked.js's ~7 KB, or markdown-it's ~25 KB)

In summary: I'd like to wait for specific user needs before making these types of changes, because they do have a cost, and because I want to make sure to solve their actual problems as best as possible.

I can see you're excited about this, and it sounds like a good project to learn things! You're welcome to try it, but I don't think I'm likely to merge a build system pull request into the core repo until it has a clear benefit for users of the library.

If you're interested in other contributions, there are some tests and bugfixes that need work which I could help with!

@faergeek
Copy link
Contributor Author

This doesn't lock project to rollup. There are at least webpack, browserify (with babel), which can understand code equally well, but rollup is famous for inventing tree-shaking and really good at that, plus it's better for libraries, while webpack is better for apps.

After running rollup I don't see anything unreadable, may be a few one liners at the top, but they are still readable, not even minified. So, even getting rid of build system in the future and editing bundle is possible. You'll lose only flow types in such case.

And there's also almost no overhead. Just a few lines and IIFE.

And benefit is not in build system, actually benefit is in plain standard es modules, which I'd say will be almost equal to source. Build system is rather for backwards compatibility (UMD etc.). Webpack works with such bundles out of the box (I mean tree-shaking) and it's most widespread bundler. Plus architecture of this project allows to benefit from this from the start. Here we have many exports which user may need or may not need (they will not be included in app). At this stage there's even nothing needed to change in library interface to benefit from tree-shaking.

A little bit later I can build an example to prove all of that if you agree with some parts of what I written here :-)

About other contributions, what about migrating to jest? It's just plain simpler and has a good watch mode, plus code coverage out of the box, etc.

Oh, and I would suggest to get rid of Makefile and just use npm scripts. It's good system, but not for JavaScript, better for C or other compiled languages with intermediary binaries :-)

@faergeek faergeek deleted the rollup branch October 16, 2018 06:09
@ariabuckles
Copy link
Owner

As I said before, I'm not interested to migrating to a more complex build system until I know what troubles users are running into with the current build, so I can make sure to solve those well.

Plus architecture of this project allows to benefit from this from the start. Here we have many exports which user may need or may not need (they will not be included in app). At this stage there's even nothing needed to change in library interface to benefit from tree-shaking.

I don't believe that's true. Of the 28 exports, 3 are core to the rules/engine (and could potentially benefit from tree shaking, if users are using only 1-2 of them, which is uncommon), 11 are helper functions which are called internally anyways and couldn't be removed by tree-shaking, 10 are convenience wrappers of less than 5 lines, and the remaining 4 functions are <30 lines, three of which are deprecated and will be removed in 1.0. So no, the current architecture of this project does not benefit significantly from tree-shaking. You could potentially get tree-shaking benefits under specific circumstances by breaking up the defaultRules object, but that changes the API significantly, and I'd like to wait until I know what people need before doing that.

About other contributions, what about migrating to jest? It's just plain simpler and has a good watch mode, plus code coverage out of the box, etc.

Jest already works; npx jest --no-watchman should run all the tests.

Oh, and I would suggest to get rid of Makefile and just use npm scripts. It's good system, but not for JavaScript, better for C or other compiled languages with intermediary binaries :-)

This sounds extremely condescending. I don't need you to explain technical concepts that I understand fine to me on my own project's page.

It's rude to come into a project and tell them to overhaul the project's infrastructure. Why should I have to switch all the systems I've used to maintain this project for years because someone tells me that they think it would be better if I used their favourite tools? You've been entitled and condescending here, and it's hurt.

@faergeek
Copy link
Contributor Author

This sounds extremely condescending. I don't need you to explain technical concepts that I understand fine to me on my own project's page.

It's rude to come into a project and tell them to overhaul the project's infrastructure. Why should I have to switch all the systems I've used to maintain this project for years because someone tells me that they think it would be better if I used their favourite tools? You've been entitled and condescending here, and it's hurt.

Sorry, I didn't want to enforce some tool or condescend. English is not my native language, so what I write may sound like shit probably.

My main concern about make actually is that there are people using Windows and AFAIK make is not common tool on Windows, may be I'm wrong, please correct me. So if I'm right then that may block contributors using Windows, not sure. I'm not against make myself and actually I even like C.

@faergeek faergeek mentioned this pull request Oct 24, 2018
@ariabuckles ariabuckles mentioned this pull request Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants