Fork me on GitHub
#babashka
<
2023-07-31
>
kenny16:07:26

Hello 👋:skin-tone-2: I’m seeing a difference in behavior between cli and bb tasks and am curious why. I build my cljs like so.

clojure -T:build build-cljs
This works as expected when running in the terminal. I define a bb task to run the same thing.
cljs:build-prod {:doc  "build release CLJS"
                 :task (clojure {:dir "."} "-T:build build-cljs")}
And run it.
bb run cljs:build-prod
Exception in thread "main" Syntax error macroexpanding at (user.clj:1:1).
	at clojure.lang.Compiler.load(Compiler.java:7648)
	at clojure.lang.RT.loadResourceScript(RT.java:381)
	at clojure.lang.RT.loadResourceScript(RT.java:368)
	at clojure.lang.RT.maybeLoadResourceScript(RT.java:364)
	at clojure.lang.RT.doInit(RT.java:486)
	at clojure.lang.RT.init(RT.java:467)
	at clojure.main.main(main.java:38)
Caused by: java.io.FileNotFoundException: Could not locate sc/api__init.class, sc/api.clj or sc/api.cljc on classpath.
...
Now, I have require sc.api in a user.clj file that is present only when the :dev alias is enabled. Afaict, that alias is not enabled here. Any idea why this may be happening?

2
borkdude16:07:59

{:dir "."} isn't necessary when you are already in the current directory, not sure why you added it

borkdude16:07:56

perhaps try erasing .cpcache and re-run. else, create a repro and I'd be happy to clone and debug

kenny16:07:46

Copy paste from the kit template 😃

kenny16:07:55

Huh, ok so not expected. I’ll try that.

borkdude16:07:36

yeah, it should work, just wondering why they did that

2
kenny16:07:50

So the issue still occurs after deleting cpcache. I’ll try to make a repro.

borkdude16:07:08

ok, will look after dinner, thanks

borkdude16:07:15

(it's dinner time here now :))

kenny16:07:30

Enjoy 😋

kenny16:07:36

So you’re going to laugh… 😅 I’m new to bb. I jumped to the task runner docs in the book and copied https://book.babashka.org/#_introduction: bb run clean. I assumed the syntax for running commands was the same as npm. e.g., to run a named task, you do bb run [task]. The kit template I copied happened to define a task _named_ run!!

run {:doc  "starts the app"
     :task (if (fs/windows?)
             (clojure {:dir "."} "-M:dev")
             (shell {:dir "."} "clj -M:dev"))}
This task enabled the :dev alias which added my dev user.clj to the cp, resulting in this error. Weird set of things. I have my answer now — delete the run task.

borkdude17:07:29

I think bb should emit a warning for this case, I think there's already an issue about it. glad you solved it

borkdude17:07:51

you can just rename the run task to dev, that's how I usually call it

borkdude17:07:08

perhaps you can even contribute this back to kit, so others won't run into the same

elken06:08:23

Maybe a simple log line at the top of execution [bb] Running task "run"