This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-05
Channels
- # 100-days-of-code (13)
- # announcements (3)
- # beginners (120)
- # boot (17)
- # calva (19)
- # cider (27)
- # cljdoc (3)
- # cljs-dev (1)
- # clojure (138)
- # clojure-dev (5)
- # clojure-italy (5)
- # clojure-nl (20)
- # clojure-russia (3)
- # clojure-spec (14)
- # clojure-uk (119)
- # clojurescript (45)
- # core-async (2)
- # datomic (23)
- # editors (28)
- # emacs (35)
- # figwheel (2)
- # fulcro (26)
- # graphql (2)
- # hyperfiddle (11)
- # jobs (4)
- # luminus (5)
- # mount (2)
- # off-topic (52)
- # onyx (39)
- # reagent (86)
- # ring-swagger (2)
- # spacemacs (20)
- # tools-deps (9)
- # yada (4)
Oh this is great! https://dev.clojure.org/jira/browse/CLJ-1209
Is it possible to read and evaluate a clojurescript string from a clojure context (.clj file instead of .cljs). I know you could do something like this with clojurescript. Is there an equivalent for clojure. Is it even possible?
(ns test
(:require
[cljs.tools.reader :refer [read-string]]
[cljs.js :refer [empty-state eval js-eval]]))
(defn eval-str [s]
(eval (empty-state)
(read-string s)
{:eval js-eval
:source-map true
:context :expr}
(fn [result] result)))
@sneakypeet you could probably try the nashorn REPL but its not exactly setup to be used that way. so yes it is possible but probably requires some amount of setup/effort
So I managed by outputting the js to a file, running clj tools using sh and then slurping the result. Not great but works for my needs 1. assuming clj tools installed 2. make a basic clj project at resouces/inline-js (basically just has the deps.edn with cljs dep) 3.
(ns sneakycode.cljs
(:require [clojure.java.shell :as sh]
[clojure.string :as string]))
(def source-proj "resources/inline-cljs")
(def source-path (str source-proj "/src/tojs/core.cljs"))
(def dest-path (str source-proj "/out/main.js"))
(def out-ns "tojs.core")
(defn- add-ns [s]
(str "(ns " out-ns ")\n\n" s))
(defn compile-cljs-str
([s] (compile-cljs-str "--optimizations advanced" s))
([opt-str s]
(let [code (add-ns s)]
(spit source-path code)
(let [opt (string/split opt-str #"\h")
options (concat
["clj" "--main" "cljs.main"]
opt
["-c" out-ns :dir source-proj])
compile-result (apply sh/sh options)]
(when-not (= 0 (:exit compile-result))
(throw (ex-info "CLJS Compilation Failed" compile-result))))
(slurp dest-path))))
(defmacro compile-cljs [& body]
(->> body
(map str)
(string/join "\n\n")
compile-cljs-str))
;;; USAGE
(compile-cljs
(fn [a] a)
(prn 1234))
š This is exactly what I was looking for š oh well learned some new things. Thank you
I'm having some issues with deps.cljs. I have a :local/root
dependency with a deps.cljs. When I use a classpath relative path to the .js files, I get the error: [Figwheel:SEVERE] java.io.FileNotFoundException: /tmp/hello-world.app/leaflet.pm/leaflet.pm.js (No such file or directory)
(note that it's not looking in src!). Are deps.cljs on the filesystem given different treatment to those found in jars?
Actually, I've been double stupid. It's not even looking in the right directory at all. It should be looking at a folder in /home/dominic/src/...
but it isn't. So it's searching relative to the cwd only?
This appears to be because clojurescript via git behaves differently to cljs via maven. I don't really know how to move forward from that.
@dominicm You built ClojureScript master (to confirm that the difference is git vs. maven, as opposed to 1.10.339 vs. master)?
@grav So long as the symbol can be calculated at compile time, you could write a macro to call resolve
In Lumo, though, you can have a āfull-fledgedā resolve
. Just copy planck.core/resolve
from Planck.
Once Lumo is updated to the latest ClojureScript, and has eval
, it would be trivial to write (see https://github.com/anmonteiro/lumo/issues/397)
cljs.user=> (let [sym (symbol "cljs.core/filter")] (eval `(~'var ~sym)))
#'cljs.core/filter
I have a question about boot. After a production build should the target folder contain a main.out folder alongside main.js? I thought the final artefact should just be a main.js file?....
If you use :optimizations :advanced
the main.js file is all that's needed but if you use no optimizations the files are actually not bundled and loaded separately in the browser
Ok thanks. Am I right in thinking I need to use :foreign-libs
to allow me to use :advanced
with 3rd party libraries?
@mfikes I used git pointed at b1ade48e21f9e7f78d9db74559ce4dd5846d0c94
(tagged 1.10.339) and saw this behavior. When I use a mvn/version of 1.10.339 I don't see it.
@dominicm Thanks. That should work. If you are in a position to create a minimal repro, I'd suggest filing a JIRA.
Wait, sorry. I said that the wrong way round @mfikes. I don't see it with git. I do see it with maven.
(The goal is that there should really be no fundamental difference between Git and Maven, but perhaps there is something subtle going on.)
@dominicm If the files are small enough, I'd use something like this in the description
{code:title=src/user.cljs}
(def a 3)
{code}
See https://dev.clojure.org/jira/browse/CLJS-2917 which this example comes from.@dnolen Iād like to be able to symbolicate stack traces that include code paths from a foreign-lib file. Iāll try to explain what I mean: ā¢ I reference a minified js file as a foreign-lib. ā¢ This js file is included in the cljs output file when using simple optimisations. ā¢ This js file has a source map produced next to it as a side product of minification. ā¢ If a stack trace includes code paths from the js file, itās not possible to use cljs fileās source map to symbolicate the code path. ā¢ Is there a way to somehow include foreign libās source map in the source map for the cljs output file?
Correct. My problem is that I have multiple source maps for a single JavaScript file. One comes from the ClojureScript compilerās output, and the other one comes with a minified foreign-lib
Does anybody have any recommendations for how to open a pdf returned by a get
call in a new window? That caviot is that we need to send a *tolkien in the request header*.
Libraries being used
[cljs-http "0.1.45"]
Without the header, this is done easily with just (.open js/window "uri-to-pdf)
, integrating the header is the tricky part.
You should be able to do the same method as long as you make the pdf a blob
Appreciate it @U5K8NTHEZ
Correct. My problem is that I have multiple source maps for a single JavaScript file. One comes from the ClojureScript compilerās output, and the other one comes with a minified foreign-lib
right what you want just isnāt supported - itās not a much requested feature so I doubt weāll spend much time on that - though if somebody wants to work on that - go for it
I think the Google Closure compiler has an option to kind of "merge" source maps