Skip to content

shadow-cljs support broken in 2.10.+ #15

@thheller

Description

@thheller

shadow-cljs 2.10.+ completely replaces all REPL implementations so the code used by clj-suitable no longer exists. It was never part of any official API so I didn't pay much attention to keeping it alive. I'll see if I can figure out a good way to restore it but in the meantime I would like to provide an official replacement so I can ensure it keeps working in the future.

For that I'd like to know what clj-suitable wants to do exactly. Plain eval I can easily offer and it looks like this is all thats needed?

The most basic form I can offer would be

(shadow.cljs.devtools.api/cljs-eval :browser "(+ 1 2 3)" {})
=> {:results ["6"], :out "", :err ""}

So a function that takes a build-id keyword (:browser is the build-id in this case) and a string of CLJS code. It just returns the results as a edn printed string. The extra map arg could take additional options, like the :ns things should be eval'd in.

(shadow.cljs.devtools.api/cljs-eval :browser "::foo" {})
=> {:results [":cljs.user/foo"], :out "", :err ""}
(shadow.cljs.devtools.api/cljs-eval :browser "::foo" {:ns 'demo.browser})
=> {:results [":demo.browser/foo"], :out "", :err ""}

Question would be how it should handle errors like no available JS runtime to eval against (eg. no connected browser).

This is what it would do currently but maybe it should throw?

(shadow.cljs.devtools.api/cljs-eval :browser "(+ 1 2 3)" {})
=> {:results [], :out "", :err "No available JS runtime.\n"}

Evaling multiple things is allowed. Thats why :results is always a vector.

(shadow.cljs.devtools.api/cljs-eval :browser "(require 'clojure.string) (in-ns 'clojure.string) (prn ::foo) ::bar" {})
=> {:results ["nil" "nil" "nil" ":clojure.string/bar"], :out ":clojure.string/foo\n", :err ""}

Would this be enough for suitable or is there anything else it needs?

One thing I saw it that it always requires an introspection-ns which I could just provide as an option.

(shadow.cljs.devtools.api/cljs-eval :browser "(foo.bar/something 1 2 3)" {:ensure-loaded ['foo.bar]})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions