Fork me on GitHub
#shadow-cljs
<
2018-07-24
>
lwhorton01:07:59

does shadow support .zip files on the classpath? i’m trying to generative-test some really crappy node code from another cljs app. that node code is ultimately bundled into a zip file, and i’m just curious if i have to unzip the file before attempting to run shadow (or if my error is elsewhere)

richiardiandrea02:07:32

I was wondering if there is an easy way to have :optimizations :none compilation mode but all in one unique file, concatenated. I have a requirement to leave things readable from a JS dev standpoint but I feel checking in :cache-root is not a clean approach.

thheller05:07:52

@richiardiandrea define "readable". its not like the compiled CLJS code is easily understandable so what do you gain by "readable"?

richiardiandrea14:07:53

I know, I think I need to make clear that is never going to be like reason or typescript compiled code...probably the goal is to debug things in the debugger and that's why the requirement is "readable" and one-file

thheller14:07:28

but you have source maps for that? wouldn't you want to know the actual code being used?

richiardiandrea14:07:25

I know well...I am trying to understand if it is possible to have an alternative, if not I will just say here that we are going to live with source maps only ;)

thheller14:07:42

you can just do a :simple build with :compiler-options {:variable-renaming :off :property-renaming :off :pretty-print true} that should be as close to readable as possible

thheller14:07:55

but I really don't know what you'd gain from having that

richiardiandrea14:07:58

I don't know either, I will try to explain that too but thanks for having an answer ready for me ;)

thheller05:07:21

the "cache" is also not useful for humans to consume as its transit encoded data

thheller05:07:22

@lwhorton .jar files are basically zip files and yes those are supported but you said "node code" so I'm assuming .js files? what kind of code are you talking about? https://shadow-cljs.github.io/docs/UsersGuide.html#_the_classpath

lwhorton18:07:06

it’s a typescript codebase, but i’m transforming the ts -> js and then adding build/the-js-files/ as a src path. after some playing around I found a way to get everything up and running. the only wonky piece was the npm integration. if i have a parent dir /proj which contains /proj/the-node-code, compiling the node code and adding it to the proj/shadow-cljs.edn’s source files config works. however, it looks like the node_modules resolving can’t find the node code’s libraries unless I add them explicitly to /proj/node_modules. i’ve tried adding the proj/the-node-code/node_modules also to the source files, but the compiler still cant manage to resolve some import foo from 'some-lib' dependency in the node code.

thheller18:07:37

I can't really make out what you are saying. you either have classpath js or node_modules. they are handled entirely differently. if you have say src/js/some-folder/converted-from-ts.js and put src/js on the :source-paths you can require it via (:require ["/some-folder/converted-from-ts" :as x])

thheller18:07:00

the converted file itself can import foo from 'some-lib' as usual assuming that some-lib is in node_modules?

thheller18:07:46

basically all "paths" (ie. "/foo/bar" or "./foo" or "../foo") are assumed to be on the classpath

thheller18:07:58

otherwise node_modules is checked

thheller18:07:45

what is "can’t find the node code’s libraries"?

lwhorton18:07:34

