This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-09
Channels
- # beginners (91)
- # boot (5)
- # cider (30)
- # clara (16)
- # cljsjs (3)
- # cljsrn (6)
- # clojure (84)
- # clojure-dev (4)
- # clojure-dusseldorf (1)
- # clojure-italy (15)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (120)
- # clojurescript (54)
- # core-async (25)
- # core-matrix (1)
- # css (2)
- # cursive (20)
- # datomic (28)
- # editors (11)
- # emacs (6)
- # figwheel (4)
- # figwheel-main (28)
- # fulcro (36)
- # graphql (7)
- # hyperfiddle (2)
- # jobs (6)
- # jobs-discuss (10)
- # lambdaisland (1)
- # lumo (3)
- # nrepl (20)
- # off-topic (24)
- # pedestal (2)
- # protorepl (3)
- # reagent (3)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (26)
- # rum (1)
- # shadow-cljs (247)
- # spacemacs (29)
- # tools-deps (12)
- # vim (15)
How does shadow
handles npm transitive deps? Core has deps.cljs
I wonder whether I can rely on it in shadow
@lee.justin.m say you have a cljs dep that includes an npm dep. You want to consume that in shadow
you have to add it to your package.json. e.g., reagent requires react. you have to add react to your package.json and install it via npm
Uhm, I thought this was a thing in shadow as well, but maybe Thomas was against it and therefore not implementated: https://dev.clojure.org/jira/browse/CLJS-1973
In your scenario a user of many lib should know and include all the npm transitive deps manually
i’m not 100% sure what he’s talking about, but i think npm-deps actually shells out to npm
in shadow, you need to install npm modules yourself, which you can do via npm or yarn
So yeah, that means that I would need to know what npm deps each lib is using. Example, cuerdas
uses xregexp
, if I want to use it I need to install it manually?
Yeah well the answer seems yes
It feels a bit backwards
having manually packed npm dependencies is fine when you have one-offs, like in cuerdas. but the moment you start including, say, more than one react library, it’s a nightmare
Say you are using 100 cljs libs including 100 npm deps...I do not think this method scales 😄
you would never get 100 cljs libs with 100 npm deps to work if they all had hardcoded crap installed
Maybe I am missing something...
What does hardcoding means?
Each cljs dep declares what it is using
cuerdas, for example, literally includes the javascript in its distribution. so if some other library has xregexp, you’ll get two copies
Yep that is not good ok
Vanilla cljs allows an :npm-deps
in deps.cljs
in your jar
So that you can transitively know which npm dep you will be using
And shell out to npm install
Cuerdas' current way is not optimal if it does the bundling and I agree with you there
yea i don’t know what npm-deps is doing under the covers (I understand that it uses npm, but beyond that, it’s a mystery to me)
i think at this point in time, most libraries (every one that I’ve looked at) that includes npm stuff just bundles the npm in the distribution
Yeah that's bad, but: > ClojureScript libraries that package foreign dependencies can also benefit from these enhancements. Ticket CLJS-1973 adds support for the :npm-deps option in deps.cljs files, allowing library authors to develop and distribute libraries that directly depend on Node.js modules.
https://anmonteiro.com/2017/03/requiring-node-js-modules-from-clojurescript-namespaces/
This is how it should be done if I understand correctly
Not sure though 😉
there are a couple of things to know (that aren’t obvious from that article or the official docs). (1) npm-deps will run the npm module through advanced compilation, which may or may not work, and (2) it seems incredibly brittle and basically impossible to debug. I believe that is why dnolen published the webpack guide
Agree and switched to shadow for exactly those reasons
Still, a way to declare and detect transitive npm deps seems good
But that's what the deps.cljs
is for I guess
And note "I am guessing"
Will actually try it out tomorrow
whether shadow can or should interpret npm-deps is something thomas would have to answer
Ah ah! I hear you
Cool so I'll stay tuned, thanks for answering 😉
seeing as I installed a cljs dependency just now and a bunch of stuff magically appeared in my package.json when I did git status
😄
@lilactown whoa. oh fascinating. so you installed a cljs dep that had an npm-deps in it, and shadow added that to your package.json?
deps.cljs defined here: https://github.com/nubank/workspaces/blob/master/src/deps.cljs
@richiardiandrea there’s your answer. it does respect deps.cljs
Awesome @lilactown @lee.justin.m with this answer in mind my goal is to check if it works with cuerdas
and fix it if not. Thank you!
@richiardiandrea deps.cljs
works BUT in case of the shadow-cljsjs
compatibility packages no deps.cljs
is provided. that is because there is no way to selectively install :npm-deps
. Since this package contains a lot of cljsjs.*
shims adding a deps.cljs
would always install too many packages. https://github.com/thheller/shadow-cljsjs
FWIW the thing I don't like about deps.cljs
and :npm-deps
is about their interaction with the compiler. using them to declare actual npm dependencies is fine by me
So I want to set some env vars that my cljs app should read to know e.g which API url to make requests to
https://github.com/shadow-cljs/quickstart-browser/blob/master/src/starter/browser.cljs#L7-L12
it is absolutely fine and recommended to pass whatever "env" vars you want to the init method
you can also use :closure-defines
https://shadow-cljs.github.io/docs/UsersGuide.html#closure-defines
you can also use :closure-defines {some.app/var #shadow/env "MY_VAR"}
if you are deadset on using environment variables
I would expect one sets them only once when starting dev server or while doing advanced compilatiion so recompiling to get the changes in doesn't sound like a problem since as the closure defines describes it they are compile time constants
and keeping them out of the compiler has many benefits, like being able to easily change them
ok here's a situation. I set it in the html and read it in my init fn then from there I use a setter to create a sort of global for the app object that other functions can access
I was wondering whether to use something like a build hook or sed to set the necessary vars in the index.html file
you can totally use env vars if you want to ... I just don't recommend it. up to you what you do
yeah the generate-prod-index.sh would edit the html file to have the necessary values for vars
you can also split the shadow/release
call into calling (shadow/get-config :my-build)
updating that config (its just a map) and then calling shadow/release*
with it
is there a way to get closure to chill out about This code cannot be converted from ES6. extending native class: Array
I’m trying to mess with the compiler options and adjust what it expects as input/output, but it’s not working quite yet
a library I’m trying to do use does something akin to:
class Foo extends Array {
...
}
which Google Closure cannot convert to ES5I had to tell a bunch of contractors at work that no, you cannot deliver a bunch of internal npm packages that have JSX in them 🙃
but the file is not properly identifed as es6 since it doesn't have any import/export statements
> Yes, Pt extends Float32Array so that we can keep all the native functions while adding new ones.
it’s not babel AFAIK
[:workspaces] Compiling ...
Closure compilation failed with 1 errors
--- node_modules/pts/dist/pts.js:288
This code cannot be converted from ES6. extending native class: Array
@lilactown yes its not babel. I mean did you try babel manually since you said "babel and closure fail"
oh I see what you mean. there might be a babel plugin we can use, but usually babel also cannot handle this
:thinking_face: so should I vendor the lib and run babel on it, since shadow isn’t detecting that it’s ES6?
since I have no idea what pts actually does I could use some help with the verify part
what you want to do is: in your project dir run npx babel --presets env node_modules/pts/dist/pts.js -o node_modules/pts/foo.js
@lilactown seems to work if you set :js-options {:language-out :ecmascript6}
and docs sounds kind nice, could be cool to have a functional cljs wrapper around it
yeah I’m going to get something working and then maybe start hacking on a CLJS interface
@thheller Do I need to do anything to turn this JS object into a clj(s) obj <script>starter.browser.init({url:"
@urbanslug dont need to use json. js->clj
it fine or just normal js interop
has anyone used shadow-cljs to develop on a raspberry pi?
lol nice
well the approach i was thinking was running shadow-cljs + emacs on my laptop and pushing the compiled js to the raspberry pi
is there a hook somewhere in shadow-cljs to do this sort of thing?
ideally i’d have a dev environment with hot code reloading
the only hooks i see are inside JS
yes a node script
ssh at the moment 😅
yeah i could do that
well what I would probably do a) mount a sshfs drive on the pi that points to your local project
cool, what’s the issue you fixed?
and thank you!
i see, so the above approach won’t work yet right?
ok no worries
also congrats on the clojurists together grant, well deserved!
it’s definitely good for the community
More of a cljs question. I set a var as you said @thheller but when it comes to retrieving it from the app-state does something change? all my attemps to retrieve give me null/undefined
(-> @app-state :config :url)
however it's there when I console log the (:config @app-state)