Fix NullPointerException when processing externs files #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
lein-figwheel expects that all files with .js extension inside its
source directories are foreign libraries. And foreign libraries must
declare a namespace. In fact, lein-figwheel assumes all .js files have
such a namespace declared. And it blindly tries to use it to map the
.js file back to a source .cljs file. When the namespace is not
declared in the .js file, lein-figwheel bombs out with a
NullPointerException when it tries to check if the the source .cljs
file exists.
This might happen when you put your externs file(s) inside the source
directories (this is our case,
e.g. https://github.com/magnetcoop/hydrogen-ce/blob/master/src/hyd/client/externs.js)
lein-figwheel doesn't try to process such files by default on its
own. But when using Duct server.figwheel, it tells lein-figwheel to
process all files inside the configured source directories (see
https://github.com/duct-framework/server.figwheel/blob/master/src/duct/server/figwheel.clj#L54-L55).
Clearly lein-figwheel should be more robust and handle that situation
in a more graceful way[1]. On the other hand Duct server.figwheel
shouldn't be telling lein-figwheel to process absolutely all files in
source directories. It doesn't make sense to process .clj files, .edn
files, etc. Probably just those having .cljs/.cljc extension and those
declared as foreign libraries.
In issue #7 James Reeves suggested that instead of hard-coding the
list of files to process by lein-figwheel, we should have configurable
options with default values. And he suggested using a regular
expression for matching filenames.
[1] We opened a pull request in lein-figwheel regarding this
behaviour, see bhauman/lein-figwheel#739. It has been fixed since
then and included in figwheel-sidecar 0.5.20. But Duct
server.figwheel is still using figwheel-sidecar 0.5.18