Fork me on GitHub
#shadow-cljs
<
2018-08-23
>
chrisetheridge08:08:42

is it possible to call (shadow/nrepl-select :app) from a different nrepl that’s running from the same app? or do you have to use the shadow nrepl to call that? can the shadow nrepl replace clojure.tools.nrepl ?

thheller08:08:43

do you mean a different nrepl server?

chrisetheridge08:08:46

okay, and then do i still call nrepl-select ?

hlolli08:08:26

did shadow-cljs offer any way of bundling a jar? Recommend using leiningen for that?

thheller08:08:51

not yet, leiningen recommended yes.

chrisetheridge08:08:17

you’d need a deps.edn file though

chrisetheridge08:08:21

i haven’t used it in prod yet though 🙂

hlolli08:08:58

I love riding on rough paths, live on the edge 😛

hlolli08:08:07

btw, a proof that audioworklet and wasm can be compiled with shadow-cljs https://jsfiddle.net/4o3q5tu7/1/ (just showoff)

parrot 4
chrisetheridge08:08:58

this is very cool

🙂 4
urbanslug16:08:42

is there a way to specify dependecies for dev and for prod with shadow-cljs?

thheller16:08:33

@urbanslug no that is not supported currently. you can do it via :lein or :deps if you need to

hlolli17:08:20

Is it possible, or has it been thought trough and considered not worth it. To publish jar with cljs resources and bundle with it the shadow-cljs.edn file, which when consumed by other shadow-cljs app. Will inherit the npm dependencies, :resolve and :hooks (or make it configureable which to inherit and what not)?

hlolli17:08:05

This seems to part of another endless discussion of npm deps in cljs. But yeh, totally annoying. tools.deps supporting :npm-deps would be nice. It almost doesn't happen anymore that someone makes a library in clojurescript.

richiardiandrea18:08:03

@hlolli I had a look at pack as well for the same reason and I am thinking of adding an Azure pack target for my use case: https://github.com/juxt/pack.alpha/issues/18

richiardiandrea18:08:20

but it would definetly convenient to have everything in one tool...

hlolli18:08:08

@richiardiandrea yes looks like this is very special usecase. Maybe it's not such a big problem of packageing the stuff we need, generate .pom etc. But what the build tools do with it. I'd like more radical integration with javascript. As for the hooks, js already has install, preinstall and postinstall. We have 4 tools to build clj/s (lein/boot/shadow-cljs/clj), and none can do it. If you ask me, the minification that webpack does is pretty radical and has gotten way better. Clojurescript isn't an island, but almost.

hlolli18:08:20

Don't know why I added the webpack comment there 🙂 but it's easy not to use any optimization, at least in shadow-cljs, which I love.

hlolli18:08:10

Anyway, to end my rant, which only in a good tone and with great love of cljs. Then imagine, publishing a cljs library running on nodejs "by the book". Then the recommended way is bundling all the dependencies in a consumeable form, makeing a jar, stuffing in the js, and declare foreign libs. With that, generate extern. Now imagine 100 modules in the node_modules for like 5 npm deps. Wiriting extern for each and one of them. Then ok, if successful, upload them to cljsjs, create PR and wait, so that at the end of it you can tell your friend, "hey check out my new library with this oneliner". End of rant 🙂

thheller18:08:06

@hlolli it has been considered but ruled "not desirable". a library should never be specific to one tool, its one of the worst aspects of some npm deps and not something I want to introduce to CLJS. its already kind of bad that CLJS can't easily consume most npm deps like shadow-cljs but I do hope that they'll catch up eventually.

thheller18:08:24

custom :resolve hooks are really a last resort option and should be used very rarely

thheller18:08:59

:npm-deps you can declare in deps.cljs which shadow-cljs supports and will install on startup. CLJS will to when configured to do so.

thheller18:08:58

js install/postinstall/preinstall hooks are the worst idea ever IMHO

thheller18:08:02

there is also the fundamental difference in how cljs and closure view the world vs webpack. closure wants to optimize your whole program, webpack optimizes file by file and only recently gained some cross-file stuff

thheller18:08:41

so publishing CLJS libs to npm for use by JS is probably never going to be easy

thheller18:08:15

webpack minification is laughable compared to what closure does. it is getting better but is nowhere near closure :advanced

thheller19:08:42

I can start ranting about all the bad things in npm for hours but I'd rather not 😉

lol 8
thheller19:08:46

happy to look over whichever problem you are running into though

thheller19:08:15

you seem to have deleted another related message. at least I got an email notification but can't find the message here 😉

