Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to open cljs file if it doesn't exist #739

Merged
merged 1 commit into from
Oct 12, 2019
Merged

Don't try to open cljs file if it doesn't exist #739

merged 1 commit into from
Oct 12, 2019

Conversation

iarenaza
Copy link
Contributor

lein-figwheel expects files with .js extension inside its source
directories to be foreign libraries. And foreign libraries must
declare a namespace. In fact, lein-figwheel assumes it, and if it
doesn't find it and can't map the file back to a source .cljs file, it
bombs out with a NullPointerException when trying to check for its
existance.

This might happen when you put your externs file(s) inside the source
directories (this is in fact the case that led to the discovery of
this issue).

While lein-figwheel doesn't by default try to process such files on
its own, when using Duct server.figwheel
it tells lein-figwheel to proccess 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 Duct server.figwheel shouldn't be telling lein-figwheel to
process absolutely all files in source directories (but probably just
those having .cljs/cljc extension or those declared as foreign
libraries[1]).

But on the other hand, lein-figwheel should be more robust and handle
that situation in a more graceful way.

[1] We have opened an issue in Duct server.figwheel regarding this behaviour.

lein-figwheel expects files with .js extension inside its source
directories to be foreign libraries. And foreign libraries *MUST*
declare a namespace. In fact, lein-figwheel assumes it, and if it
doesn't find it and can't map the file back to a source .cljs file, it
bombs out with a NullPointerException when trying to check for its
existance.

This might happen when you put your externs file(s) inside the source
directories (this is in fact the case that led to the discovery of
this issue).

While lein-figwheel doesn't by default try to process such files on
its own, when using [Duct
server.figwheel](https://github.com/duct-framework/server.figwheel) it
tells lein-figwheel to proccess 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 Duct server.figwheel shouldn't be telling lein-figwheel to
process absolutely all files in source directories (but probably just
those having .cljs/cljc extension or those declared as foreign
libraries[1]).

But on the other hand, lein-figwheel should be more robust and handle
that situation in a more graceful way.

[1] We have opened an issue in Duct server.figwheel regarding this behaviour.
@bhauman bhauman merged commit baf93e2 into bhauman:master Oct 12, 2019
iarenaza added a commit to biotz/server.figwheel that referenced this pull request Feb 10, 2021
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 duct-framework#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants