This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-06
Channels
- # beginners (137)
- # cider (60)
- # cljs-dev (52)
- # cljsrn (5)
- # clojars (15)
- # clojure (156)
- # clojure-brasil (1)
- # clojure-dev (7)
- # clojure-italy (13)
- # clojure-serbia (2)
- # clojure-spec (12)
- # clojure-uk (76)
- # clojurescript (129)
- # core-async (27)
- # core-typed (1)
- # cursive (3)
- # datomic (105)
- # devcards (39)
- # emacs (10)
- # figwheel (1)
- # fulcro (68)
- # graphql (6)
- # juxt (3)
- # klipse (85)
- # lein-figwheel (47)
- # leiningen (3)
- # midje (1)
- # mount (26)
- # off-topic (71)
- # om (4)
- # overtone (4)
- # parinfer (3)
- # pedestal (4)
- # portkey (37)
- # re-frame (37)
- # reagent (13)
- # reitit (3)
- # ring (1)
- # rum (5)
- # shadow-cljs (191)
- # spacemacs (35)
- # specter (26)
- # tools-deps (45)
- # vim (20)
so in order to bundle in node, which target should I use? I am adding the preamble so I need I thing either :node-library
or :npm-module
because :node-script
prepends a #!
and webpack barfs 😄
Hi, trying to setup and inspect my production build found release-snapshot
really usefull ( https://clojureverse.org/t/help-wanted-release-bundle-size-visualization/871/11). Could not find in the user guide release-snapshot
any reason why it's not there ?
@claudiu yeah I still need to mention that. It is a bit unfinished thats why it is not mentioned yet.
Cool 🙂 Playing with react-semantic-ui, it really helped a lot to understand why my bundle-size grew so much. Are there any optimizations that I can opt-in to get better build sizes with shadow-cljs (ex: change the js output to es6, ie11+) ?
I asked on #clojurescript about issue with https://github.com/venantius/accountant . But I would like to be sure: is it shadow-cljs issue or accountant issue? Looks like accountant, but who knows.
@kwladyka how's your :devtools in shadow-cljs.edn config? You define correct http-root?
Oh I just discovered without accountant I have the same issue, so it is about shadow-cljs
When run http://localhost:8020/foo/bar/baz but app works with http://localhost:8020/foo (which doesn’t exist too)
and of course it works with http://localhost:8020 🙂
@kwladyka what your :asset-path
look like (in the build config)?
@wilkerlucio :asset-path "js"
that looks like the issue to me, try /js
instead
no worries, this is the base path for js requires, so if you have it relative it only works on the root
glad to help 🙂
@thheller hey, this might be something stupid I'm doing, but I'm getting some warnings that I didn't expect in shadow, I create a new namespace, both clj and cljs separated files (clj for a macro), I did :require-macros
on my cljs file, but when I use the macro shadow is warning me that I'm using an undefined symbol, but my macro is a def-like macro, so I don't understand why I'm getting these warnings
this is my macro code:
(defmacro defcard [sym settings]
(let [fqsym (if (namespace sym)
sym
(symbol (name (ns-name *ns*)) (name sym)))]
`(init-card ~fqsym ~settings)))
macro usage:
(ws/defcard sample-card
{::ws/node-props
{:className ""}
::ws/render
(fn [node]
(gobj/set node "innerHTML" "Hello World"))})
warning:
5 | (ws/defcard sample-card
-------^------------------------------------------------------------------------
Use of undeclared Var my.ns/sample-card
am I missing something here?
@wilkerlucio Is it possible to require macro in clj in cljs file?
thats how you have to do it, macros in cljs only exists in clj space, since they run at compilation time
Oh I see. I didn’t write macro for cljs. I expected macro for cljs need to be in cljs files.
@wilkerlucio is init-card
itself a macro which expands to (def ~the-name ...)
? I don’t see a def
form in the macro so I don’t know where that var is being defined
I said def-like just in the sense of syntax, init-card
is just a function
I don't actually def anything, the macro is just a sugar to expand the symbol
Now it is just expanding to a fully qualified symbol which hasn’t been defined anywhere so you are seeing that warning
Most def-style macros use a real def
behind the scenes to create a var which can be referenced like any other. (Not all of course.)
fulcro for example has the defmutation macro, it doesn't output anything by default, also don't give warnings
I'm pretty sure that's is possible to do, and shouldn't trigger a warning, my guess is that I'm just missing something stupid
I'm registering it on an atom for later usage
yes! that's the stupid thing I was missing, thanks 🙂
When I start shadow-cljs, it prints:
shadow-cljs - Using IP "10.83.10.6" from Interface "tun0"
Jun 06, 2018 1:56:37 AM shadow.cljs.devtools.server invoke
INFO: Found multiple IPs, might be using the wrong one. Please report all interfaces should the chosen one be incorrect.
Jun 06, 2018 1:56:37 AM shadow.cljs.devtools.server invoke
INFO: Found IP:10.83.10.6 Interface:tun0
Jun 06, 2018 1:56:37 AM shadow.cljs.devtools.server invoke
INFO: Found IP:192.168.1.220 Interface:wlan0
Jun 06, 2018 1:56:37 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.8.Final
Jun 06, 2018 1:56:37 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.8.Final
shadow-cljs - server version: 2.3.23
shadow-cljs - server running at
The problem here is that it uses tun0
interface, which is a VPN interface in my case. I casually switch VPN throughout the day, and when I do that, I also have to restart shadow-cljs.
Maybe it shouldn't use tun
interfaces? Is there anything I can do on my setup to make it always use localhost?heya guys, i’m looking for a way to build a release version of my app using shadow that replaces just a few namespaces with “mock” implementations. is there support for this somewhere? i know I can use clojure.defines via the normal compiler config options.. but i wonder if there’s a better approach, or if this is crazy. the intent is to replace just a few functions that do side-effectey/networking things with stubs so that I can run some functional tests without touching the network
@lwhorton generally to mock something in Clojure just use https://clojuredocs.org/clojure.core/with-redefs
For example:
(deftest wfirma
(with-redefs [wfirma.api/request-api (constantly (read-string (slurp "test/bind-input/products-wfirma.edn")))]
(let [products-wfirma (db-products/get-products :wfirma)]
(testing "wfirma -> products"
(is (every? nil? (map (partial s/explain-data ::sp/product) products-wfirma))
"spec")
(is (= "00014" (:code (first products-wfirma)))
"parse")))))
or
(deftest estore->db
(with-redefs [atomstore.soap/connection (constantly nil)
atomstore.soap/get-products (constantly (slurp "test/bind-input/products-all.xml"))]
(testing "atomstore->products"
(is (= (:body (core/app (mock/request :get "/shops/hc/db/products/refresh")))
"done")))))
So you save in some files reposne from server and later use this files to bind reposne from server
yea I wish I could, but my contexts are not great for with-redefs: i have a clj runtime executing webdriver ui tests, so I can’t really with-redef some cljs code to stub out implementations. like I said I think I have to pre-build the cljs component with a “global redef” and then use the clj webdriver to interact for testing
hmm I remember in one project we were starting webdrive ui tests from ClojureScript code, so then it should be possible to do with-redef. I didn’t have exactly this issue before, so I don’t have solution for that.
I still see errors when I compile with deps.edn
, but this time also an error
Failed reading cache for cljs.core: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.FileInputStream@c0ed4f0; line: 1, column: 1893745])
at [Source: java.io.FileInputStream@c0ed4f0; line: 1, column: 1899511]
Failed reading cache for cljs.spec.alpha: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.FileInputStream@5aaab369; line: 1, column: 494770])
at [Source: java.io.FileInputStream@5aaab369; line: 1, column: 501773]
Failed reading cache for cljs.core.async: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.FileInputStream@5b8c485b; line: 1, column: 451425])
at [Source: java.io.FileInputStream@5b8c485b; line: 1, column: 455003]
Failed reading cache for ep-cloud.util: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.FileInputStream@1e9fc7bc; line: 1, column: 59073])
at [Source: java.io.FileInputStream@1e9fc7bc; line: 1, column: 66261]
NullPointerException:
clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:301)
shadow.build.output/flush-dev-js-modules (output.clj:469)
shadow.build.output/flush-dev-js-modules (output.clj:465)
shadow.build.targets.npm-module/process (npm_module.clj:89)
shadow.build.targets.npm-module/process (npm_module.clj:77)
clojure.lang.Var.invoke (Var.java:381)
shadow.build/process-stage/fn--15264 (build.clj:140)
shadow.build/process-stage (build.clj:137)
@richiardiandrea can you please confirm that you are absolutely 100% certain that there is only ONE instance of shadow-cljs running at any given time for the project? not some process running a background racing another process in the foreground or anything like that? there can only be one process active at any given time for a build. I have seen the above error when 2 processes were active and tried to write the cache at the same time. that produced garbage JSON and could never be read again
ps -ef | grep java
arichia+ 23173 22953 0 12:22 pts/1 00:00:00 grep --color=auto java
when it runs it is:
arichia+ 23272 23266 0 12:23 pts/1 00:00:00 bash /home/arichiardi/.local/bin/clojure -J-Djava.util.logging.config.file=/home/arichiardi/git/laputa/lambda-cqrs/.shadow-cljs/logging.properties -Sdeps {:aliases {:shadow-cljs-inject {:extra-deps {thheller/shadow-cljs {:mvn/version "2.3.35"}}}}} -A:cljs-jvm:shadow-cljs-inject -m shadow.cljs.devtools.cli --npm compile init-store
arichia+ 23285 23272 99 12:23 pts/1 00:00:30 /usr/bin/java -Djava.util.... <- shadow?
should I delete some folder?
please send me the .shadow-cljs/builds/init-store/dev/ana/cljs/core/async.cljs.cache.transit.json
file
and a clj -Stree
would help although deps shouldn't play a role here. doubt there is the JSON impl that writes invalid JSON and then complains about it when trying to read it
@thheller Could you please check my message above about tun
devices and constant IP changes? Thanks!
@p-himik yes I'll switch the default back to localhost
. detecting the IP is way too unreliable https://github.com/thheller/shadow-cljs/issues/296
other q: is there a way to export a function as default export? I am trying to achieve this: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node#exporting-a-function
thats currently "buggy" but you can {:target :node-library :exports some.ns/some-fn}
(defn some-fn [] the-exported-fn)
ok let me try that and then I can try to see if I can help with some fix or something..
@thheller just out of curiosity could shadow have an issue with the “use strict” issue that they were talking about in #cljs-dev
probably not since it does the same as webpack and others, ie. wrapping in a function
ah yea that would fix it. i wonder why dnolen doesn’t want to do that. it seems not hard to do and much safer
if you wrap that code in a functions some global it is supposed to create might not end up getting created maybe?
well i’ve never really understood how webpack knows what its supposed to export. you have to manually export every symbol through the iife
the issue is that if you do blind concatenation and a script has a global “use strict”, that will break other parts of code that are not strict compliant
it’s likely that simply removing “use strict” will be okay, though technically you can write code that breaks without it (though not very realistic code, to be fair)
yes. i agree. clearly wrapping each module in an IIFE with a function-local “use strict” is much more robust
so @thheller the exports above does not work for :npm-module
it seems
@richiardiandrea thats why I included :target :node-library
explicitely when mentioning it
index.js
module.exports = require("./foo/your.ns").foo;
and (defn ^:export foo [...] ...)
ok yeah 😄
so what is the difference between library and module ?
oh ok that's is what I need then
sorry I mean :node-library
:npm-module
is mostly intended to be processed by other tools, ie. including cljs output in a webpack build
uhm...ooook
ok right
I can basically pass one file with the exported default and give that to webpack can't I? then it will bundle node_modules
+ mine
I am at the "whatever" is faster kind of point 😄
but does the amazon cloud stuff seriously not support installing packages via package.json
?
well, I am on azure now ......
yeah you can but you have to have one package.json per function
I want to produce one js per function from one cljs project
I know it is weird, but azure wants
fn1
- index.js
- node_modules
fn2
-
fnn
and I want to produce that from a unique clojure project
why? because they will all run in a REPL
and emulate the cloud
ok cool :node-library
works
$ node init-store/unbundled.js
Hello World
:builds {:fn1 {:target :node-library :exports your.fn1/foo :output-to "fn1/index.js"}}
yep that's what I am doing 😉
took a bit of questioning about shadow's options
thanks for your answer btw
never written a azure fn but could add a :target :azure-fn
if it needs some custom processing or config options
it could generate the package.json
and maybe this from metadata? https://github.com/Azure-Samples/functions-node-sas-token/blob/master/GetSasToken-Node/function.json
I think that bundling node in shadow
would already improve things phenomenally. So that you get js + node-modules without using webpack
just abusing metadata on defn
and the target could read that to generate the function.json
Opened an issue for that 👼
Ah yeah that of course is better ;)
Also more work :)))
function.json
contains a lot more
Because a function can bind to many things not just http
For sure
They are static yeah...but then shadow would need to know about azure functions...dunno up to you :)
I think the bundling is a good compromise for me ;)
the target could technically be a library. although its not documented at all so I don't expect anyone to be able to write one.
Ahah ok cool
@thheller so build hooks are always clojure only right? they are executed by the jvm ?
sorry yes, the answer is yes
too bad the hook is not triggered here for some reason
Yeah I wanted to launch webpack on flush but that's ik. Can use bash for now, don't have really time to debug it
> At least one configured stage is required since the hook otherwise would never do anything.
I copied the example in the doc basically
The file I have in my dev
folder is:
(ns ep-cloud.shadow)
(defn hook
{:shadow.build/stage :flush}
[build-state & args]
(prn [:hello-world args])
build-state)
which is :source-paths
and I have :build-hooks [(ep-cloud.shadow/hook 1 2 3)]
latest version
anyone know the require form and symbol to access Button.Group
below via shadow-cljs?
import React from 'react'
import { Button } from 'semantic-ui-react'
const ButtonExampleGroup = () => (
<Button.Group>
from: https://react.semantic-ui.com/elements/button#groups-groupHi guys. First time shadow-cljs user here. I just created a project with reagent, but I get the folowing error when building "The required namespace "react" is not available, it was required by "reagent/core.cljs".
no foreign-libs in shadow, so cljsjs is ignored
@spieden thanks, didn't know that. Now I get a different error, The required namespace "create-react-class" is not available, it was required by "reagent/impl/component.cljs". Do i just :exclude create-react-class when requiring reagent.core ?
@spieden, thank you. And thanks for the docs, I don't know how I missed these beutiful docs. Maybe I'm blind.
welcome to the npm-enabled cljs world 🙂