Welcome! Please see the About page for a little more info on how this works.

0 votes
in tools.namespace by

Having a cljc file at path {{public/js/out/foo/bar.cljc}} with ns form {{(ns foo.bar)}} will result in namespace {{foo.bar}} being reloaded.

This is problematic because ClojureScript compiler will copy all the input files to {{:output-dir}} for source-map use. Lately as more libraries have started using cljc, and this has started causing problems in cases where library is used on Clojure env. Cljs compilation will result in reload of the library code, which can redefine protocols etc. and break the Clojure env.

I think it would make sense for tools.namespace to ignore changes where file path and namespace don't match.
Another question and perhaps way to fix this, is to understand why dependency resolution doesn't work in this case: namespaces which depend on the protocols at a cljc file on output-dir aren't reloaded.

19 Answers

0 votes
by

Comment made by: stuart.sierra

Using {{c.t.n.repl}}, an ignored directory can be added back to the scan by calling {{c.t.n.repl/clear}} to initialize a new tracker.

0 votes
by
_Comment made by: deraen_

Great!

I applied and installed this locally and tested with one Boot projects where I know Cljs output contains some [[.cljc}} namespaces, and this indeed ignores those.

Two notes:

Every time I call refresh, I get the warning about directory being ignored. This does add a bit clutter, but is probably acceptable, as system restart will probably log a few lines anyway in most cases.

One thing that might be a problematic, is that if single file has bad ns declaration at some point, e.g. user accidentally has typo on the name, the whole directory is ignored untill {{clear}} is called. This will probably cause confusion. Would it make sense automatically remove ignored directories if the problematic files are fixed? Looks like that would be possible in {{find-files}}.
0 votes
by

Comment made by: deraen

-5 patch modifies {{find-files}} to check ignored directories if all the ns declarations in the directory have been fixed. I had to move the side-effects from predicate functions to {{find-files}} so this is not the cleanest change, but should work. I should be able to clean this a bit if this seems like good approach.

0 votes
by
Reference: https://clojure.atlassian.net/browse/TNS-45 (reported by deraen)
...