manastech/middleman-search

Replace therubyracer with execjs

Opened this issue · 4 comments

When user already has nodejs installed, (s)he really don’t want to install therubyracer and compile v8. It’s very problematic, does not work in many environments (e.g. on grsecurity kernel), other Ruby implementations, and takes long time to compile.

The correct solution is to use execjs which allows to use various runtimes.

@jirutka I totally like the idea, but I'm not sure how easy it is to implement.

It seems execjs has the lowest common denominator of features from the different engines, so it may not support everything we need.

Do you have a good execjs tutorial or a project already implementing it? I couldn't, for example, compile multiple js files into the same context - maybe concatenating the sources, but I'm not sure that'll help us.

Anyway - I'd totally love a PR, but a good example showing how to use execjs could also help to get this done 👍

…but I'm not sure how easy it is to implement.

Me neither. I thought that it should be easy, but after reading the code and ExecJS API, I’m afraid that it will not be so easy.

Do you have a good execjs tutorial or a project already implementing it?

I’ve tried to find some examples, but without much success.

I think that it’d be more feasible to reimplement the whole initialization logic in JavaScript and just pass data from Ruby as a serialized JSON object. Something like in https://github.com/18F/jekyll_pages_api_search.

I think that it’d be more feasible to reimplement the whole initialization logic in JavaScript and just pass data from Ruby as a serialized JSON object. Something like in https://github.com/18F/jekyll_pages_api_search.

I'd really love to see your PR 😆😇

Jokes aside, that may be a lot of work for not-that-much gain. I know installing therubyracer is an issue itself, but "it works on my machine", he. I don't see we're doing this in the short term, unless we find a really good reason to do it ¯\_(ツ)_/¯

I gave it a try (PR #24)

In the end it was more like a search-and-replace task, because the core logic didn't change. The hardest part was translating the Ruby-JS/V8 mixture to pure JS.

I'm not 100% sure this is the correct way and there's certainly room for improvement, but "it works on my machine" 😉

I tested it sucessfully with Duktape and nodejs. JScript didn't work, but that's because the Lunr code cannot be executed by JScript.