clojurescript

Giu 2025-11-06T12:54:49.276429Z

Hi. Just for fun I'm trying to develop a JS plugin for an application I'm using, using clojurescript (as far as I understand about clojurescript is possible). Is not working and trying to understand why, I noticed I have a simple function

(defn decir-hola-run [_ctx _context]
  (println "¡Hola desde la acción decir_hola!")
  {:message "¡Hola! Acción decir_hola ejecutada correctamente."})
But in the generated JS file, there is nothing about my "Hola" strings. At the end, what I'm trying to do the same as this JS when loaded, but I must be doing all wrong because I don't see any trace about my code in the generated JS file):
module.exports = {
  decir_hola: {
    description: "Muestra un mensaje simple",
    run: async (args, context) => {
      console.log("¡Hola desde decir_hola!");
      // Podrías usar aquí mecanismos Saltcorn para mostrar toast si la API lo permite
      return { success: true, message: "¡Hola desde la acción decir_hola!" };
    }
  }
};

Roman Liutikov 2025-11-06T13:00:38.296339Z

You have to explicitly ^:export your defn

Roman Liutikov 2025-11-06T13:01:08.110989Z

And specify build target based on your JS env, browser or node

Roman Liutikov 2025-11-06T13:01:58.520489Z

Or just do manual module.exports in cljs same way as you do it in js

Giu 2025-11-06T13:03:37.507929Z

Sorry, that was not the complete code.

(ns plugin.correos-api)

(defn decir-hola-run [_ctx _context]
  (println "¡Hola desde la acción decir_hola!")
  {:message "¡Hola! Acción decir_hola ejecutada correctamente."})

(def decirhola
  {:decir_hola
   {:description "Mostrar un saludo simple"
    :run decir-hola-run}})
And this is the shadow-cljs.edn
{:source-paths ["src"]
 :builds {:app {:target :node-library
                :output-to "out/correos_api.js"
                :exports {:correos_api plugin.correos-api/decirhola}
                :closure-defines {goog.DEBUG true}
                :compiler-options {:optimizations :none}}}}

Giu 2025-11-06T13:04:53.430449Z

BTW, because the idea was to get something fast just to test if it's possible to do it and work, is AI code

p-himik 2025-11-06T13:33:12.560209Z

Was the file that you were checking built with a release build?

Giu 2025-11-06T13:34:00.563539Z

Sorry @p-himik but I'm not sure I understand you. New rto clojure and more new to clojurescript

p-himik 2025-11-06T13:37:59.205859Z

With shadow-cljs and other similar tools you can make two kinds of builds: for development and for production. The former lets the code be reloadable, doesn't optimize things, etc. The latter does a lot to your code. If you were checking the dev code, there are multiple files and the top-level file only loads other files. The top-level file itself won't have any useful code, it won't have your strings. But some other files will. In a production file (with shadow-cljs, it's created with its release command), every module has just a single file. Since you don't define any modules in shadow-cljs.edn, it will be just a single module, with just one file - all the strings should be there.

Giu 2025-11-06T14:48:00.672169Z

Ok, that makes sense. Now I know why maybe I don't see my code, my issue is how to detect if the generated JS makes the same at the end because the third app is not showing me the action. Need to do more testing

Giu 2025-11-06T14:48:07.037419Z

thanks

p-himik 2025-11-06T14:56:01.578339Z

I'd try first with a production build to confirm that it works.

Giu 2025-11-06T14:57:01.309509Z

Yes, . I will try to get it working with a pure javascript module, then will trasnlate to clojurescript because I noticed several issues here

Giu 2025-11-06T14:57:10.385159Z

not related with clojurescruipt

Giu 2025-11-06T15:49:53.392549Z

Finnally got it working!!! yay!!!!!

🎉 1
Giu 2025-11-06T15:51:46.834679Z

"clj->js", and ":exports-var" in shadow-cljs.edn were the key

2025-11-06T13:29:20.574709Z

I have forgotten why it is in cljs you do

(extend-protocol Foo object ... )
or similarly, string. are there any docs on this? tried to find but failed. only this https://www.exchangetuts.com/extend-protocol-in-clojurescript-to-get-value-from-native-js-object-1641206764327839 which doesnt explain also, what if you want to extend to some other 'built-in' type such as js/Foo.Bar ?

rolt 2025-11-06T15:14:21.299099Z

There is a list here: https://cljs.github.io/api/cljs.core/extend-type

🙏 1