ill see if i can be more clear: compile the node code into some /build folder. add that build folder to a parent project’s source files. from a test_runner.cljs file (in the parent), require a file from the /build project (something like ["/build/my-file/file" :as x]. the file can be found, because it doesn’t complain about resolving /build/my-file/file, but it does throw an error such as cannot import module 'momentjs' from /build/my-file/file.

thheller18:07:58

first mistake is the /src

thheller18:07:36

please be very clear about the exact paths you are using. otherwise it just gets confusing as hell.

lwhorton18:07:44

ah yea, sorry… assume that’s supposed to be /build/my-file/file

thheller18:07:47

first specify your :source-paths

thheller18:07:29

:source-paths ["src/cljs" "src/js"] I'd suggest

thheller18:07:55

you generate the code into src/js/some-unique-enough-name/my-file/file.js

thheller18:07:06

you MUST qualify names on the classpath otherwise they will clash

lwhorton18:07:43

i will get back to you on this, i’m unfortunately knee-deep in another (unrelated) problem. thanks for the quick turnaround time, though

thheller18:07:43

inside your CLJS you then (:require ["/some-unique-enough-name/my-file/file.js" :as x])

thheller18:07:59

in the JS or TS however you only use relative paths

thheller18:07:16

since node handles absolutes paths differently

thheller18:07:53

cannot import module 'momentjs' from /build/my-file/file who produces this error? its not a shadow-cljs error? is this a node build?

lwhorton18:07:20

give me 2 mins let me context swap so i dont waste your time

thheller18:07:45

isn't the package called just moment? not momentjs?

lwhorton18:07:52

okay, here’s the details:

koz15:07:34

Can you set custom shadow-cljs configuration options based on the deps.edn alias that is passed in on startup via shadow-cljs -A (for instance, only load a preload or set a compiler option if a specific alias is passed)? If not, can you extend an existing build configuration?

thheller15:07:17

what kind of option do you want to pass?

koz15:07:11

Basically, I want to opt-in to re-frame-10x in development since it’s slowing things down at times, so at the minimum, enable the re_frame.trace.trace_enabled_QMARK_ closure-define flag if an alias is passed to the dev build

thheller15:07:04

you could use clj-run and build a function that uses shadow.cljs.devtools.api to do (shadow/get-build-config :foo) update that config map and then call (shadow/compile* modified-config {})

thheller15:07:24

the cli has nothing to overriding built-in currently

koz15:07:45

cool, i’ll look into that. yeah, this is probably an edge case. thanks @thheller

justinlee16:07:55

@thheller new perf enhancements are quite nice. about a third faster on the initial load

👍 4
richiardiandrea19:07:42

so :node-test returns 0 even when tests are failing

thheller19:07:30

only if you use :autorun. instead use compile and run node the-output.js. that will preserve the proper exit code

thheller19:07:35

ie. do shadow-cljs compile the-test && node out/the-test.js

richiardiandrea19:07:40

ok cool that should work

richiardiandrea19:07:35

is there an env var / switch to enable :autorun from the command line (it would be super handy)

richiardiandrea19:07:53

watch should be good enough if it runs the tests

thheller19:07:57

there will probably be some kind of shadow-cljs node-test --ns-regexp foo

thheller19:07:04

so you don't need an actual config

thheller19:07:20

then there could be a --autorun or --compile-only depending on which makes more sense

richiardiandrea19:07:20

the goal would be to keep :autorun false in shadow-cljs.edn but be able to run tests in watch mode

thheller19:07:22

you could set :release {:autorun false} and then use shadow-cljs release the-tests. that way they wouldn't autorun

richiardiandrea19:07:12

uhm I am doing yarn shadow-cljs release :test && node .cljs-tests/cd-tests.js but I still have a zero exit code

thheller19:07:26

I blame the extra yarn

thheller19:07:41

try without that first

richiardiandrea19:07:51

well, the && is after that

thheller19:07:05

what is the exit of just the node?

thheller19:07:27

and its :target :node-test?

richiardiandrea19:07:30

Ran 3 tests containing 7 assertions.
2 failures, 1 errors.
[email protected] ~/git/laputa/continuous-delivery (master *$% u=)$ echo $?
0

richiardiandrea19:07:46

{:target :node-test
                 :main cd.test-runner/-main
                 :autorun true
                 :release {:optimizations :simple
                           :variable-renaming :off
                           :property-renaming :off
                           :pretty-print true
                           :source-map true
                           :autorun false}
                 :output-to ".cljs-tests/cd-tests.js"}

richiardiandrea19:07:09

maybe the merge has a problem, let me get rid of :autorun true

thheller19:07:26

thats incorrect. missing a :compiler-options for anything but :autorun

thheller19:07:50

but none of that would affect the exit code

richiardiandrea20:07:22

trying:

{:target :node-test
                 :main cd.test-runner/-main
                 ;; :autorun true
                 :release {:compiler-options {:optimizations :simple
                                              :variable-renaming :off
                                              :property-renaming :off
                                              :pretty-print true
                                              :source-map true}
                           :autorun false}
                 :output-to ".cljs-tests/cd-tests.js"}

thheller20:07:00

wait. why is there is :main?

richiardiandrea20:07:08

yeah let me get rid of that

richiardiandrea20:07:37

I wanted to test only one namespace

richiardiandrea20:07:46

but it is unnecessary

thheller20:07:54

then set :ns-regexp "that.ns"

thheller20:07:02

ugly hack but works for now

richiardiandrea20:07:14

yeah so removing the :main makes it work

richiardiandrea20:07:02

still odd the reason why it does not do it though, I can open a low-prio issue if you like

thheller20:07:15

well it won't include the main runner ns then

thheller20:07:29

so the defmethod isn't added which sets the exit code

thheller20:07:44

:main is allowed in case you want to use other test frameworks and such

thheller20:07:22

nothing odd about it. should probably just document it.

richiardiandrea20:07:09

Ok cool thanks for the support 😉

flyboarder20:07:20

@thheller We are building out a comprehensive collection of boot tasks for shadow-cljs

flyboarder20:07:43

feedback from any boot users is appreciated

thheller20:07:37

@flyboarder :cache-root is a global config option and cannot be set per build

flyboarder20:07:00

@thheller thanks! cache disabled!

grav21:07:50

Is it possible to set a closure define in the config edn from an environment variable?

thheller21:07:10

@grav #shadow/env "THE_THING"