This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-25
Channels
- # announcements (22)
- # babashka (9)
- # beginners (33)
- # biff (12)
- # calva (17)
- # cider (64)
- # cljdoc (3)
- # cljfx (16)
- # clojure (125)
- # clojure-bay-area (14)
- # clojure-europe (15)
- # clojure-norway (64)
- # clojure-uk (2)
- # clojurescript (7)
- # conjure (1)
- # core-async (4)
- # cursive (6)
- # data-science (14)
- # datahike (8)
- # datomic (6)
- # defnpodcast (4)
- # emacs (5)
- # events (1)
- # hyperfiddle (15)
- # leiningen (17)
- # lsp (8)
- # membrane (27)
- # off-topic (25)
- # podcasts-discuss (4)
- # polylith (6)
- # portal (21)
- # reagent (11)
- # releases (1)
- # shadow-cljs (36)
- # slack-help (2)
- # sql (1)
- # squint (131)
- # testing (12)
- # xtdb (7)
Maybe more a babashka question, do tasks in bb.edn
join/pipe their stdio
when they are run in parallel
?
Like in https://github.com/squint-cljs/squint/blob/main/examples/vite-react/bb.edn#L4 vite-react
example, where you spawn 2 shells.
I mean: we can see stdout/stderr output from both shells in the single terminal session.
Currently squint watch
compiles all the files in the path, but the compile
command requires file list provided by name.
To use squint for production (in the future) we may need a build
command that behaves almost like watch
(transpiles all files in the path),
but also applies production level optimizations, sans watch feature.
Sorry, optimizations maybe not required. squint -> mjs/jsx -> (vite/esbuild etc.) -> production bundle
will be more proper.
vite-react on main $ npx squint --help
Squint v0.0.0
Usage: squint <subcommand> <opts>
Subcommands:
-e <expr> Compile and run expression.
run <file.cljs> Compile and run a file
watch Watch :paths in squint.edn
compile <file.cljs> ... Compile file(s)
repl Start repl
help Print this help
Use squint <subcommand> --help to show more info.
Created a new vite
project (React/JSX), added squint-cljs
to deps and bb.edn
squint.edn
.
The plan is to not change vite
directory structure, but add a separate src-cljs
path, that outputs into src
which is watched by vite.
The issue is that squint watch
or squint compile
are not outputting transpiled files into src
folder.
https://github.com/sher/squint-vite
I get the confusion but everything on the path needs to use underscores, but not the path directories itself, unless you write :paths ["src_cljs"]
Btw, what is the meaning of adding -
to functions and tasks, does it mean an entry point hint?
Like here https://github.com/squint-cljs/squint/blob/main/examples/vite-react/bb.edn#L4
Still working on squint-vite
and trying to https://github.com/sher/squint-vite/blob/main/bb.edn#L2 to the dest
path, replicating what https://github.com/squint-cljs/squint/blob/main/src/squint/internal/cli.cljs#L142.
Added shadow-cljs
to node dependencies, but can't require it in the babashka task. Getting this error.
----- Error --------------------------------------------------------------------
Type: java.io.FileNotFoundException
Message: Could not locate shadow/esm.bb, shadow/esm.clj or shadow/esm.cljc on classpath.
Location: <expr>:4:47
The idea is to use chokidar
to watch the paths
and copy all non-cljs.@URCRY0U87 I don't understand what you're trying to accomplish. When you run npx squint watch
, files are already watched and compiled by squint? (it uses chokidar under the hood btw)
and why do you need shadow-cljs?
What I m trying to do is copy files like styles, images that can be required like this https://github.com/sher/squint-vite/blob/main/src-cljs/core.cljs#L5
And the compiled output will be like vite would expect https://github.com/sher/squint-vite/blob/main/src/core.jsx
$ ./node_cli.js --show --no-run -e '(ns foo (:require ["assets/core.css"]))'
import * as squint_core from 'squint-cljs/core.js';
import 'assets/core.css';
I am doing as you mentioned above, but the actual assets/core.css
file is never copied to the output destination folder, never processed by squint's chokidar watch function.
My understanding is that chokidar now filters only cljs files https://github.com/squint-cljs/squint/blob/main/src/squint/internal/cli.cljs#L152
this file doesn't have to be compiled using squint, so why should squint watch it? vite itself should pick up on it
where does assets
live in your directory structure? I think you should just place this where vite can already see it
You are correct. The plan was, to make it more developer friendly, to write the app in the src-cljs
folder, also putting all static assets there. Then the dev
or build
tasks would compile cljs files and copy static assets to the src
folder.
right, I think we could add maybe something to squint watch
to support this, to watch all files but to copy all other assets that aren't .cljs files
Then you could add :paths ["src" "resources"]
and even separate the css stuff from the srces
Have to think about making this configurable. Certainly :paths ["src" "resources"]
could work, also clojure way to separate resources. But then vite also should be able have access to files out of src
scope.
> But then vite also should be able have access to files out of src
scope
No, these files are copied to :output-dir
and vite is going to pick them up as relative imports
@URCRY0U87 publishing 0.4.41 now, all non .cljc/.cljs files are just copied over to the output-dir
this also works nicely if you want to include some .js
files among your .cljs
files btw
If all works as expected, can I update your https://github.com/squint-cljs/squint/tree/main/examples/vite-react example or create a new example?
Just tried and files other than cljs
are recursively copied to :output-dir
🎉
Things left to do:
• update squint-vite
and squint
README, mention caveats like
◦ asset imports must have relative path (:require ["./assets/some.css"])
or (:require ["../resources/assets/some.css"])
▪︎ depending on where you wish to keep them
◦ bb tasks should run in parallel in order to have their stdio piped
▪︎ {:parallel true}
option can also be re-considered, because dependent tasks may run serially
but still have stdio piped, so we can see output from every spawned process
▪︎ {:parallel false :stdio "pipe"}
as an option for node https://nodejs.org/docs/latest-v18.x/api/child_process.html#optionsstdio
Will prepare a PR.
I'm not sure what you mean with the stdio issue but maybe it will become clear in the PR
Sorry, not pipe
but inherit
(in nodejs terms) so all spawned child processes' logs will be print to parent process streams.
Currently, if you not state that tasks should run in parallel
child process logs dont appear.
https://github.com/sher/squint-vite/blob/main/bb.edn#L5
They don't appear since the "second" task doesn't even run, it's blocked by the other one until it finishes
I see, if a task depends on multiple other tasks listing them like -dev {:depends [dev:squint dev:vite]}
, none other tasks will run until the previous one is finished?
Now I understand the point. But in dev mode, processes may watch
and never exit.
You may have bunch of those processes, that bundle some sort of deliverables.
Maybe there is a way to accommodate this case, maybe we can consider.
I don't think anything has to change really. watch
is a development task. when you need to bundle stuff up, you quit the watcher, and run squint compile
+ vite build
or whatever
https://github.com/nextjournal/clojure-mode/blob/2da3d79f082ae29e4510b28448217abffa929489/bb.edn#L56
I am excited to share vite-bb with others who wanted to write clojure for frontend SPA.
For this phase, I want to create a command that will give the dev a boilerplate to create a vite SPA project scaffold which has bb.edn squint.edn etc.
I am looking forward to attracting more enthusiasts to both https://github.com/sher/squint-vite/tree/main frontend, using vite SPA and nbb fastify https://github.com/sher/nbb/tree/main/examples/fastify to create a public facing service, all written in cljs.
But, ruby on rails we had this experience decades ago, with rails c
command. You can query database, you can require any class etc.
Squint nREPL if combined with browser websocket, refresh the state of an item: this should be very complicated.
yes, but for Node.js applications nREPL is doable. I'm of the opinion that for front-end hot-reloading with vite is 90% what I want
nREPL on Node.js with squint I mean. nREPL on Node.js with nbb already works perfectly
I understand it is complicated (without understanding the actual complexity), but JavaScript runtime engines trying their best.
> JavaScript runtime engines trying their best. Actually this is what makes it complicated: ES6 (immutable) modules destroy the REPL experiences, you have to basically undo everything ES6 modules stand for
Of course. When you import function f from module F and you call it in your own function:
(ns my-ns (:require [foo :refer [f]]))
(defn g [] (f))
and f
gets redefined, you want to see the updated version when you call g
so when you are in a REPL:
foo> (defn f [] 3)
f
should get updated (which implies mutating the namespace)Every file in squint is compiled to an ES6 module but to make the above possible you basically have to work around it
Is it just a namespace/naming issue, because we can import and destruct values like import { a: b} from 'c'
where original b
inside the module, will be mapped to a
within current context.
This seems to me that you are creating not only compiler, but have to struggle with linker.
It is not just a mapping problem. The original b
can change because of what you are doing in the REPL, but ES6 module c
can never change.
vite uses workarounds for this like adding a ?<timestamp>
to each module and rewrite all imports using these timestamps
CLJS makes the REPL experience possible by just using global mutable objects for namespaces
Now I kind of understand, that in REPL anythyng should happen, even rewriting the imported external library logic.
In an ES6 module but without restarting Node.js for a node app? This is what a REPL should support
I mean, initially, I'm ok with just supporting this for code on :paths
, not JavaScript libraries, but in a squint node app you will be working on multiple namespaces at the same time
With the latest squint copy command update, we can create a full web service: front: squint-vite back-api:nbb-fastify.
Compiling babashka.cli to squint so you can directly use it from JS :-D
[ '--foo', '1' ] {} => { foo: 1 }
[ '--foo', '1' ] { coerce: { foo: 'string' } } => { foo: '1' }
[ '--foo', '1' ] { coerce: { foo: [ 'string' ] } } => { foo: [ '1' ] }
If this means there's a possibility I can npm install
a babashka-like-in-js then I'm very interested! The main thing that stops me from making my apps depend on bb
is needing to install a separate binary outside the normal deployment flow.