I would like to see if I can use scittle from inside a Swift playground. It must be possible. I was able to load the file and evaluate the module without errors. However, after that I'm pretty much lost. The file I'm using is scittle.min.js from JSDelivr. Before I set up the scittle dev env on my system, is there some way I can bundle everything in one file but it's not optimized? There is a bb dev task but that might not be bundled.
@gerome.bochmann You can compile with :optimizations :simple to get one file without optimizations
I'm not sure how Swift relates to JavaScript but I'd like to hear more about it. I'll check back in tomorrow after getting some sleep
Yes, I’m going to need some of that too.
So, I added a new task, created a new build for shadow-cljs. I ran npm install and then bb tasks to see if my task had registered. Afterwards, I ran bb ios and got the attached error. I also got this error when I opened VSCoded because Calva complained about it and told me that the build might not work correctly. I'll attach the changed files, also because I'm not sure if I'm doing this right :D
Alright, now calva says that shadow-cljs is not installed. I might have to read the docs for shadow-cljs. My only project in cljs was done with figwheel-main.
Alright, so, I’m in a little bit of a dead end right now. I created a minimal project and targeted node and none and in both cases the Google Closure code relied on something that did not exist and the code execution did not reach the namespace I created. I managed to get the namespace to run and execute my function but only by manually deleting Google Closure code from the compiled js file. However, I still think that this is possible. I hear that there is react native applications written in ClojureScript that run in iOS. However, I used cljs.main for this. Maybe I should use shadow-cljs. In addition to that there is [replete](https://github.com/replete-repl) which is using some compiles version of clojurescript from [planck](https://github.com/planck-repl/planck)
Ah I see. I think what you might need is :target :esm which is fairly neutral, as in, it doesn't assume any target specific stuff
This is the same target that nbb uses so if you're looking for an example, look over there
Try npm install
Hm, I did that and when I run it again, it says all is installed. The error log above is looking for some .cp file in .cpcache but I thought that is only available after compilation.
What babashka version do you have
> Library org.babashka/sci has prefix sha, use full sha or add tag Do you still get that?
Can you push the branch you're working on? This is easier than looking at snippets of code in slack
I'll take a look in an hour or so
Sure, no hurry, though. I have errands to run today and my family needs me as well. I'll try to find some time later on. I'll let you know.
It could also be that this is something with my system. I'll go and see if something similar is occurring in other repos as well.
Can you also try with the vanilla scittle branch?
without making your own changes
I’ll try but as I wrote, this error occurred right when I opened Calva for the first time.
I'm only interested in the output of bb dev in the main branch of scittle without any of your changes
let's leave calva out of the equation for a minute
Sure!
Here's the output. I also tried on a different system, and did get an error but a different one. 😊 So, it's probably my system configuration.
Gotta run now.
Can you just execute clj -Stree -A:dev and pos the output here?
Can you do cat deps.edn?
I can't explain this error. Can you do clj -Sforce -Stree -A:dev?
Same as without -Sforce
weird
what is your clojure --version
can you upgrade? maybe it helps
I'll try it
or are you missing one digit at the end?
Yes, it's 1224, sorry
😄
ok, that's the newest
can you try with -Srepro?
Same
I would bring this to #tools-deps - I don't know what's wrong
Alright, thanks a lot for the patience.
it might be your git version perhaps
can you do git --version?
I have:
$ git --version
git version 2.37.0 (Apple Git-136)2.39.2
should be good I think
Let me talk to #tools-deps and see what they're saying. I'll get back to you as soon as I know what's wrong.
ok
Just tell them that clj -Stree -A:dev isn't working
Okay
and point them to the scittle repo
Will do
so we got that out of the way now
Yeah, I just ran my custom ios task. I’m going to have lunch with my family now. Will get back to you later.
Alright, I was able to compile scittle with different optimizations but I run into a couple of problems on the Swift side of things.
First of all, this should in principle be possible. iOS has https://developer.apple.com/documentation/javascriptcore which allows evaluation of JavaScript. It's specifically meant for running JS code from within Swift and even treat JavaScript entities such as functions and data structures like Swift entities. This is pretty cool.
However, what I need is just Scittle's (eval-string). I was hoping that if I evaluate Scittle I will have access to the module somehow but I'm not even sure if it's properly loaded as the evaluation function just returns undefined for stuff like 1 + which is obviously broken JS and should cause some kind of error. I think part of the problem is that Scittle is meant to be run in the browser and there are references to window in the compiled code. So, I suspect it's not even loading. If I try to run it in node it just breaks. I tried changing the target to :node-library but that caused some errors, so I need to take some time and look into it more closely.
If you're not going to use a browser, it may be better to use SCI directly
Just look how SCI is used in scittle. There isn't much going on there
Alright, I'll take a look.
core.cljs is only 100 lines or so, you can just rip out the stuff you need
or delete the stuff you don't need
🙂 Okay, I'll take a closer look.
Instead of this 'js js/window it's better to write js/globalThis
I'll change this in scittle now
Then you can delete this: https://github.com/babashka/scittle/blob/cfaf6b0b33e6a2fd1fb82ef99871be38ce0e5c53/src/scittle/core.cljs#L66-L104
and also you won't need reagent etc, so I'd also leave that out (just delete it from the shadow-cljs.edn)
Yes, I've done that already.
About the window reference. That was in the compiled code. So, I'm not sure if you have actual references to it in the cljs code 🙂
These are good ideas. I'll take them into account with my next steps.
Starting small is always a good idea.
I removed the window reference from scittle core.cljs now on master
but it still has references to js/document to load the script tags, you can remove those
sorry, my push didn't work, it's now there