@pasib -- sorry to hear about that! Yes, npm or yarn will sometimes clobber anything inside node_modules/. Never do anything in that directory as it is considered transient!
Look into npm link or yarn link, and develop your theme elsewhere. Then you can use those tools to "link" the theme into the node_modules/ folder, and it will be safe from deletion. Sometimes the link itself will be deleted, but that is trivial to put back in.