Fork me on GitHub
#shadow-cljs
<
2023-02-13
>
thheller10:02:24

@borkdude what happened to this highlighting thing? code link is dead https://blog.michielborkent.nl/writing-clojure-highlighter.html

borkdude10:02:09

I ended up using a .js highlighter since this simplified building the blog a little bit, but I can dig up the code if you want to look at it, from the git history

thheller10:02:54

so you wouldn't recommend doing the server side thing? or any other issues?

thheller10:02:09

I can dig out the code myself, just thought I ask why its gone 😛

borkdude10:02:40

This is the server side solution: https://github.com/borkdude/blog/blob/293b8883ad96d9dd4a4c14b21aec381b2785b73a/highlighter.clj If you're on the JVM you can use clj-kondo directly rather than the pod. Or leave it out: it only improves the situation for coloring locals that have the same name as clojure vars, for example.

borkdude10:02:09

> so you wouldn't recommend doing the server side thing? It depends: this code is for generating static assets and in the end I went with prism.js which I found not perfect, but good enough, and relatively small

thheller10:02:43

I'm parsing some code in CLJ and just want basic highlighting when dumping it out into html

borkdude10:02:14

feel free to re-use that code, I think it makes sense

thheller10:02:39

thanks, I'll think I go with something like this

thheller10:02:58

I want to make stuff clickable so it takes you to the source location

thheller10:02:09

so can't just use a pure JS highlighter anyways

thheller10:02:15

I think this looks like a good base

thheller10:02:48

I'll tinker and let you know

borkdude10:02:12

I also have a documentation solution which analyzes vars (statically) and adds source links: https://github.com/borkdude/quickdoc Also based on clj-kondo

borkdude10:02:46

but I guess in shadow-cljs you know the source locations at runtime

thheller10:02:52

its for a thing I'm building, similar to clerk in some ways. don't just want to display the code, want to make it clickable so it takes you to the source

Braden Shepherdson18:02:11

is there any way under shadow-cljs to set the Closure options object? I want to set CompilerOptions.setCrossChunkMethodMotion(false) because I'm having issues with Malli caused by https://clojure.atlassian.net/browse/CLJS-3207

thheller18:02:49

:compiler-options {:cross-chunk-method-motion false}

thheller18:02:11

which version do you use though? this should be fixed?

Braden Shepherdson18:02:27

version of which? that bug is still open against CLJS.

thheller18:02:54

shadow-cljs

thheller18:02:05

I hacked reify to emit different code, which should prevent this

thheller18:02:31

should be fixed since 2.20.19

Braden Shepherdson18:02:03

ah, it was 2.19.6. I didn't realize we were trailing that far. let me try that!

Braden Shepherdson18:02:20

works great! thanks for the pointer, I never considered that possibility.

👍 1
jlfischer19:02:02

Is there a way to use build hooks to set Closure defines for the application to pick up later? I’m looking for a way to automatically inject some information about the project’s repository into the application so that I can display a version number, etc.

jlfischer19:02:14

I had seen that, but I didn’t want to have to worry about passing it on the command line. Ended up with this:

(defn- scrape-command
  [args]
  (-> (apply shell/sh args)
      :out
      (string/trim-newline)))

(defn export-repo-version
  {:shadow.build/stage :configure}
  [build-state]
  (let [branch       (scrape-command ["git" "rev-parse" "--abbrev-ref" "HEAD"])
        commit-count (scrape-command ["git" "rev-list" "HEAD" "--count"])
        defines      {' branch
                      ' commit-count}]
    (println (str "export-repo-version - branch is '" branch "', commit-count is " commit-count "."))
    (update-in build-state [:compiler-options :closure-defines] #(merge % defines))))

jlfischer19:02:41

Thank you for shadow-cljs, by the way!

niwinz22:02:51

Hello @thheller I'm not very sure if this is shadow-cljs related... I found a strange compilation output, for the following cljs code (note that the parameter arguments in the protocol definition are all _):

(defprotocol IState
  "Additional state/introspection abstraction."
  (-extract [_] [_ _] [_ _ _] "Extract the current value."))
The generated code looks like this:
// [...]

(promesa.protocols._extract.cljs$core$IFn$_invoke$arity$2 = (function (_,___$1){
if((((!((___$1 == null)))) && ((!((___$1.promesa$protocols$IState$_extract$arity$2 == null)))))){
return ___$1.promesa$protocols$IState$_extract$arity$2(___$1,___$1);
} else {
return promesa$protocols$IState$_extract$dyn_43250(___$1,___$1);
}
}));

// [...]
You can observe that on arity 2 the argument passing on the following function call are all the same (repeated twice) If I define the protocol with argument names, I mean (-extract [it] [it default] [it default default2] "Extract the current value.") The problem disappears and the compilation results in:
// [...]

(promesa.protocols._extract.cljs$core$IFn$_invoke$arity$2 = (function (it,default$){
if((((!((it == null)))) && ((!((it.promesa$protocols$IState$_extract$arity$2 == null)))))){
return it.promesa$protocols$IState$_extract$arity$2(it,default$);
} else {
return promesa$protocols$IState$_extract$dyn_37688(it,default$);
}
}));

// [...]
Is this expected behavior and the _ can't be used repeatedly as param placeholder or there is a bug somewhere? Thank you very much.

thheller06:02:11

interesting, but this would be a cljs issue. not something shadow-cljs influences or controls in any way. given that the defprotocol definitions are also sort of documentation I'd have a hard time figuring out what arguments you are supposed to pass? so not great just definining _ in the first place, but should probably file a bug regardless

niwinz08:02:24

yeah, that was initial only a single first argument with _ that is ok because it represents this but the other one was just quick prototyping.

niwinz08:02:07

I have no permissions on jira, so I guess I need to wrinte on the ask.clojure right?

thheller08:02:56

that is best probably. or ask in #C07UQ678E, best to have a quick repo