planck

Planck ClojureScript REPL
briemens 2018-07-07T19:32:23.000016Z

Question! I’m writing a small cli application in Planck which I want to call from anywhere by putting the location of this app/script in my path. The thing is I can’t figure out is how to reference/require my sub cljs files. So what I did to make my code manageable is break it up into multiple files, which I put in a subdirectory under the main cljs file. I can require them just fine as long as I exec the main cljs file from the app’s root dir, anywhere else requiring fails because it tries to find the dependencies relative to the dir I’m currently in. What are my options? Do I need to solve this using a bash command (change my cwd), start Planck with a cli option or manage it from code? Any advice would be welcome.

mfikes 2018-07-07T19:47:05.000008Z

@briemens perhaps you could make a stand-alone script as described here http://planck-repl.org/dependencies.html but use :paths to define fully-qualified paths to where your subscripts reside

mfikes 2018-07-07T19:48:21.000026Z

(See the “Shebang Deps” section.)

briemens 2018-07-07T19:51:59.000006Z

Thanks @mfikes I was reading that section carefully, but couldn't find an example of how to use/work with :paths. Thanks for pointing me into this direction I will play with this a bit more. Is there anywhere else where I can read up on :paths?

briemens 2018-07-07T19:57:02.000079Z

Thank you! 😄

mfikes 2018-07-07T20:03:15.000049Z

@briemens I misspoke when saying "fully-qualified." I meant "absolute." So for example, if you have a subscript at /usr/local/lib/planck/src/foo/core.cljs you would include :paths ["/usr/local/lib/planck/src"].

mfikes 2018-07-07T20:06:01.000013Z

#!/usr/bin/env bash
"exec" "plk" "-Sdeps" "{:paths [\"/usr/local/lib/planck/src\"]}" "$0" "$@"
(require '[foo.core])

briemens 2018-07-07T20:25:16.000028Z

@mfikes I tried this right after you mentioned :path and this definitely works. I'm now trying to find a hack to inject the absolute path "dynamically".

briemens 2018-07-07T20:26:54.000029Z

Using $0

mfikes 2018-07-07T20:26:56.000073Z

@briemens Yeah. Perhaps one day we will have add-lib everywhere 🙂 https://gist.github.com/mfikes/a81ae3d006830dc34663f976aaf2291b

mfikes 2018-07-07T20:27:28.000059Z

But add-lib is likely to be a REPL-only thing, I suppose.

briemens 2018-07-07T20:28:13.000043Z

With this "exec" "echo" "$(dirname $0)" I get the path of the cljs file

briemens 2018-07-07T20:29:39.000061Z

This seems to work @mfikes. Can you verify this? 🙂

"exec" "plk" "-Sdeps" "{:paths [\"$(dirname $0)\"]}" "-Ksf" "$0" "$@"

briemens 2018-07-07T20:32:34.000094Z

I see I have the -Ksf flags from the documentation page, from my earlier attempts 😉

briemens 2018-07-07T20:34:16.000067Z

@mfikes I get the following error when running the script for the second time with the -Ksf flags:

undefined is not an object (evaluating 'entries.db.load_entries')

briemens 2018-07-07T20:36:37.000050Z

Boiled it down just to be the -K flag, -sf works fine. So auto-cache does not work with multiple files (I assume)

mfikes 2018-07-07T23:14:42.000053Z

@briemens The issue you describe is similar to https://github.com/planck-repl/planck/issues/749