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.
@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
(See the “Shebang Deps” section.)
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
?
Thank you! 😄
@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"]
.
#!/usr/bin/env bash
"exec" "plk" "-Sdeps" "{:paths [\"/usr/local/lib/planck/src\"]}" "$0" "$@"
(require '[foo.core])
@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".
Using $0
@briemens Yeah. Perhaps one day we will have add-lib
everywhere 🙂
https://gist.github.com/mfikes/a81ae3d006830dc34663f976aaf2291b
But add-lib
is likely to be a REPL-only thing, I suppose.
With this "exec" "echo" "$(dirname $0)"
I get the path of the cljs file
This seems to work @mfikes. Can you verify this? 🙂
"exec" "plk" "-Sdeps" "{:paths [\"$(dirname $0)\"]}" "-Ksf" "$0" "$@"
I see I have the -Ksf flags from the documentation page, from my earlier attempts 😉
@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')
Boiled it down just to be the -K flag, -sf works fine. So auto-cache does not work with multiple files (I assume)
@briemens The issue you describe is similar to https://github.com/planck-repl/planck/issues/749