Fork me on GitHub
#shadow-cljs
<
2020-03-03
>
deep-symmetry00:03:05

Is there a shadow-cljs equivalent to lein ancient?

teodorlu09:03:22

If you're using Shadow-CLJS with deps.edn, you can use olical/depot. Here's my global deps.edn alias:

:outdated
       {:extra-deps {olical/depot {:mvn/version "1.8.4"}}
        :main-opts ["-m" "depot.outdated.main"]}

deep-symmetry17:03:30

Thanks! At this point I only have a shadow-cljs.edn, I am unclear as to what adding a deps.edn would do, wouldn’t that be two different places to specify the dependencies which could get out of sync?

teodorlu11:03:56

You can ask Shadow-CLJS to use deps.edn to speficy dependencies: https://shadow-cljs.github.io/docs/UsersGuide.html#deps-edn This functionality is in place just to avoid the duplication you're (rightly) reluctant to create. The advantage being that you can plug into the rest of the ecosystem for deps.edn / tools-deps 🙂

deep-symmetry16:03:09

That’s awesome! Thanks so much for pointing me in that direction.

👍 4
deep-symmetry16:03:03

Time to learn deps.edn

kaffein08:03:03

Hi friends! does anyone here have experience with code reloading in a Cordova + cljs + shadow-cljs stack please ? I am really interested if you could point me to a resource I can pick ideas from. Thanks in adv

achikin19:03:14

Did anyone manage to make shadow-cljs work with Cursive?

achikin19:03:55

I’ve managed to connect to remote shadow server, but Send to repl does not work properly

achikin19:03:06

(+ 1 1)
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: + in this context

lilactown19:03:17

I think thheller (the author) uses Cursive as his main editor

thheller19:03:39

yep, works fine for me

thheller19:03:05

@achikin I think you get that result if you (in-ns 'foo.bar) without having (require 'foo.bar) first, ie. switching before actually loading

thheller19:03:54

also I think thats a CLJ error ...

achikin19:03:04

Still the same after (in-ns)

achikin19:03:22

Looks like Cursive does not pick up the namespace properly

thheller19:03:58

maybe you are doing something wrong 😛

thheller19:03:01

what are you doing?

thheller19:03:10

and which mode are you expecting to be in?

achikin19:03:51

I’m running shadow-cljs watch app in a separate terminal and trying to connect to it with Cursive remote repl

thheller19:03:19

shadow-cljs doesn't create a port file you can use by default

thheller19:03:30

did you enable that manually?

achikin19:03:34

I have a script that copies that file from .shadow-cljs/nrepl.port to .nrepl-port

thheller19:03:54

so you are then connected to the shadow-cljs CLJ repl

thheller19:03:59

what do you do next?

achikin19:03:11

Ah, that’s a clj repl…

thheller19:03:38

yes, always

thheller19:03:49

you switch via (shadow.cljs.devtools.api/repl :app)

thheller19:03:56

DO NOT manually use the Cursive select box

achikin19:03:09

Which box?

thheller19:03:23

there is a clj/cljs select box in the REPL window

thheller19:03:29

DO NOT EVER USE THAT! 😛

achikin19:03:33

That’s what I did 🙂

thheller19:03:48

ok yeah thats your problem then

achikin19:03:56

Thank you!

thheller19:03:07

if you do the repl command above it should automatically switch to CLJS

achikin19:03:15

Is there any way to make Cursive run (shadow.cljs.devtools.api/repl :app) automatically?

thheller19:03:19

you can use :cljs/quit to switch back to CLJ

thheller19:03:33

no I don't think so

thheller19:03:57

bind it to a repl command and keyboard shortcut 😉

achikin19:03:53

Maybe provide some custom :in-ns that contains that command?

achikin19:03:51

I mean :init-ns

thheller19:03:12

no its mostly a nrepl session issue

thheller19:03:22

the client session needs to be initialized so it must be something the client sends

kaosko21:03:45

I'm sure this is more of a node/closure/javascript question, but how the heck do I import a path? (I'm trying to import parts of three.js into my cljs app). All I get is: Cannot import Closure files by path. Use either import goog:namespace or goog.require(namespace)

kaosko21:03:04

