Elasticsearch-Exporter
Elasticsearch-Exporter copied to clipboard
Revisit transform function
Referencing pull request #119 and @harelba.
It still seems to me that this could be done easier (and potentially faster) without building your own module. Something along the lines of:
let content = fs.readFile(file);
let transform = file.test(/(^exports|module.exports)/m) ? require(file).transform : eval(content);
Note: The changes in Node v6.0 show that the module interface is not necessarily fixed and could change in the future (haven't checked if this implementation is broken in that version).
Also this needs to be documented in the readme.
Hi @mallocator , sorry for the late reply, I was a bit sick for a few days...
I believe that fn-encapsulate needs to be eventually treated as a 3rd party module and not an intrinsic part of es-exporter. In fact, I'll probably push it to npm at some point, relieving es-exporter from its source code and logic.
In regard to its implementation, I personally don't like eval(), since it allows for many issues which are mostly non-debuggable, not to mention the namespace mixups that can happen (e.g. someone will call the function with the same name as one of the es-exporter's function and override it without no one noticing).
In that regard, you are definitely right that compatibility with node v6.0 will be required by the fn-encapsulate module itself. I'll take a look at that and perhaps fix fn-encapsulate to something which will ensure compatibility.
btw, I have to say that me and my team have actually used the transform capability already several times, saving us hours of manual work and debugging.
Harel
Glad to hear that you guys can make good use of it. In the end that's why I published this tool to the community and still at least try to maintain it.
I agree, a separate module might be a better idea. Modulizer, ah no that already exists. Capsule - already taken. You'll find a good name. As a byproduct of so many things being broken by v6 right now, I realized that there has to be a way to get the Module version (new one is 48 I think). Based on that you could provide specific implementations for the individual interfaces, if there are such differences.
You could try to shield against eval()'s shortcomings, but I agree it's not the safest or easiest method. Somewhere I assumed that that was the original intention, maybe not in your pull request but somewhere in a community request. I think someone mentioned passing in a function from command line.
In any case, looking forward to the new module and I will integrate it when it's ready.
Great.
Really appreciate your efforts on this tool. I'm sure it helps lots of people all around.
I'll update once it's a separate module. Harel
Yes, a little late, but I've moved on to other projects. Unfortunately, I can't point you to any other repo that forked and continued the work here, so you'll have to look for another solution, although I believe AI will soon make all of these little tools obsolete.
Most functionality was broken when ES moved to v6, and I don't even know what version we're on today, so it's no surprise it's broken. If there's huge demand I may come back to this as I was working on a more generic implementation with drivers for different DBs, a web GUI, and other little improvements. For now, consider this project abandoned 😢. One person can only do so much.