coenjacobs / mozart

Developers tool for WordPress plugins: Wraps all your projects dependencies in your own namespace, in order to prevent conflicts with other plugins loading the same dependencies in different versions.
https://coenjacobs.me/projects/mozart/
MIT License
427 stars 53 forks source link

How to run Mozart on a composer.json that has platform requirements locked to an older PHP version? #95

Open Luc45 opened 3 years ago

Luc45 commented 3 years ago

Our plugin is compatible with PHP 5.6+. To make sure all our dependencies are also compatible with these PHP versions, we have specified a platform requirement in composer.json:

"config": {
  "platform": {
    "php": "5.6.20"
  }
},

However, Mozart requires PHP 7.2, and as far as I understand, it must be placed in the same composer.json as the one being prefixed.

I can't just run composer update --ignore-platform-reqs to install Mozart because then the PHP version check step will be skipped when resolving my dependencies, installing libraries that are not compatible with PHP 5.6.

Can I use Mozart on a plugin that has PHP platform requirements such as this one?

coenjacobs commented 3 years ago

Yeah, this is something that might be classified as kind of an oversight from my end. I don't think there is a way you can work around this, right now. Mozart might be better off as one of the developer tools, that aren't tied to the project in its composer.json as it directly affects the dependencies that your project actually requires.It also sparked some ideas for resolving the issues raised in #79. I'm going to need some time to properly think things through and consider my options.

Luc45 commented 3 years ago

Awesome, thanks for the reply, @coenjacobs.

Please feel free to close this issue.

coenjacobs commented 3 years ago

@Luc45 I will not close it, as it is a valid issue. Mozart is currently not able to deal with these kind of situations all too well. It's actually one of the main issues that I've tried to explain in #96 now, where I'm discussing the future of Mozart. I do not have an immediate solution for this specific issue, but I am very much keen on solving it in the nearby future.

BrianHenryIE commented 3 years ago

@Luc45

I think I've got a solution for you –– I've created a mozart.phar to use without requiring Mozart in your composer.json. I does still read its config from your project's composer.json, and does still need PHP 7.2 to run, but since it's outside your project it should still work.

Please try:

curl -OL https://github.com/BrianHenryIE/mozart/releases/download/v0.6.0-bh/mozart.phar
php mozart.phar compose

You should be able to put that inside your "post-install-cmd" to download and run each time.

PR #105 would make an official build on each Mozart release.

Luc45 commented 3 years ago

@BrianHenryIE that looks great, thank you!

I've already moved on to another solution, but if I try this out I'll post here the results. Either way, this was a very necessary PR for other people as well.

coenjacobs commented 3 years ago

@Luc45 The above PHAR release that @BrianHenryIE mentioned is now merged into master and released as part of the 0.7.0 release. You basically have three options since release 0.7.0, to install Mozart without affecting the dependencies of the project itself:

  1. Use the Docker container as part of your build process
  2. Use the PHAR file added to each release from now on
  3. Install Mozart as a global dependency on your machine (if that's where you're building your projects)

All three work the exact same, as in that you still configure them in your projects composer.json file. It's just different in how you run them. Please let me know how this works out for you!