hlolli19:08:41

hehe yup, I deleted it, it was about being stuck between :es5 and :es6 when I using cljsbuild. If I uesed :es5 then I got errors about const and whole lots of features not being supported. When I used :es6, I started to get require calls adding .default and some of the node modules. Basically I'm working on packaging cljs app so that, hopefully, everyone can consume it on any build tool. But :npm-deps in deps.cljs, I had no idea that was possible. That may actually be exactly what I need. Thanks for pointing that out!

thheller19:08:05

yeah the .default issue is a bit annoying. its the closure compiler doing that and unfortunately breaks many npm packages. and its a wontfix 😞 https://github.com/google/closure-compiler/issues/2971

hlolli19:08:50

Chad Killingsworth seem to have encountered this himself and made some changes. Maybe I try them out.

onetom13:08:26

It's funny you are mentioning this because when vscode was open sourced, the very first thing i did is i tried to compile it, then i tried to see how can i hook in to the rendering and the file buffer, to see if i can implement elastic tabstops. But then I got lost in the forrest of typescript classes and gave up on it...

👏 1
hlolli19:08:25

the problem was with .default, is that it was a module that I wasn't event require-ing directly, but a nested require

thheller19:08:35

the change should be available in the closure compiler version used by shadow-cljs

thheller19:08:46

but it doesn't matter. it only fixed an unrelated issue

hlolli19:08:50

it was in lein, but yup, I am leaving it behind for now and concentrating on tools.dep.

thheller19:08:24

tools.deps isn't any different than lein when it comes to what CLJS does

thheller19:08:49

but whats the actual problem you are trying to solve?

hlolli19:08:08

ah sorry, the actual problem was running tests.

hlolli19:08:50

But I guess that they need to run in lein too... so I won't leave it behind. My brain is bit drained.

hlolli19:08:24

if this is a nofix, then I just publish this stuff I have and write big red letters, use shadow-cljs. This is happening in the module "safe-buffer", which some module I'm requireing, is requireing, is requireing a built-in module "buffer"

var buffer = require('buffer')
this becomes
module$buffer.default
and I get ReferenceError: module$buffer is not defined

thheller19:08:18

closure probably didn't understand the buffer package

thheller19:08:18

but yeah .. actually using :npm-deps in CLJS is rather unreliable still

thheller19:08:36

buffer is also usually a built-in node package so it requires the node-libs-browser shims that webpack also uses

thheller19:08:56

dunno if you have those installed

hlolli19:08:33

I'm in this case only targeting node, I have seperate namespace for the browser, which I don't think this package will get required

hlolli19:08:53

I would assume that, built-in modules would just get hard-coded into the closure compiler.

thheller19:08:10

hmm if you are only building for node that closure shouldn't rewrite any code at all?

thheller19:08:18

are you maybe not setting :target :nodejs or so?

thheller19:08:48

and no closure has no predefined handling for built-in node packages at all

hlolli19:08:13

yes ahh, but I have :simple I "meant" that for .cljs sources

thheller19:08:31

it doesn't matter

hlolli19:08:08

this is what I'm working with now

thheller19:08:18

in shadow-cljs when compiling for node the (:require ["whatever" :as x]) just generates a require("whatever") call

thheller19:08:36

the code rewriting stuff only applies for browser builds since they can't use require

thheller19:08:47

node builds for CLJS also emit require

thheller19:08:13

so it should never get to the situation where require("buffer") is turned into module$buffer at all

thheller19:08:49

I honestly have no idea about that config, may need to ask someone else

hlolli19:08:54

ok, yes, I wish closure would not change anything inside node_modules

thheller19:08:09

it shouldn't when building for node

thheller19:08:25

but I think :npm-deps confuses it

thheller19:08:35

try setting :npm-deps false and see if that works

hlolli20:08:22

ah ok I get it! now what's happening it that I just add the npm modules to foreign-libs, which is good, because I can set :module-type for each and every dependency.

thheller20:08:26

you don't add npm modules to :foreign-libs ever. they won't work.

hlolli20:08:32

for example, when compiling, I get

Caused by: clojure.lang.ExceptionInfo: No such namespace: web-audio-api, could not locate web_audio_api.cljs, web_audio_api.cljc, or JavaScript source providing "web-audio-api"

thheller20:08:03

does node_modules/web-audio-api exist?

hlolli20:08:16

yes and if I add

{:file        "node_modules/web-audio-api/index.js"
:provides    ["web-audio-api"]
:module-type :commonjs}
it will go away

