sci

https://github.com/babashka/SCI - also see #babashka and #nbb
mauricio.szabo 2021-02-19T12:40:12.062300Z

Hi, @borkdude. I'm trying to do something quite bizarre, so let me check if there's a better way with you here 🙂. I want to use SCI on a CLJS project. The problem is that I'll need to alter the source a little bit before I interpret it. In my case, I want to convert every instance of (js/require "some-filename.js") that appears on my code to a string (specifically, I'll replace to the contents of some-filename.js). Does exist a simple way to do this, to make this transformation?

mauricio.szabo 2021-02-19T12:40:36.062900Z

Originally, I was thinking on using rewrite-cljs to make the change, just so you know what are my ideas 😄

borkdude 2021-02-19T12:41:27.063800Z

@mauricio.szabo yes, you can do this quite easily, by using the lower level API, by first parsing the expressions using sci/parse-next, then rewrite them and then evaluating using eval-form.

borkdude 2021-02-19T12:42:34.064300Z

@mauricio.szabo I'm doing something similar in grasp, where I parse expressions and only evaluate the namespace forms after a bit of rewriting.

borkdude 2021-02-19T12:43:20.065200Z

However, why don't you just use :load-fn so users can use the normal require?

borkdude 2021-02-19T12:43:56.065700Z

Ah you are not loading normal CLJS code. Yes, the above approach should then be ok

borkdude 2021-02-19T12:44:16.066300Z

Alternatively you can override another function into js/require possibly

mauricio.szabo 2021-02-19T12:44:28.066600Z

Yes, and I have to bundle the JS lib too, and other strange things 😄