So here’s a problem I’m facing. I make changes to some of my extensions in my vendor folder, however, composer update deletes all my changes and brings in the default extension files, overwriting what I already did.
Am I doing something wrong by editing my files in the vendor folder?
Did you create your own repositories of those extensions by forking them? If not, they are not yet yours. Any changes on them should be considered "unofficial" and will be lost on update.
When you want to use some 3rd party extension and customize it, you can do the following:
Fork the extension project into your github repository.
For example, if you want to use "someone/yii2-something", fork it into your github repository as "kevinkt/yii2-something".
Add "repositories" entry to you composer.json at the root level.
Have you ever worked with git and github? Are you using some version control system for your own project? If not, you should not try to do what I have suggested. Instead, you should start to learn how to use VCS (e.g. git or mercurial) at once, before carelessly trying to modify the 3rd party code.
Copy the source files in the vendor directory to somewhere outside of your project directory. You don’t need to copy all the files, but only those files that you have modified.
Fork the extension project(s) that you have modified.
For example, if you have modified "someone/yii2-something", fork it into your github repository as "kevinkt/yii2-something". This process should be done in github, using your github account.
And you must repeat the same process for each extension that you have modified.
Add “repositories” entry to your project’s composer.json at the root level.
Do "composer update", and composer will fetch your extension(s) from your github repositori(es).
This will overwrite all the existing code of the extensions, as was the case with you.
But there’s a big difference. “someone/yii2-something” now doesn’t point to someone’s Packagist package, but to your own github repository. And the directory itself is a local git repository of yours.
Edit your extension in the sub-directory of the vendor directory as you may like.
Here, you can restore the saved files.
Commit the changes and push them to your github repository.
You can commit the changes to the local repository, and push it to your github repository. By doing so, you can maintain your extension’s source code.
So I tried to do this. However, when I push my changes to Github, the extension’s repository (the one that I just forked) doesn’t get updated with my new files I edited.
I think the problem I’m having is that I’m editing my main project through GitHub, but I don’t have separate local repositories set up for each of my extensions I forked. Is that the issue?
“vendor” directory is “ignored” in your main project’s repository. So committing changes to your main repository doesn’t do any changes to your extension’s repository. Do commit in your extension’s repository which is in “vendor” directory.