-
Notifications
You must be signed in to change notification settings - Fork 235
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
Adds Sass template processing #439
Conversation
Same deal here - really happy to finally get Sass, but just haven't had a chance to review yet. Will soon. |
The code looks great. I do have some concerns about LibSass.Net though. Specifically:
That said, I don't know that there are any good alternatives. One thought I had been tossing around earlier was to use Jint (which supports netstandard) to run sass.js, which is a pure JS version of libsass (cross-compiled via emscripten). That would be interesting because it may also open up the door to other Jint-powered libraries for things like Handlebars, better Less support, etc. Thoughts? |
I like it. Let me get a POC running on this branch to kick the tires. Haven't seen Jint before but it looks like a heck of a better option than the MsieJsEngine and requiring C++. |
Jint seems to have a major blocker - regex support. Part of its transpiling magic it converts the calls to use the .Net implementation but there's limited code in converting the actual regex string to something .Net likes. I tried converting a few statements but quickly realized I was just randomly smashing combinations of I'm going to try out VroomJS which is a wrapper around V8. I think the wrapper route is going to be a necessary evil here, especially with linting tools and the such which are so regex heavy. ReactJs.Net uses it and it is cross platform but not in a plug and play kind of way. See their docs here on what's required - https://reactjs.net/guides/mono.html |
Sigh, playing around with this today lead to one unfortunate and inevitable conclusion - What I'm not sure about it how to make it cross platform. There's tons of implementations of IJsEngine that seemingly cover the majority of scenarios, the question that I just don't have the experience with it designing it so that they all play nice for both end-users and developers. |
You know, I'm okay with exposing a common JS framework and supporting interfaces from The interfaces should go in You're right, the challenge here is going to be figuring out how to implement so that it's stable cross platform and supports netstandard. I'll try to carve some time tomorrow to look into Jint and others. I've been down this path before and I seem to remember there being some additional alternatives like Jurassic. |
Right on. I'm going to add a new test to the highlighting PR that forces the highlight.js auto highlighting mode on. That seems to be the stress test here. It more or less goes through each language's syntax looking for a match using regular expressions. That's where the JS -> IL libraries seem to fall short. I suspect only V8 or Chakra will pass that kind of test. |
Perfect! I was just about to ask if you had a good test case... |
Ok, updated #442 with a new test case with commit 4720180. It's a simple one, but definitely the stress test of a JS engine I think due to how highlight.js guesses the language for highlighting. Chances are with Jurasic or Jint you'll see exceptions like |
Can confirm your expected error with Jurassic:
The search continues... |
Yeah, I think JsEngineSwitcher is the only way to go here. I've got like 90% of an implementation going where I've abstracted it out so that it is only in the Core library. Need to regroup my thoughts on testing with it though. |
Might be, but I'm not ready to give up on a fully xplat answer quite yet 😉 I'm going to play around with Jint a little bit and see if I can't figure out how to fix/swap the regex handling. This looks like a pretty specific edge case with character class escapes, which is good because it hopefully means there's a consistent mechanical fix. It's not just .NET either - PCRE/PHP can't handle that expression either: https://regex101.com/r/FguKcY/1 In any case, I really like the idea of exposing a JS runner abstraction through Wyam.Common/Wyam.Core. That way it doesn't matter which engine we use and we can swap it out later if we need to. I'm interested to see what you came up with as far as the abstraction API (no rush though - ATM I'd just like to see if I can get one of the managed engines to work). |
AHA! Got to the bottom of this. The problem is the So since this looks like a bug inside highlight.js I was wondering where it was coming from. It's in the Ada language highlighter. Pretty sure that one's not too critical for us. I also found one instance of another similar JavaScript-only character class By deleting the So here's what I propose:
|
Well hot damn. That's fantastic. |
Had a chance to play with this some last night, but ran into some more roadblocks. Might be poor JS skills on my part, but I do fear this might fall into the not possible land without some serious hacks. Problem 1 - sass.js uses ES2015. Jint only supports ES5 right now (although it looks like Jint 3.0 will support ES2015 which is nice). Messed around with a couple of polyfills like I added ChakraCore to the test projects which has ES2016 support and ran into the next hurdle. Looks like sass.js does some detection trying to figure out what environment it is in. It guesses we are a shell operation (good!) but it expects And then the third problem - file system access. Need someway to plug into their callbacks so that we can hold it's hands when So long story short :-). I went hunting for other libraries but even in the node world the best solution is also a wrapper for libsass. It looks like libsass.net is tracking better support for Core support here. Might be wise just to rely on it rather than trying to force the issue with javascript IMO |
This more or less copies the LESS module but adds Sass processing using LibSass.Net. LibSass.Net is a wrapper around the C library LibSass which worried me a bit, but everything seems to wire up just fine. The test project is pretty simplistic. I would have liked to have a few test cases for testing out that I got the include functionality right, but I couldn't wrap my head around how to do that easily. But basic verification of a successful call and a failing call are there for now.
I never made much progress with getting sass.js to work. My javascript skills just aren't there. Figured I'd at least get this PR up to date though. |
Original code was modifying the class level list on each run in parallel. Not smart. This creates a new array if it is needed rather than adding to the class level instance.
Cool, thanks. I'm aiming for a release early next week with basically what's already committed. After that's out I'll take a look at this one and see if I can help at all - would love to get Sass support with the new Bootstrap on the horizon. |
Looks like an alternative library that is on the path to .NET core support is LibSassHost. Tricky part here is that it still requires the native libraries for Libsass and there are four separate packages for each platform. 😕 |
I'm not letting this go easy into that good night 😄 spent way too much time doing server side sass processing for a side project. LibSassHost seems to be the better option here, and looks to be the best cross platform option. I think it might just be a matter of bringing in the root library and all four of the platform assemblies. It should just find the right one at runtime and be good to go. The next issue would be that this would also require VC++ 2015 runtimes to be installed though. That's going to be an issue no matter what libsass wrapper is used. Not sure what could be done there other than fail gracefully and point them towards the installer (or choco package). I think the target audience for wyam more than likely does have it installed anyways, but it is definitely another stumbling block. |
439cbec
to
340dd18
Compare
Thanks again for the hard work on this one! I just merged it in and then did some refactoring, but the head start on the Sass module was much appreciated. Ended up being able to keep the entire public API you wrote. |
This more or less copies the LESS module but adds Sass processing using LibSass.Net. LibSass.Net is a wrapper around the C library LibSass which worried me a bit, but everything seems to wire up just fine.
The test project is pretty simplistic. I would have liked to have a few test cases for testing out that I got the include functionality right, but I couldn't wrap my head around how to do that easily. But basic verification of a successful call and a failing call are there for now.
I originally started out making this its own separate Nuget package, but I figured with LESS being built in it would only be a matter of time until someone else wanted Sass support and having it out of the box probably makes more sense in terms of growing the user base via out of the box features. I could easily rip it back out if you want to go the seperate package route.