Fork me on GitHub
#shadow-cljs
<
2017-11-24
>
Hendrik Poernama12:11:59

I just tested shadow-cljs in my project and everything just works.. How can this be?? I haven't even included my 2500 lines extern files. This has got to be black magic.

Hendrik Poernama12:11:41

it even knows I'm pulling a var from script tag???

vN.j ? vN.j(ax, e5) : vN.call(null, ax, e5);
function f5() {
    return "undefined" !== typeof $zopim ? $zopim.livechat.window.show() : null

thheller12:11:49

I did a “few” tweaks to the compiler to make this easier

Hendrik Poernama12:11:11

wow... why doesn't everybody just use this. I think I spent close to a week debugging mangled node libraries that I fed to closure

thheller12:11:24

I don’t know 😉

Hendrik Poernama12:11:06

thank you for shadow-cljs, this is amazing. I will help with documentation as I go along.

thheller12:11:20

its early still … still much left to do. I really need to write more docs but I prefer writing code.

nha13:11:11

wow that looks really useful! I’ll give shadow-cljs a spin when I get a chance 😄 can it run in separate “.edn” files like boot-cljs (https://github.com/boot-clj/boot-cljs/blob/master/docs/cljs.edn.md)?

thheller14:11:14

not currently no

thheller14:11:14

could add something like shadow-cljs.<build-id>.edn if that seems useful. I kinda like having my config in one place but it tends to get pretty large in bigger projects.

nha14:11:55

oh that’s because my build currently produces several js files

thheller14:11:38

multiple builds or one build with :modules?

nha14:11:51

multiple builds. I have yet to play with modules

nha14:11:31

although two of these builds share a few common functions, they are mostly independent.

nha14:11:34

oh cool 😄

nha14:11:48

looks good 😛

mitchelkuijpers14:11:07

How do people here handle cljs.spec integration with regards to the instrument call? My first guess would be to call it after each reload?

sundbp15:11:41

I’m looking to use the “consul” npm module from cljs in a shadow-cljs project. I’m doing: (:require ["consul" :as consul]) in cljs, and the consul.js looks like:

sundbp15:11:02

function Consul(opts) {
  if (!(this instanceof Consul)) {
    return new Consul(opts);
  }
.....
};

/**
 * Module exports.
 */

exports.Consul = Consul;

sundbp15:11:21

the js docs looks like:

sundbp15:11:33

Usage

var consul = require('consul')();

sundbp15:11:43

and then call fns like:

sundbp15:11:52

consul.acl.bootstrap(function(err, result) {
  if (err) throw err;
});

sundbp15:11:20

I’m struggling to work out how I translate to cljs side - any insight?

sundbp15:11:00

I find a blog entry (https://blog.thheller.com/blog/shadow-cljs/2017/11/10/js-dependencies-in-practice.html) that states: Some packages just export a single function which you can call directly by using (:require ["thing" :as thing]) and then (thing).

sundbp15:11:28

not having luck with that.

mitchelkuijpers16:11:57

That is because they export a class

mitchelkuijpers16:11:08

probably consul/Consul will work

sundbp16:11:48

eval error <eval>:-6
shadow.js.shim.module$consul.Consul()
                             ^

TypeError: Cannot read property 'Consul' of undefined
    at <eval>
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at runInThisContext (vm.js:152:38)
    at global.SHADOW_NODE_EVAL (/Users/sundbp/dev/bi/permafrost/out/permafrost.js:113:30)
    at Object.shadow$cljs$devtools$client$node$node_eval [as node_eval] (/Users/sundbp/dev/bi/permafrost/target/shadow-cljs/builds/pf/dev/out/cljs-runtime/shadow/cljs/devtools/client/node.cljs:28:1)

sundbp16:11:22

i tried that one..

mitchelkuijpers16:11:24

and consul/default?

sundbp16:11:43

eval error <eval>:-6
shadow.js.shim.module$consul["default"]()
                            ^

TypeError: Cannot read property 'default' of undefined

sundbp16:11:43

if i change “consul” to “consul123" it fails, so it’s doing “something” with the require..

sundbp16:11:45

[:pf] Compiling ...
[:pf] Build failure:
The required JS dependency "consul123" is not available, it was required by "permafrost/cli.cljs".

mitchelkuijpers16:11:52

can you print what is in the consul object?

sundbp16:11:20

permafrost.cli> consul
"nil"

sundbp16:11:34

i don’t seem to really get anything in that require..

sundbp16:11:45

or i don’t know how to see anything at least

mitchelkuijpers16:11:46

Can you require consul/consul?

mitchelkuijpers16:11:57

consul.consul i mean

sundbp16:11:20

[:pf] Compiling ...
[:pf] Build failure:
The required JS dependency "consul.consul" is not available, it was required by "permafrost/cli.cljs".

mitchelkuijpers16:11:13

What is your target? :node ?

sundbp16:11:36

node-library in shadow-cljs.edn

mitchelkuijpers16:11:01

I am sorry I have no idea what is going wrong 😞

sundbp16:11:20

likewise..

mitchelkuijpers16:11:25

I have never tried node stuff with shadow-cljs

sundbp16:11:50

in package.json of consul package it says main = ./lib, and then in lib/consul.js is the code i pasted.

sundbp16:11:57

so it sort of looks reasonable to me

sundbp16:11:44

» less target/shadow-cljs/builds/pf/dev/out/cljs-runtime/shadow.js.shim.module\$consul.js                              
goog.provide("shadow.js.shim.module$consul");
shadow.js.shim.module$consul = require("consul");

sundbp16:11:10

@thheller I’ve got a feeling we’re hitting some kind of bug here in the require system. it all looks ok, but I don’t think that the require to that shim has happened at the right time or something like that. looks like it’s nil

Jon16:11:20

Use of undeclared Var shadow.test.env/register-test

Jon16:11:24

what's this

sundbp16:11:05

@mitchelkuijpers i got it to work in a release build!

sundbp16:11:21

so it may be related to REPL stuff

sundbp16:11:56

in release i can do the require, and then do (prn (js-keys (consul))) and see the fns in the js docs

sundbp16:11:26

@thheller let me know when you’re around and I can describe things and perhaps we can diagnose what goes wrong in REPL case.

sundbp17:11:07

now next problem is to call a nested fn. i.e. I can do (let [c (consul (clj->js {...})] ...), but then i need to access .kv.get in that c object.

sundbp17:11:51

if i fetch out the fn via e.g. aget and call it I get a failure as it expects this to be set to c during the call..

sundbp17:11:56

actually - got it all to work now. started again, cleaned dirs etc and got it working.

thheller18:11:32

@sundbp I’m back. reading log.

thheller18:11:05

nested fns you call with (-> consul (.-kv) (.get arg1 arg2 ...))

thheller18:11:30

@jiyinyiyong where did you get this error? ah hmm … crap you are probably requiring cljs.test and do deftest somewhere in your build

thheller18:11:16

shadow.test.env is included automatically for the new test builds but not for everything else. need to fix that

thheller19:11:43

@sundbp (:require ["consul" :as consul]) should have just worked. no idea why it wouldn’t.