This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-21
Channels
- # beginners (55)
- # cider (13)
- # cljdoc (4)
- # cljsjs (1)
- # clojure (11)
- # clojure-spec (7)
- # clojure-uk (9)
- # clojurescript (42)
- # docs (5)
- # figwheel-main (9)
- # fulcro (4)
- # graphql (4)
- # hoplon (27)
- # keechma (32)
- # leiningen (11)
- # luminus (2)
- # nyc (2)
- # off-topic (73)
- # parinfer (1)
- # re-frame (36)
- # reagent (2)
- # reitit (6)
- # ring-swagger (3)
- # shadow-cljs (51)
- # spacemacs (4)
- # tools-deps (17)
- # uncomplicate (1)
has anyone successfully applied the “gradual migration to node_modules” path implied at the end of https://clojurescript.org/news/2017-07-30-global-exports? my app uses a library that depends on cljsjs.react and i’d like to provide that dependency via node_modules instead.. my compiler options include
:npm-deps {:react "16.4.1"}
:install-deps true
and i’ve added a project dependency on a react-npm-shim
artifact I created that contains the following in deps.cljs
{:foreign-libs
[{:file "react/cjs/react.development.js",
:file-min "react/cjs/react.production.min.js",
:provides ["cljsjs.react"],
:global-exports '{cljsjs.react React}}]
:npm-deps {:react "16.4.1"}
}
but cljsbuild is failing to compile the .cljc file that requires [cljsjs.react] with java.lang.IllegalArgumentException: contains? not supported on type: clojure.lang.Cons
(using clojurescript “1.10.339")further info - the exception is being thrown from the dep-has-global-exports? function in the analyzer https://github.com/clojure/clojurescript/blob/b1ade48e21f9e7f78d9db74559ce4dd5846d0c94/src/main/clojure/cljs/analyzer.cljc#L782
I’m building a website for a non-profit I am a part of, and I was hoping of writing it in ClojureScript. The only requirement is that it have a CMS or some other way for someone who is not very technical to update the website. Any ideas on what to use ?
have you read this? https://nordicapis.com/10-frameworks-for-building-web-applications-in-clojure/
dumb nodejs question - how do I set an process env var from CLJS? I know the nodejs process API and have tried various options and can’t find the correct incantation. Any help would be appreciated - thanks 🙂
@raymcdermott (goog.object/set js/process.env "FOO" "BAR")
thanks @thheller - excellent. Any tips on how I can I discover these things independently?
its odd to set env vars at runtime though since .. you know .. they are supposed to come from the env 😉
it looks like there’s also a cljs compiler option you can set at build time :process-shim
https://clojurescript.org/reference/compiler-options#process-shim
is that even possible? I mean what does it mean to change the env variables for a running process?
@j1mr10rd4n that's for something different
ah ok thanks! i’m still getting my head around all the moving parts
certainly in Bash, when you "change" an env var (export MYVAR=value) you don't update the existing var, as visible by ps -p <PID> -wwwwE
you only make that var available locally (as a Bash var, not as an env var) and for subprocesses as an env var
although I can't find a reference, I think that unix env vars are immutable
Yeah, you can
man putenv
A use case is when you know something else in your process is going to read that environment variable and you need to set it in order to affect that other thing.Here is an example: Planck controlling JavaScriptCore via an environment variable: https://github.com/planck-repl/planck/blob/master/planck-c/main.c#L307
Thanks for the pointer
You learn things about Unix even after years
i’ve got a quick question that i’m looking for some help with - it’s about how to do this: “For example, a user could create a cljsjs.react artifact with a declared :npm-deps on React” mentioned in https://clojurescript.org/news/2017-07-30-global-exports i’ve created an artifact with a deps_cljs file that defines global exports but how should that artifact declare its npm dependencies? i took at a guess at putting :npm-deps in the deps_cljs file but that seems to be causing a compiler error
i’m not sure if i should expect it to work or if i’ve found a bug
what do you want to do exactly?
my app uses a library that depends on cljsjs-react, i’d like to satisfy that dependency by providing react as a node_module and shim the cljsjs-react namespace - the penultimate paragraph on https://clojurescript.org/news/2017-07-30-global-exports seems to indicate this is a supported strategy
right
what I do is create empty files declaring those namespaces: https://github.com/pesterhazy/double-bundle
then just set window.React to your preferred React version: https://github.com/pesterhazy/double-bundle/blob/master/library.js#L1
note that the cljsjs.react namespace (like other cljsjs nss) doesn't really provide anything; libraries like React typically grab the library from a well-known location, i.e. window.React
I think the same should be possible using the global exports feature
instructing the cljs compiler to download the library from NPM (using :npm-deps
) is orthogonal to this AFAIK
(note that :npm-deps
still has some rough edges, which is why I use the "double bundle" approach, which is foolproof)
yeah i feel like i might have found an edge…
@j1mr10rd4n @pesterhazy the :global-exports
are only relevant when using (:require ["react" :as r])
. they are not related to cljsjs.react
.
your double-bundle appears to be what is referenced in the 5th paragraph on that page “For many projects this meant using tools like Webpack to package up all such dependencies into a single foreign library. While expedient, this approach leads to an unidiomatic style, and furthermore creates an obstacle should users try to migrate these dependencies to direct consumption from node_modules down the road.” https://clojurescript.org/news/2017-07-30-global-exports
@j1mr10rd4n if you just want to use npm
and not worry about all this use #shadow-cljs
that had occurred to me but that paragraph in the news article was tantalising
@j1mr10rd4n hehe right, I don't think that's entirely relevant anymore, given that the double bundle approach is documented in an official guide now: https://clojurescript.org/guides/webpack
(It really doesn't lead to an unidiomatic style for deps like React, so I wouldn't worry about that part.)
Double bundle or shadow-cljs are both good approaches for pragmatic cljs teams that use a ton of NPM dependencies (which at this point will be most non-trivial projects).
excellent advice, thanks for the pointers!