Fork me on GitHub
#shadow-cljs
<
2019-07-24
>
sogaiu08:07:54

@thheller is ^js a shadow-cljs specific feature?

thheller08:07:38

it works in plain CLJS in pretty much the same way

sogaiu08:07:03

@thheller i looked for annotation docs and found some, but didn't find anything specifically mentioning just ^js -- do you happen to know of any?

thheller08:07:22

the guide tells you to use "typed" annotations like ^js/Foo.Bar but I decided to skip those in shadow-cljs

thheller08:07:33

you can still use them they just won't be used for anything specific

sogaiu08:07:35

so, if i write ^js/something it will be treated the same as ^js?

sogaiu08:07:43

> By using the ^js tag metadata we are just telling the compiler that this is a native JS value and we are going to need externs for it. In shadow-cljs the /Foo.Bar type info is optional. You can still use it if you like but shadow-cljs won’t bother you if you don’t.

heyarne13:07:39

What is the recommended workflow for developing node scripts? I'm using emacs w/ CIDER and I find it a bit clunky… I have to start the cljs repl myself and it crashes a lot (when requiring something that doesn't exist for example); my experience in the browser was waaaay smoother

thheller13:07:12

can't comment on the cider parts since I don't use emacs

thheller13:07:26

for regular shadow-cljs I would just use shadow-cljs node-repl and go

thheller13:07:10

a regular :node-script build for the actual script then

heyarne14:07:24

Hm… it always shows the cljs-repl as pending if I do that, even though I can run code in the repl itself

heyarne14:07:32

That seems to be a CIDER issue, thanks!

Karol Wójcik17:07:09

What is correct way to import file ./src/infrastructure/config.js from another (to be specific) ./src/api/client/schemas/login.js file. From the login.js I tried to import the configuration via:

const config = require('../../../infrastructure/config.js')
But I'm receiving the undefined

thheller17:07:25

thats not CLJS code? need more context 😛

Karol Wójcik17:07:49

Well it's still CLJS code, because it's then required by the api/client/core.cljs via ["./schemas/login" :as login] Project configuration:

;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 [[mount "0.1.16"]
  [funcool/promesa "2.0.1"]]

 :builds {:api         {:target    :node-script
                        :output-to "target/api.js"
                        :ns-regexp "^api.*"
                        :main      api.server/main!
                        :devtools  {:after-load api.server/reload!}}
          :worker      {:target    :node-script
                        :output-to "target/worker.js"
                        :ns-regexp "^worker.*$"
                        :main      worker.setup/main!
                        :devtools  {:after-load worker.setup/reload!}}
          :worker-test {:target    :node-test
                        :output-to "target/worker-test.js"
                        :autotest true
                        :ns-regexp "^test.worker.*"}}}

Karol Wójcik17:07:45

Tree of the project

thheller17:07:35

and what is in config.js?

Karol Wójcik17:07:14

config.js

const providers = {
  someProvider: {
    scope: [{
      name: "shopping-lists"
    }]
  }
}

const allowedProviders = Object.keys(providers)

export const configuration = {
  ...providers,
  allowedProviders
}

thheller17:07:30

try sticking to one concept

thheller17:07:38

don't mix export with require

thheller17:07:46

either use only import/export or require/module.exports

Karol Wójcik17:07:50

@thheller I've just changed require to export import Here is how ./src/api/client/schemas/login.js looks like

import joi from '@hapi/joi'
import { configuration } from '../../../infrastructure/config.js'

console.log(configuration)
Error message: TypeError: Cannot read property 'configuration' of null

Karol Wójcik18:07:47

@thheller Is it even possible to import one .js file from another .js file and then import it in cljs file? Or should I use webpack to join all js files together?

thheller18:07:15

yes thats possible and should be working fine

thheller18:07:35

it is somewhat unreliable in a node environment

thheller18:07:47

I'm not sure how to make it more reliable

thheller18:07:06

given that you are targetting node however you could just import the .js files directly and not have shadow-cljs process them in any way

Karol Wójcik18:07:17

That's true. I will use nodejs.require then 🙂 Thanks for pointing me that 🙂

thheller18:07:26

it might be more reliable if you actually just use require and module.exports

thheller18:07:42

so exports.configuration = ... instead of the export const configuration

thheller18:07:13

closure does very strict rewriting of ES6 type code that doesn't play well with hot-reload style dev builds currently

Chase17:07:18

any of you folks happen to be (neo)vim & fireplace users? I'm trying to follow a tutorial that uses shadow-cljs and can no longer get my repl connected. I included cider/cider-nrepl and cider/piggieback as dependencies and get the following warnings when starting the repl: https://pastebin.com/LPrmeKmz

Chase17:07:09

Can I just ignore those? When trying to actually connect vim to the running repl I get this warning and further stacktrace:

[2019-07-24 12:37:11 - SEVERE] Unhandled REPL handler exception processing message {:id ae40bfe8-e180-4ad0-33de-ceb5d15054f3, :op classpath}
java.lang.IllegalArgumentException: No implementation of method: :send of protocol: #'nrepl.transport/Transport found for class: clojure.tools.nrepl.transport.FnTransport

thheller18:07:44

