johnpbloch/wordpress

Setting `"wordpress-install-dir": "."` erases installation directory

malthejorgensen opened this issue · 2 comments

I wanted to install Wordpress in the same folder as the rest of my files so I set

"extras": {
  "wordpress-install-dir": "."
}

in composer.json.

This erased all files in the directory, including the .git-folder and .gitignore – leaving only the files from this repository (johnpbloch/wordpress).

Hi @malthejorgensen,

Thanks for reporting the issue. I think this is not quite the way you want to go about doing what you want to do. That being said, the installer shouldn't let that mistake happen. I'm not at my computer at the moment, so could you please copy this issue one to my wordpress-installer repository? I'll work on a fix that prevents composer from accidentally overwriting an important directory.

As a general rule, composer dependencies should not be under version control and need to be self-contained (i.e. in its own dedicated directory) so that composer can safely manage it as a dependency. That includes deleting the contents of the old version and replacing them with the new version when updating. That means that if you want to manage WordPress with composer, it needs to be a subdirectory installation with wp-content moved outside of WordPress core.

If you want wp-content in its normal place, you can't manage core with composer because a core update would delete all themes, plugins, and uploads.

The best way to use composer to install WordPress in the root directory of your project is

composer create-project johnpbloch/wordpress 4.7 .

at the beginning of your project. After that, you can use WP CLI to update core.

I think this is not quite the way you want to go about doing what you want to do.

Yeah, I thought I was a bit overzealous 🤣

could you please copy this issue one to my wordpress-installer repository?

I'll do that.

I'll work on a fix that prevents composer from accidentally overwriting an important directory.

Thank you, I was thinking about doing a pull request myself, but created the issue as a reminder. If you have the time, I think it makes more sense for you to do it, as you have the understanding of how the package works. Otherwise, I can do it :)