Fork me on GitHub
#shadow-cljs
<
2019-01-06
>
hueyp02:01:59

is there a way to kind of force shadow-cljs to not include a namespace? e.g. we get cljs.pprint in our bundle due to some bad DCE and would like to force it to be gone ๐Ÿ˜œ thinking maybe a hook could do this?

thheller12:01:09

that is currently not possible with hooks. the closure compiler supports stripping by namespace so it could remove everything starting with cljs.pprint. the option for that however is not exposed since its kind of a footgun and easy to destroy your entire build using it

thheller13:01:56

so I just released 2.7.11 which exposes those options. I'll just document with a warning but basically you can now add :compiler-options {:strip-type-prefixes #{"cljs.pprint"}}

thheller13:01:24

that will remove everything cljs.pprint related, which also includes every USE of cljs.pprint so beware ๐Ÿ˜‰

thheller13:01:30

this only applies to :release builds though

hueyp18:01:58

this is amazing

hueyp18:01:02

thanks ๐Ÿ™‚

henrik07:01:23

I have a Node and browser build, with some shared code between the two. Remind meโ€”is it recommended to split these into two separate projects, or can I stick them in the same one?

lilactown07:01:27

stick em in the same!

๐Ÿ‘ 5
henrik07:01:00

Follow up question: when selecting a build with shadow.cljs.devtools.api/nrepl-select, how can I switch over to another build? Can I require shadow-cljs from within the build?

lilactown07:01:12

and then select another build

henrik07:01:05

Excellent, thank you

henrik07:01:21

If only this could be done automatically depending on namespace.

henrik11:01:13

OK, so I'm trying to do something really wonky to see if it works: running separate scripts in dev mode in the same browser tab at the same time. Doesn't work, even a little bit. Namespaces (cljs., goog., etc.), in assuming they're alone in the global scope, clash of course. Any ideas of how to make it work? Basically, I have two scripts, where either one, or both, might be in dev mode at the same time. One script calls stuff in the other one.

orestis12:01:50

I think this is a limitation of ClojureScript in general. Canโ€™t do it.

thheller12:01:51

@henrik in general it is not advised to run 2 separate CLJS builds in the same app at all ever. dev or release. both will include their own version of cljs.core and won't be compatible with each other

henrik12:01:30

Alright. So this essentially means that I couldn't have a CLJS-generated script sitting on a CDN somewhere, to be pulled into a site as a JS script, compiled and ready for consumption, if that site itself happens to use CLJS.

thheller12:01:28

well that is ok. I was assuming you were running both builds

henrik12:01:29

Ah, OK! So the limitation is not "dev or release", only "dev"?

thheller12:01:52

yes, in that case 2 dev builds can't run in the same browser

thheller12:01:00

2 release builds is fine

thheller12:01:04

or 1 release 1 dev

henrik12:01:39

I admit, it probably doesn't happen much. A thing built in CLJS, targeted at a JS audience, but not available as CLJS library.

conan14:01:29

Hi, just trying out shadowcljs for the first time. I'm making progress getting through all the compilation errors, but I keep getting this warning:

------ WARNING #1 --------------------------------------------------------------
 File: shadow/module/main/append.js:2

 variable shadow$umd$export is undeclared
--------------------------------------------------------------------------------
any clues as to what might be wrong would be super helpful, thanks

conan14:01:17

More info: I'm compiling for node and running on AWS lambda. This is the execution error I get:

{
  "errorMessage": "Cannot find module 'bluebird'",
  "errorType": "Error",
  "stackTrace": [
    "require (internal/module.js:11:18)",
    "/var/task/main.js:494:240",
    "shadow$umd$export (/var/task/main.js:5:22)",
    "Object.<anonymous> (/var/task/main.js:9:3)",
    "Module._compile (module.js:652:30)",
    "Object.Module._extensions..js (module.js:663:10)",
    "Module.load (module.js:565:32)"
  ]
}
I can see the shadow$umd$export mentioned in there, so I suspect it's related

thheller14:01:27

"errorMessage": "Cannot find module 'bluebird'"

thheller14:01:31

thats the actual error I guess

thheller14:01:36

try npm install bluebird

conan14:01:21

ah thanks, i'm learning about npm as i go. i take it those deps aren't pulled in by leiningen?

thheller14:01:41

no npm stuff is not covered by leiningen

conan14:01:42

ok cool. can you recommend somewhere i can read about how to use the npm dependencies once i've done npm install bluebird (i've done yarn add bluebird, which i'm hoping does the same thing)?

thheller14:01:04

yes thats the same

conan14:01:51

so in my case i'm trying to work out how to get these npm deps into AWS lambda, they don't seem to go into the target folder which is what i'm sending to AWS

thheller14:01:12

yeah I think you need to include the node_modules folder in your upload

thheller14:01:29

I don't know much about AWS

conan14:01:05

ah ok, thanks

conan14:01:28

your help is much appreciated, and i'm writing a blog post about how to do this so hopefully it'll go a little further yet!

thheller14:01:08

someone wrote an article not too long ago

thheller14:01:50

