This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-28
Channels
- # announcements (12)
- # babashka (87)
- # beginners (84)
- # calva (22)
- # circleci (4)
- # clj-kondo (46)
- # cljdoc (6)
- # cljsrn (15)
- # clojure (87)
- # clojure-europe (18)
- # clojure-uk (7)
- # clojurescript (20)
- # community-development (3)
- # conjure (1)
- # cursive (13)
- # datomic (14)
- # events (7)
- # fulcro (27)
- # graphql (31)
- # helix (8)
- # jobs-discuss (1)
- # lsp (43)
- # malli (11)
- # meander (64)
- # off-topic (7)
- # pathom (26)
- # polylith (9)
- # practicalli (2)
- # re-frame (33)
- # reagent (2)
- # reitit (5)
- # releases (2)
- # rewrite-clj (2)
- # shadow-cljs (69)
- # specter (5)
- # sql (1)
- # tools-deps (85)
- # tree-sitter (1)
- # vim (3)
How can I create a Node CLI tool that allows for optional modules, similar to the modules feature?
Eg I want to offer reagent support, but for those who don’t need it, it should not have to load reagent at startup
I’ve done something similar for scittle via modules but for a Node CLI, can that work as well?
if you are asking about :node-script
then no that cannot do :modules
. there is no currently available target for node that would support this
you could write one but its never come up before so it doesn't exist, also much less relevant in node land given that you'll probably save 1ms or so on startup
I want to make a scripting tool for node and support a variety of libs. Would be very nice if modules worked, so it can be … modular.
well did you try a benchmark of loading nothing vs everything? last time I tried it didn't make much of a difference
modular is trivial from the build perspective though. nobody ever asked for it though so it doesn't yet exist
@thheller I didn't benchmark yet, but can do later today.
> modular is trivial from the build perspective though.
that sounds cool. Does it work with :node-library
already though? I assume it's not that hard to offer a library (which I want to do anyway) that exposes on CLI main namespaces as well
The benchmark is a bit too early days though: adding just one lib might be ok, but dozens of them might impact startup time, which I want to avoid in the long run
I'm trying to use :target :npm-module
, but no matter what I do, I always get the error:
module.exports = goog.debug.Error;
^
TypeError: Cannot read property 'Error' of undefined
Am I doing something wrong here?@mauricio.szabo :npm-module
is pretty much dead. some recent updates to the closure-compiler,closure-library makes it pretty much a no-go
@borkdude none of the node targets support modules currently. :target :esm
does but that not yet fully working for node since the focus was the browser. also still not sure what the current state of ESM in node is. I think it works but interop with CommonJS is kinda weird
it's ok, we just need to have the module loaded and it will register itself through some side effect. beyond that we don't really need interop with the module
:esm
is currently sort of hard coded to bundle all dependencies. which typically isn't what you want for node builds
thanks. @mauricio.szabo is trying this :)
@thheller what I want to do is basically the same as scittle (https://github.com/borkdude/scittle/blob/main/shadow-cljs.edn) but then for the nodeJS ecosystem. Just to give you some context. I understand that things may not be there yet. Will give :esm
a go.
I don't know what you mean by "for the nodeJS ecosystem". I don't even see the point of scittle to be honest so I'm unsure what problem you are actually trying to solve
scittle is a way to make small CLJS apps by just including source in script tags. the use case is to get something going quickly. when the project becomes "too big" then you can migrate to a normal CLJS project.
yeah but why not start a normal CLJS project directly. takes like 10 lines of setup 😛
I noticed that when I tried something different before, I think it can just be an empty map
just :init-fn
would work though. so no :exports
just :init-fn
, at least judging by the code 😛
its really not that much code in the targets https://github.com/thheller/shadow-cljs/blob/ef164e2c46dfe390a86c0f30206b938a08989702/src/main/shadow/build/targets/esm.clj#L118
but maybe you want :exports
anyways, don't know exactly what you are planning for node
in node it would work similarly: you would always start with the tbd.core "module" and optionally you can then load tbd.reagent for example. on load, that module will register itself in some atom.
the user code is a script which gets loaded from a .cljs file which is then interpreted
hmm? scittle looks for <script type="application/x-scittle">
or did I miss something?
yes, tbd (name is subject to change) exposes one CLI main function which has one argument which is the input file
so tbd can have multiple pre-compiled libs available that can be optionally loaded, aside from interpreted scripts and npm libs
Hi! Is there a way to get all declared externs in the command line?
@thheller so I was able to make something work with :npm-module
, and now I'm migrating to :esm
. It's giving me the following error:
file:///home/mauricio/projects/tbd/out/cljs-runtime/shadow.cljs.devtools.client.websocket.js:5
var socket = (new WebSocket(ws_url));
^
ReferenceError: WebSocket is not defined
at shadow$cljs$devtools$client$websocket$start (file:///home/mauricio/projects/tbd/out/cljs-runtime/shadow.cljs.devtools.client.websocket.js:5:14)
@mauricio.szabo need to set :runtime :node
in the build config, otherwise it assumes browser
:esm
needs some work for node targets. I only tested browser and deno as described in the clojureverse post
Right, ok. So far, it works-ish... release
don't work (it fails with Error processing externs: JSC_PARSE_ERROR. Parse error. Semi-colon expected at externs.modules.js line 1 : 10
)
hmm odd, wonder what that line is? can you check the file in .shadow-cljs/builds/<build-id>/release
?
This file doesn't even exist...
╰─>$ ls .shadow-cljs/builds/modules/
dev/
╰─>$ npx shadow-cljs release modules --verbose
shadow-cljs - config: /home/mauricio/projects/tbd/shadow-cljs.edn
[:modules] Compiling ...
-> build target: :esm stage: :configure
<- build target: :esm stage: :configure (3 ms)
-> Resolving Module: :tbd.core
<- Resolving Module: :tbd.core (226 ms)
-> Resolving Module: :tbd.main
<- Resolving Module: :tbd.main (0 ms)
-> Resolving Module: :tbd.reagent
<- Resolving Module: :tbd.reagent (0 ms)
{:type :empty-module, :mod-id :tbd.main, :shadow.build.log/level :info}
{:type :empty-module, :mod-id :tbd.reagent, :shadow.build.log/level :info}
-> build target: :esm stage: :compile-prepare
<- build target: :esm stage: :compile-prepare (2 ms)
Error processing externs:
JSC_PARSE_ERROR. Parse error. Semi-colon expected at externs.modules.js line 1 : 10
Don't know if it helpsAlso, if it helps, this is the code that's currently failing to compile: https://github.com/mauricioszabo/tbd/tree/migrating-to-esm