Comments (8)
This is not supported. This is not at all what hooks are meant for and I strongly suggest looking for other solutions. Why do this at all as part of the build cycle? Seems like a bad fit to abuse the shadow-cljs file watcher to trigger a build and then make it do something else instead?
from shadow-cljs.
Thanks for having a look!
First of all, "format on save" is an extremely common desire.
I'm not abusing shadow-cljs builds for triggering formatting. I certainly can set up a file watcher myself.
What I'm seeking is optimal behavior: files are only compiled after the final formatting is applied. i.e. I can avoid double compilations, which as mentioned are noisy and slower.
For accomplishing that, by definition, I need some sort of coordination with shadow-cljs. Hooks seem a good medium for achieving that coordination.
from shadow-cljs.
Would a "format before save" not make more sense? That is how I handle it in Cursive?
from shadow-cljs.
I'm aware that there are many approaches to formatting.
As a tooling author, I'm seeking to offer a workflow that a wide variety of Clojure programmers could use, regardless of their choice of IDE, or how that particular IDE might be configured.
In that regard, "format on save" is a universal inferface that anyone can participate in, and that requires zero knowledge and setup.
from shadow-cljs.
You can toggle the autobuild feature off completely via (shadow.cljs.devtools.api/watch-set-autobuild! :the-build false)
and then enable it again after the formatting finished? You can also drop the autobuild completely and just always trigger the build via (shadow.cljs.devtools.api/watch-compile! :the-build)
. That'll account for all changes it detected since the last compile.
Would that work?
from shadow-cljs.
There is also a 500ms delay before a compilation starts, after changes were detected. Precisely for cases such as this where other things might happen after save. Maybe that just isn't enough for your case? :fs-watch {:loop-wait 1000}
would bump that to 1sec instead.
from shadow-cljs.
You can toggle the autobuild feature off completely via (shadow.cljs.devtools.api/watch-set-autobuild! :the-build false) and then enable it again after the formatting finished?
I tried this and in appears to leave the build stuck in this state:
[:app] Compiling ..
Maybe that just isn't enough for your case?
That wouldn't be a deterministic fix, and also would make users pay a fixed performance penalty. People typically enjoy fast hot-reloads.
Would you generously take a look at the original proposal? As I see it, it is aligned with the design pattern that is documented in https://shadow-cljs.github.io/docs/UsersGuide.html#build-hooks:
They will receive the build-state (a clojure map with all the current build data) as their first argument and must return this build-state modified or unmodified.
I'm fairly certain that taking a state object, inspecting it for a :shadow.cljs.compilation/abort
key and dropping the current workload if found is something that is simple and easy. i.e. refraining from doing work is simple.
I could totally see how a request for e.g. an exotic feature or intrincate logic could be something reasonable to dismiss, but hopefully that's not the case here.
from shadow-cljs.
No, I will not be considering solving this via :build-hooks
. Implementing it is trivial, but it just feels fundamentally broken as a concept. The decision whether to build or not is not to be made when the build already started. There is already some "progress" happening in the build state before it gets to any hooks, so I also don't want to potentially having to "rollback" those changes.
That being said I'm willing to consider alternate solutions.
So, lets start with the watch-set-autobuild!
I suggested. It is working fine for me locally and doesn't get stuck. If you provide the steps to reproduce I can take a closer look.
It would help immensely if your entire setup is somewhat reproducible, so I can see what stuff is actually doing and when. Also what kind of capabilities it may have.
from shadow-cljs.
Related Issues (20)
- Warnings on using decprecated-fn in a deprecated-fn HOT 3
- CLJS build failure HOT 2
- class shadow.undertow$fn$reify__11358 cannot be cast to class clojure.lang.Var$Frame HOT 3
- Requiring a namespace with an underscore instead of dash gets par-compile stuck
- :js-provider :external should support :modules
- Mention that build report only works for :browser target HOT 9
- Issue with CORS in dev HTTP server since 2.25.10 release HOT 2
- :module-hash-names doesn't work with :web-worker true
- Build report for :node-library builds needlessly requires :output-dir
- Preloads with a top-level namespace don't load macros HOT 3
- 2.26.5 incorrectly tagging @dagrejs/dagre npm module js file as es3 HOT 2
- date-fns v3.3.1 and shadow-cljs 2.26.5 to 2.26.6 triggers ICE HOT 2
- Compiling squint-cljs (via @nextjournal/clojure-mode) on 2.27.1 throws ICE HOT 14
- npm-module exports vars in random order with large namespaces HOT 2
- Check namespaced keywords for build ids
- More readable error log with pre-line for browser-test HOT 3
- Srting handling different to clj HOT 1
- `Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.tools.analyzer.utils/update-vals` when trying to import a dependency via git HOT 9
- #shadow/env not working in ~/.config/shadow-cljs/config.edn? HOT 7
- How to debug the par-compiler for :cache-level :all HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shadow-cljs.