maybe that helps?

conan14:01:05

yeah that's what i've been following but it doesn't seem to cover npm deps

conan14:01:45

just out of interest, when developing with shadow-cljs, how do you know which npm deps you need to install?

thheller14:01:08

well typically they are installed automatically

conan14:01:24

for example, you add a clojurescript library, and when it runs it'll throw errors for all the missing npm libraries until you install them, right?

thheller14:01:29

but you are most likely affected by the cljsjs compatibility stuff

conan14:01:39

so i'm going through one by one, but it feels like i'm missing something simple

thheller14:01:49

those can't install the deps automatically since the cljsjs deps don't declare their npm dependencies

conan14:01:11

what's the workflow you would usually use for this?

thheller14:01:17

it is unfortunate that most cljs libs don't declare their npm dependencies properly

thheller14:01:41

there typically is not workflow involved

conan14:01:50

oh so it's a problem that can be resolved only in the libraries themselves

conan14:01:55

ok thanks!

thheller14:01:01

when using anything react related you probably just do yarn add react react-dom create-react-class

thheller14:01:26

bluebird is most likely coming from promesa

conan14:01:38

good to know, i'm sure at some point i'll try out react yeah bluebird > promesa > kvlt

thheller14:01:47

so yeah its just libraries that don't declare npm deps properly since they typically just use cljsjs instead

conan14:01:51

i'm trying to make an http request but it seems super difficult

conan14:01:08

oh, does cljsjs not work with shadowcljs?

thheller14:01:10

just use (js/fetch "something")

conan14:01:20

wow ok, that'll take some learning, thanks!

conan14:01:29

on that js/fetch, what is that? is there some js interop i can use to make http requests without having to use a cljs one?

conan14:01:37

i've always used cljs-http in the past

thheller14:01:53

ah right you are on node

conan14:01:54

but that doesn't work in node

thheller14:01:58

sorry js/fetch is for the browser

thheller14:01:04

cljs-http should be working for node?

conan14:01:06

no, it doesn't because there's no XmlHttpRequest in node, which cljs-http requires. i've also looked at kvlt, but that has the similar problem of needing other stuff, which is why i'm learning about npm

thheller14:01:22

otherwise the npm request lib is pretty popular I think

conan15:01:15

cool, maybe straight interop will be easier, although it seems to require npm as well which is the main problem

conan15:01:19

thanks again

thheller15:01:46

node http package is built-in and should work just fine

conan15:01:54

yeah it looks as though that's always available, but i'd have to write a bunch of code to handle chunked responses. i'm guessing that solving the npm problem will be easier, and it has obvious other benefits for the future

conan15:01:26

incidentally i always get the variable shadow$umd$export is undeclared warning on compilation. is that something to worry about?

thheller15:01:46

uhm are you publishing shadow-cljs compile or shadow-cljs release?

thheller15:01:04

should only use shadow-cljs release when copying something to AWS

thheller15:01:10

compile/watch are only meant to run locally

conan15:01:00

i'm running yarn shadow-cljs release app

conan15:01:55

)$ yarn shadow-cljs release app; cd target; rm arch
ive.zip; zip -r archive.zip *; cd ..
yarn run v1.12.3
$ /mnt/c/Users/conan/dev/minimal-shadow-cljs-nodejs/node_modules/.bin/shadow-cljs release app
shadow-cljs - config: /mnt/c/Users/conan/dev/minimal-shadow-cljs-nodejs/shadow-cljs.edn  cli version: 2.7.9  node: v8.15.0
shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm release app
[:app] Compiling ...
------ WARNING #1 --------------------------------------------------------------
 File: shadow/module/main/append.js:2

 variable shadow$umd$export is undeclared
--------------------------------------------------------------------------------

nil
[:app] Build completed. (130 files, 1 compiled, 0 warnings, 16.52s)
Done in 37.80s.

conan15:01:25

shadow-cljs.edn:

{:lein true
 :builds {:app {:target :node-library
                :exports {:handler server.main/handler}
                :output-dir "target"
                :output-to "target/main.js"}}}

thheller15:01:28

oh. yeah ignore that. I'll fix that so it doesn't show up

conan15:01:34

cool, thanks

thheller15:01:36

thought you had some runtime error with that

conan15:01:43

no, just a warning on compilation

conan15:01:53

just to wrap up, i went through all the npm errors one by one installing each dep and now it's working! in the end i used kvlt. thanks for your help!

๐Ÿ‘ 5
ribelo22:01:29

How does the situation with react-native look like? Still possible? Deprecated?

thheller22:01:02

@huxley has always been possible. just not as smooth as it could be since I don't do any react-native development myself and haven't worked on support for a while

thheller22:01:12

:npm-module builds just work however

ribelo22:01:24

Can I do something to make REPL work?

thheller23:01:04

@huxley you need to require("shadow-cljs/shadow.cljs.devtools.client.react_native") from JS and set :runtime :react-native in your build config

thheller23:01:29

or require("./path-to-output-dir/shadow.cljs.devtools.client.react_native")

thheller23:01:33

depends on which path you use