Description
Currently sphinx_js basically rebuilds the documentation every time as it hooks on env-before-read-docs
and expands docs to process to all found_docs
[0]. The docstring of the callback specifically notes that this is done "because we have no way of telling which ones reference JS code that might have changed".
Turns out, as I somehow managed to find out for an other project Sphinx actually has the tools for that: BuildEnvironment.note_dependency.
Just invoke it with the relevant source file(s) during directive processing and it will add the source file as a dependency of the current rST document, and will remember that during the next (incremental) build.
[0] incidentally a simpler version might have been to hook onto env-get-outdated
and return found_docs
, anything returned by the env-get-outdated
handler is considered a changed file.