First of all, you should be using
npm link or at least manually symlinking your projects into
node_modules so only the links get deleted if something happens.
So this behavior is due to how new versions of npm work. NodeBB uses npm to install plugins. The short answer is to just say that your custom plugins and themes need to be added to package.json otherwise npm will remove it. npm might even remove it anyways. If you keep having issues, you might consider switching to yarn.
You can tell nodebb to use yarn by setting the
package_manager field in config.json to "yarn"