looks like you might be using an outdated nrepl version?

tianshu18:07:26

@karol.wojcik sorry for interrupting you, I see there's a crypt.cljs in your screenshot. I'm searching for a library for doing AES in cljs, any sugeestions?

Chase18:07:34

i'm using "0.21.1" which appears to be the latest. hmmm

thheller18:07:47

@chase-lambert no they changed the artifact id

Chase18:07:44

oh.my.god. Thank you! Wow. The folks over on the vim channel are going to kill me.

tianshu19:07:05

@thheller Looks like I need some features like InitVector that goog not support. I found a library called "crypto-js", but looks like there's something not correct in cljs.

tianshu19:07:34

https://github.com/brix/crypto-js this will not work, the error is Cannot read property 'charAt' of undefined

(ns foo.bar
  (:require ["crypto-js" :as CryptoJS]))

((.. CryptoJS -enc -Base64 -parse)
 "aGVsbG8n")
This is the JS version
var CryptoJS = require('crypto-js');

var result = CryptoJS.enc.Base64.parse('aGVsbG8n');
console.log(result);

tianshu19:07:29

@thheller Am I do the correct translating? If it is, I think there's something wrong with shadow-cljs.

tianshu19:07:05

also there's a html version, to ensure it can be run on browser environment.

<!DOCTYPE html>
<html>
  <head></head>
  <body>

    <script src="node_modules/crypto-js/crypto-js.js"></script>
    <script>
var result = CryptoJS.enc.Base64.parse('aGVsbG8n');
console.log(result);
    </script>
  </body>
</html>

tianshu19:07:52

I submit an issue for this.

Karol Wójcik19:07:00

@doglooksgood It's not problem with shadow. Try this:

(.. crypto/enc -Base64 (parse "hello"))

tianshu19:07:34

@karol.wojcik so what's going on here, very strange

tianshu19:07:42

I can even confirm CryptoJS.enc.Base64.parse and (.. CryptoJS -enc -Base64 -parse) are totally equal. tried in the console and repl.

tianshu19:07:29

But calling in console with JavaScript will work, calling in repl with ClojureScript will fail, they are in one environment.

Karol Wójcik19:07:26

Did you try my example?

tianshu19:07:10

sorry, haven't notice that. where is the example?

Karol Wójcik19:07:24

(.. crypto/enc -Base64 (parse "hello"))

tianshu19:07:16

ohh, it works

tianshu19:07:39

can you have a explain?

Karol Wójcik19:07:42

I'm not 100% sure, but as I understand the property access does not makes the js function invokable.

Chase19:07:49

hey @thheller, what's the latest with piggieback and shadow-cljs these days? Now that I can connect with clojure I'm having problems getting the cljs repl connected. I used to just put :Piggieback :app and it worked. Shadow-cljs says it's watching build :app I have the cider/piggieback dependency loaded in.

tianshu19:07:20

I think in this case, sometimes invokable. there're some functions works like CryptoJS.enc.Utf8.parse

tianshu20:07:36

https://lwhorton.github.io/2018/10/20/clojurescript-interop-with-javascript.html @karol.wojcik It's not invokable, it's missing the context for this. this post have a great explain.

elarouss20:07:07

Hi, i'm using shadow-cljs, the live reloading works great, except when i create a new namespace inside a package (folder) and require it somewhere, where it says : The required namespace X is not available, it was required by Y, so i need to kill the shadow-cljs server and restart it, is there a better way to do this? i've tried shadow/stop-worker and then shadow/watch again but no luck

neupsh20:07:11

I have the same problem as @ichigo as well. I have 2.8.40

tianshu20:07:58

@ichigo did you eval the namespace before save the new created file?

neupsh20:07:30

@doglooksgood nice catch. I think that is the issue. I have been used to intellij automatically saving files and sometimes don't save manually. I just tried saving the file manually before using it and it worked. I will keep an eye on it to see if not saving was the cause. @ichigo let us know if that fixed it for you or not

elarouss20:07:03

thanks @doglooksgood, @neupsh i'll try that :thumbsup:

tianshu20:07:26

I'm using Emacs, get an different error. But evaluating the namespace before you save that file(let shadow-cljs compile it) will cause problem.

🙏 4
elarouss20:07:51

so i've tried 2 things: 1. create a package with a namespace, define a function inside it, require it in another namespace, this didn't work, even after evaluating the namespace after. 2. same as before, but after creating the function i evaluated the namespace and then require it, this works 🎉

isak20:07:04

How are people handling watching other assets like CSS during development? Do you just start multiple processes, or is it possible to add this to the normal shadow-cljs commands with the hooks? (E.g., start webpack as the build is configured)

lilactown21:07:57

I use css-in-js on my current app but I think the other option is to run node-sass or whatever as a separate process

neupsh21:07:51

There was a way to specify shadow-cljs to build only one js file instead of injecting a lot of <script> tags for node_modules in the html during development. Anyone remember how to do that?

thheller21:07:17

@neupsh :devtools {:loader-mode :eval} in the build config

isak21:07:55

@lilactown hm, how are you making css-in-js work with shadow?

lilactown21:07:16

by css-in-js I mean something like emotion

isak21:07:59

ah ok, interesting