thheller20:08:52

but your code won't run at all

thheller20:08:02

thats not what foreign-libs are for

thheller20:08:44

you want the CLJS compiler to emit require("web-audio-api"). that is all. nothing else.

thheller20:08:57

I don't know what setting you need to set to get it to do that

thheller20:08:18

ask someone that does before continuing. you are on the completely wrong path when trying to use :foreign-libs to solve this.

hlolli20:08:44

ok just commented :npm-deps false then it compiles, just again ReferenceError: module$buffer is not defined

thheller20:08:47

they are not suitable for this at all. :foreign-libs are prepended to the compiled code as-is!

hlolli20:08:22

hehe I maybe ask at another channel. And want to add that this is no "problem" for me, it's only an extra cool point that more people could use my code. Most likely, 1-2 peeps max will 🙂

thheller20:08:20

I honestly can't figure out how to make it emit require

thheller20:08:27

I know that it can do so but no idea how

hlolli20:08:57

before asking, I'll try this with vanilla closure in js...

hlolli20:08:02

just for sanity

thheller20:08:32

closure got nothing to do with this

thheller20:08:45

thats the point. closure should not be involved at all.

thheller20:08:50

the CLJS compiler should emit require and let node figure it out

hlolli20:08:35

you don't think it could be connected with :language-in :es6 ?

raf20:08:48

Hello, I've just started using shadow-cljs for my ClojureScript development. My configuration file looks so:

{ :source-paths ["src/clj" "src/cljc" "src/cljs"]
 :dependencies [[reagent "0.8.1"]]
 :builds {:app {:target :browser
                :output-dir "resources/public/js"
                :asset-path "/js"
                :modules {:main {:entries [my-ns.main]}}}}}
In one of the file I'm requiring reagent like so:
(ns my-ns.main
  (:require [reagent.core :as r]))
when I try to build this I got such message: The required namespace "reagent.core" is not available, it was required by Should I invoke some command to install it? Or maybe I should install it by lein project? Thanks in advance!

thheller20:08:22

@raf use three quotes for multi line code. your config looks fine and should work. are you sure you started shadow-cljs after adding the dependency?

thheller20:08:33

if you have an old instance running that won't have the dep and won't find it

raf20:08:49

@thheller I use such command in the shell:

lein run -m shadow.cljs.devtools.cli compile app

thheller20:08:11

well if you use lein to run the command you need to add the dependency to project.clj

thheller20:08:35

or run shadow-cljs compile app

raf20:08:03

ah, clear. Somehow I thought lein is just throttling it to the shadow-cljs cli

raf20:08:24

then I've install npm package with shadow-cljs

thheller20:08:39

:source-paths and :dependencies in shadow-cljs.edn don't matter if you use lein

thheller20:08:50

as lein will only use project.clj

raf20:08:51

@thheller clear - I thought that only puting :lein option in the shadow-cljs.edn makes that lein deps are used

thheller20:08:30

generally yes but only if you actually use the shadow-cljs command itself and not lein

raf20:08:34

now everything is clear. Thank you very much for help! I appreciate this! You've saved me a lot of time 🙂

raf20:08:55

@thheller now when I think about this, this ofc makes sens

raf20:08:57

@thheller thank you. Have a good night

raf20:08:10

@thheller just wanted to let you know, that now everything works, I was able to compile and run code

👍 4
hlolli20:08:04

I think the problem is @cljs-oss/module-deps": "^1.1.1"

thheller20:08:29

you are still doing it wrong it that is used at all

thheller20:08:19

but yeah maybe just having it installed messes with things

hlolli20:08:18

I get Error: Cannot find module '@cljs-oss/module-deps' don't know who's asking for this then Error: Could not locate the bindings file. Tried:... for node-speaker

thheller20:08:11

not a clue whats happening. I'm off to bed. gn8

hlolli20:08:55

ok, gn8, thanks again for all your help!

kwladyka21:08:22

What is the best way to develop “lein” library and include it to shadow-cljs as dependency? My goal is to develop module and during this development test it in separated project as lein and shadow dependency.

kwladyka21:08:38

I was even thinking about use the same project with project.clj and shadow-cljs.edn and run the same code using both to test it

kwladyka21:08:38

So all in all I created module to help validate form with specs and fns. I want it to be dependency for lein and shadow-cljs example project (which will be the same project). This example project will have forms in web browser to let developers easy have the demo.

kwladyka21:08:42

But the main issue is during developing I want to use version from my local hard drive, but when build project I want to use version from github.