Using cljs.jar, version 1.7.48.
Desired behavior: ability to watch a single cljs file for changes, without any additional directories.
I'm aware that:
java -cp cljs.jar:src clojure.main watch.clj
is the normal command to run.- Single-segment namespaces are not normally recommended.
With that said, it would be very neat to be able to have just a single cljs file and a temporary out directory. How do you best achieve this? What changes have to be made to the FS watcher?
watch.clj
:
(require 'cljs.build.api)
(cljs.build.api/watch "src"
{:main 'hello
:output-to "out/main.js"})
src/hello.cljs
:
(ns hello)
(enable-console-print!)
(println "Hello world A!")
Output of running java -cp ~/bin/cljs.jar: clojure.main watch.clj
:
Reading analysis cache for jar:file:/Users/oskarth/bin/cljs.jar!/cljs/core.cljs
Compiling src/hello.cljs
WARNING: hello is a single segment namespace at line 1 src/hello.cljs
... done. Elapsed 0.992244 seconds
Watching paths: /Users/oskarth/tmp/cljs-watch-behavior/src
Change detected, recompiling ...
Compiling src/hello.cljs
WARNING: hello is a single segment namespace at line 1 src/hello.cljs
... done. Elapsed 0.110331 seconds
Change detected, recompiling ...
Compiling src/hello.cljs
WARNING: hello is a single segment namespace at line 1 src/hello.cljs
... done. Elapsed 0.066818 seconds
I get WARNING: hello is a single segment namespace at line 1 src/core.cljs, but it works.
Moving src/hello.cljs
to hello.cljs
and changing watch.clj
to:
(cljs.build.api/watch "hello.cljs"
{:main 'hello
:output-to "out/main.js"})
Output:
~/tmp/cljs-watch-behavior$ java -cp ~/bin/cljs.jar: clojure.main watch.clj
Building ...
Analyzing jar:file:/Users/oskarth/bin/cljs.jar!/cljs/core.cljs
WARNING: hello is a single segment namespace at line 1 hello.cljs
Compiling out/cljs/core.cljs
Using cached cljs.core out/cljs/core.cljs
... done. Elapsed 5.7541 seconds
Watching paths: /Users/oskarth/tmp/cljs-watch-behavior/hello.cljs
Changing hello.cljs doesn't change anything. (It also says it's using cached cljs.core, but I ran rm -r out
in between runs.)
If I change it to absolute path of current directory, it predictably goes into an infinite loop (due to FS changing after out dir)
watch.clj
:
(cljs.build.api/watch "/Users/oskarth/tmp/cljs-watch-behavior"
{:main 'hello
:output-to "out/main.js"})
~/tmp/cljs-watch-behavior$ java -cp ~/bin/cljs.jar: clojure.main watch.clj
Building ...
Reading analysis cache for jar:file:/Users/oskarth/bin/cljs.jar!/cljs/core.cljs
Compiling /Users/oskarth/tmp/cljs-watch-behavior/hello.cljs
WARNING: hello is a single segment namespace at line 1 /Users/oskarth/tmp/cljs-watch-behavior/hello.cljs
Compiling out/cljs/core.cljs
Using cached cljs.core out/cljs/core.cljs
... done. Elapsed 1.521039 seconds
Watching paths: /Users/oskarth/tmp/cljs-watch-behavior
Change detected, recompiling ...
Compiling /Users/oskarth/tmp/cljs-watch-behavior/out/hello.cljs
WARNING: hello is a single segment namespace at line 1 /Users/oskarth/tmp/cljs-watch-behavior/out/hello.cljs
... done. Elapsed 0.098181 seconds
Change detected, recompiling ...
... done. Elapsed 0.069759 seconds
Change detected, recompiling ...
... done. Elapsed 0.058259 seconds
Change detected, recompiling ...
... done. Elapsed 0.061258 seconds
Change detected, recompiling ...
build.clj
:
(require 'cljs.build.api)
(cljs.build.api/build "hello.cljs"
{:main 'hello
:output-to "out/main.js"})
Running java -cp ~/bin/cljs.jar: clojure.main build.clj
gives no output (other than warning for single segment ns), but it produces js.