Git Product home page Git Product logo

Comments (8)

thheller avatar thheller commented on June 13, 2024

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.

vemv avatar vemv commented on June 13, 2024

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.

thheller avatar thheller commented on June 13, 2024

Would a "format before save" not make more sense? That is how I handle it in Cursive?

from shadow-cljs.

vemv avatar vemv commented on June 13, 2024

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.

thheller avatar thheller commented on June 13, 2024

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.

thheller avatar thheller commented on June 13, 2024

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.

vemv avatar vemv commented on June 13, 2024

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.

thheller avatar thheller commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.