Prevent writing the same file several times (fixes #3753)

As far as I can see, `jsPath` always ends with `.js`.