yeah, from cljs I have no problem importing npm modules or even files paths from the source-paths, but this is inside a js file that wants to import other js files

kaosko21:03:41

thanks, incidentally I'm on that page. the original js did

import { OceanShaders } from "../shaders/OceanShaders.js";
but that results in undefined. any other form results in "Cannot import Closure files by path..."

Aleed21:03:02

if you’re consuming js files via shadow-cls make sure the js files you’re importing are inside a registered cljs path (or inside you’re node_modules)

kaosko22:03:15

yeah they are, I can require them in cljs

thheller22:03:08

would help to have a complete example to look at. can't quite figure out what you are doing.

kaosko22:03:22

in cljs, I am doing:

(:require
 ["/jsm/misc/Ocean" :as ocean]
that Ocean.js tries to import OceanShaders.js with:
import { OceanShaders } from "../shaders/OceanShaders.js";
OceanShaders there passes compilation but comes up as undefined. Elsewhere, I rewrote a similar syntax to:
import * as three from 'three';
const {...} = three;
to make it work. If I try to rewrite similarly:
import * as OceanShadersLib from "../shaders/OceanShaders.js";
const {OceanShaders} = OceanShadersLib;
it'll fail with: Closure compilation failed with 1 errors jsm/misc/Ocean.js:64 Cannot import Closure files by path. Use either import goog:namespace or goog.require(namespace)

thheller22:03:47

sorry I need to see this in actual files otherwise my brain has issue putting things together 😛

kaosko22:03:19

I could make a barebones project demonstrating this but you probably don't want to see all of these files, there's a lot. but this issue comes from closure compiler and I'm not quite sure why it cares

thheller22:03:59

well .. first of all the closure-compiler does NOT understand how shadow-cljs processes npm deps

thheller22:03:11

so basically it doesn't see three

thheller22:03:24

so its absolutely easily possible for it to get confused

thheller22:03:38

especially if you mix import/export ESM style with commonjs require

thheller22:03:53

and/or files NOT having either of those

kaosko22:03:00

no, the three part is fine. it's importing from the the path that's the issue

thheller22:03:30

shadow-cljs isn't really meant to compile JS projects. it is very lacking in that regard. its possible for easy stuff but I haven't put much work into the full support

thheller22:03:18

if you setup a reproducible example I can take a look but otherwise there are too many unknowns for me that I cannot reconstruct from slack threads

kaosko22:03:53

yes, I understand. I'm not sure though whether it's the closure compiler that is the limitation of if you could even do something about it in shadow

kaosko22:03:38

or, if there's something I can do to easily make it into a pseudo(?) module

thheller22:03:51

maybe ... impossible for me to say.

kaosko22:03:08

or, if I can just require it in cljs and just kind of make it visible to the js. I don't know, really don't know enough about all these npm, esm modules or requires

thheller22:03:07

listen ... I do want to help you but I can't without knowing more about what you are doing

thheller22:03:05

I know a lot about npm, esm, modules, requires, etc but NOTHING about your actual code/setup so you might see the problem

kaosko22:03:14

yes, thanks for replying. I really just wanted to see if it's possible to work with an existing large js codebase and cljs. it's basically this: https://github.com/mrdoob/three.js/blob/dev/examples/webgl_shaders_ocean2.html

kaosko22:03:12

the latest version of three.js npm module includes all examples on the same level as the build folder

kaosko22:03:53

but it's really not packaged as an npm module

kaosko23:03:30

I was reading https://github.com/google/closure-compiler/wiki/JS-Modules and I guess the module resolution mode at least explains why referring to the npm module in js works. I don't know, perhaps passing the source-paths to the closure compiler with --js would work

thheller23:03:38

FWIW I compiled it just fine and have it running

kaosko23:03:31

what's the closure compiler version you are using?

thheller23:03:11

but :advanced doesn't work so I'd stop right there 😛

thheller23:03:40

I guess the thing I might have done differently is not using three from npm

thheller23:03:03

just used the file from the build dir, moved it to the examples folder and adjusted the path accordingly

thheller23:03:39

but yeah .. use webpack or something for large JS codebases. that is not the focus of shadow-cljs

kaosko23:03:34

ok, yeah I considered doing that, i.e. dropping the three.js as npm dependency but I had of course started from that end and things in general worked well with shadow and npm deps

kaosko23:03:58

but no, I'd rather drop or rewrite the js dependencies in cljs than integrate the rest with webpack

Aleed21:03:24

can we specificy specific node_modules to transpile in shadow-cljs config?

Aleed21:03:33

i can’t find mention of this in docs, so either it’s undocumented or I imagine @U05224H0W you’ve decided against it? Building a react-native-web app and stumbled upon a module that isn’t transpiled 😓

thheller22:03:35

clarify what you mean by transpile

thheller22:03:54

shadow-cljs performs no "transpile" from other JS dialects at all

Aleed22:03:28

i.e. i’m getting an invalid token error because package includes es6 module statements

thheller22:03:19

like what? I mean are you sure its es6 and not typescript or something?

Aleed22:03:03

export * from './SQLite';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Module._compile (internal/modules/cjs/loader.js:896:18)

Aleed23:03:04

the linked file is .js and only includes export statements so pretty sure it’s just that the node_module needs to be compiled?

Aleed23:03:21

i’m going to be running into this a lot since not all react-native packages transpile their code. wondering how to best handle it

thheller23:03:59

SyntaxError: Unexpected token 'export'
    at Module._compile (internal/modules/cjs/loader.js:896:18)

thheller23:03:08

that is an error from node?

thheller23:03:29

but yeah SQLite isn't transpilable .. it is C.

thheller23:03:54

(it'll not run in the browser)

thheller23:03:36

well if thats the actual sqlite and not just a namespace named that way of course 😛

Aleed23:03:18

ah yeah sorry, in this specific case it’s a node error - i’m trying to use expo-sqlite in an electron app

thheller23:03:33

shadow-cljs is not involved in loading the code then so there is nothing you can configure

thheller23:03:52

maybe you can configure electron to support ESM. in node thats behind a flag.

Aleed23:03:31

:desktop-main
  {:target :node-script
   :output-to "apps/desktop/dist/index.js"
   :main rf.app-desktop.main/start}

Aleed23:03:48

^ i’m using shadow for the main process too

Aleed23:03:00

as a node script

thheller23:03:40

yep and you are relying on require. so shadow-cljs processes no npm deps whatsoever

Aleed23:03:15

oh got it, that makes sense then

Aleed23:03:18

thanks for explaining

Pavel Klavík21:03:07

Hi, my build got recently broken on Windows 10 due to

Cannot run program "java" (in directory "M:\libs\myproject"):
  CreateProcess error=206, The file name or extension is too long
which basically means that leiningen computes too many classpaths. I was googling little bit around and one suggested solution is to add plugin
[lein-classpath-jar "0.1.0"]
Which solves that problem but creates a new problem while compiling shadow-cljs release build. I am doing this in lein by
["run" "-m" "orgpad.build/release"]
whose code is the following
(ns orgpad.build
  (:require [shadow.cljs.devtools.api :as shadow]))

(defn release []
  (let [version (System/getenv "HEROKU_SLUG_COMMIT")]
    (shadow/release :client {:config-merge [{:release-version version}]})))
But it fails with the error:
Warning: implicit hook found: lein-classpath-jar.plugin/hooks
Hooks are deprecated and will be removed in a future version.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.
[:client] Compiling ...
The required namespace "orgpad.client.core" is not available.
Compiling directly using shadow-cljs release client works fine. Any ideas what is wrong?

thheller22:03:34

@pavel.klavik looks like your sources just aren't on the classpath maybe?

Pavel Klavík22:03:00

if I remove that plugin, everything compiles fine, haven't done any changes to it recently

thheller22:03:38

I don't know that plugin so no clue

thheller22:03:38

maybe you are activating different profiles? no clue what you whole setup looks like

isak22:03:34

Are you sure lines 3+ are related to the first 2? Because I have the same thing, and get the first 2, but not the rest @pavel.klavik

Pavel Klavík23:03:17

not really, it is something which always displays when I start java app, not sure what they mean

Pavel Klavík23:03:05

is it possible to use different plugins for different lein rules? so I could fix it for now by having it only on lein run, but not on lein uberjar?