-
Notifications
You must be signed in to change notification settings - Fork 30
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
Rewrite using promises and less dependencies #23
Conversation
* Remove async dependency * Remove lodash.constant dependency * Remove xtend dependency * Added test for inline-ignore in CSS * Only search content once before replacing and rebasing * Returning a promise, making callbak optional
* Added suport for srcset * Added promise response * Removed async * Removed lodash * Removed xtend * Use htmlparser2 instead of regex * Respect original attributes * Use htmlparse2 for generating valid output
Thanks for the PR. A few thoughts here:
Feel free to push more commits into this PR and let me know how you feel about this feedback. Thanks again. |
Thanks for the feedback! The xtend dependency comes with it's own package,json, tests and two versions of the same code, immutable and mutable. With a total size of 7kB. It's not that much but for projects like mine this kinds of dependencies stack up. I'll re-add it if you like but i see no real reason to have it, please let me know. How do you feel about clean-css? It's nice to have the css cleaned but i would argue that it's not within the scope of this project. perhaps have a similar hook like the scriptTransform and let people choose their own css cleaning library? I have made the same changes to the HTML part with the biggest change is utilizing htmlparser2 for all HTML parsing, this should be more reliable then using regex but changes the output a bit. There is a couple of things i would like to do before I'll consider this code ready.
|
* Lookup inlineAttribute on initial serach * Only replace content of url()
I agree about clean-css. That has already been removed in master though in favor of using linkTransform, unless I missed it somewhere? In reference to xtend, I was really talking about the memory footprint vs the amount on disk. With I'm not super-familiar with how htmlparser2 works internally, but my concern with moving away from regex is causing changes to the code formatting such as you see. Unfortunately, based on what I know about how people use this library, I don't think those changes required to the tests are acceptable. |
I'll re-add xtend for you. I was referring to settings.cssmin used in css.js. Alright, i could make some changes to the output from htmlparser2 so that the output is more similar to what is expected. Is there something in particular with the tests that needs to be reverted?
For the CSS output it now only replaces the content of a |
* Make sure to ignore CID paths
* Correctly opt-in for sources * Fix issue with svg sources * Re-added xtend dependency
The cssmin setting should be removed, you are right, since it shouldn't be used anymore. For the change to htmlparser2, I'm still very worried about unacceptable breakage from that. Do you mind reverting the htmlparser2 changes so we can merge all that other good stuff and continue the conversation? I didn't think you'd be adding that as a dependency since you earlier stated you were trying to remove dependencies. |
You are probably right, this would require a bump in the major version in both juice and web-resource-inliner to make sure there will is no breakages. htmlparser2 is already used in the master version of web-resource-inliner for parsing SVG, so I'm not adding a new dependency, simply using the once we have in a better way. I could probably change the replacing part back to the original regex way and make the tests compatible with the current once, but i think that ultimately regex is never a good solution for parsing HTML reliably. |
This project introduces a lot of dependencies. This is an example of css.js without much of the dependencies. If approved i would like to make the same changes to html.js and remove most of the dependencies all together.
Promises is part of node 4.2.0 so it should be safe to use instead of async.