thheller / shadow-cljs

ClojureScript compilation made easy
https://github.com/thheller/shadow-cljs
Eclipse Public License 1.0
2.27k stars 179 forks source link

Building scripts in the same cljs file should not build twice #343

Closed arichiardi closed 6 years ago

arichiardi commented 6 years ago

Hi all and Thomas, A hopefully small feature request as cropped up today.

I have two scripts in my shadow-cljs.edn:

{:cpp {:target :node-script
                :main cd.core/create-publish-pipeline
                :output-to "bin/create-publish-pipeline"
                :devtools {:autoload false
                           :enabled false}
                :release {:compiler-options {:optimizations :simple}}}
          :aenv {:target :node-script
                 :main cd.core/assert-environment
                 :output-to "bin/assert-environment"
                 :devtools {:autoload false
                            :enabled false}
                 :release {:compiler-options {:optimizations :simple}}}}

The both live in cd.core. The problem is that when I do yarn shadow-cljs release :cpp :aenv I see:

[:cpp] Compiling ...
[:aenv] Compiling ...
[:aenv] Build completed. (39 files, 1 compiled, 0 warnings, 17.45s)
[:cpp] Build completed. (39 files, 1 compiled, 0 warnings, 17.45s)

Which seems to compile the namespace twice. I know that there is caching so I am not sure detecting and avoiding compiling twice would speed up things, but I am opening this issue nonetheless just to talk about it.

thheller commented 6 years ago

Each build runs isolated and does not share resources with other builds. That is by design and probably not changing anytime soon. Cache invalidation is hard enough as it is and building a cross-build cache would only make it harder.

Yes everything is compiled twice (once per build) but with the proper caching in place that should never be an issue?

thheller commented 6 years ago

That being said why not create one node-script which you call by bin/script create-publish-pipeline ... or bin/script assert-environment ... and do the dispatch manually in :main cd.core/main?

arichiardi commented 6 years ago

I prefer to keep them separated, I wonder if 30 seconds sounds like normal when compiling one single file with a couple deps. I will try to enable verbosity and see what is cached and what not just to make sure. Thank you!

arichiardi commented 6 years ago

All seems good, with :whitespace the release build was reduced to around 20 seconds. Closing.