Skip to content

Instantly share code, notes, and snippets.

@Blizzke
Created July 16, 2015 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blizzke/c46f614640be10ecf2d3 to your computer and use it in GitHub Desktop.
Save Blizzke/c46f614640be10ecf2d3 to your computer and use it in GitHub Desktop.
Heroku split dependencies composer.json

Hello,

Our demo application running on heroku uses the default composer.json for our project. Unfortunately the project contains functionality that is optional in use for the user, but would be nice to be able to demo in the site.

So we're having a bit of a dilemma: Take for example our soap logging functionality. We would like to demo it, but including the extension as a dependency in the composer.json would force all our users to have it too, which is not what we want. We've added yii2-swiftmailer already as a dependency (which is also optional) to demonstrate the mail capabilities.

Is there another way to indicate to to Heroku that it should install the soap extension? Eg a require-heroku in the composer.json or some settings in a .heroku.yml? We would really like to avoid having to add another branch to maintain specifically for that purpose.

Thanks!


Hi Steve,

We had pondered auto-installing extensions from the suggest list before, but the problem is that those don't support version constraints.

Even with a separate key, the problem is that we use composer.lock information, and we resolve the entire dependency graph of all platform packages at once using repurposed Composer internals. This guarantees that you never end up with mismatched extension versions et cetera. Injecting new extensions into that predictably stable graph may cause conflicts that would then cause a build failure.

My recommendation, also after consulting one of the Composer maintainers, is to really have a separate demo project with "all the bells and whistles", and a separate project that has fewer dependencies.

Another alternative may be to use the COMPOSER env var, to have a composer-max.json with the extra dependencies. You then set that config var on the app (heroku config:set COMPOSER=composer-max.json), and it will build using that alternative composer-max.json and composer-max.lock.

You can automate that using the Heroku Button, which I presume you're already using - you can pre-set that config var there.

Your users would do a composer install as usual, and COMPOSER=composer-max.json composer install if they want "maximum bling" - you could include the Yii Swiftmailer dependency in there as well.

Obviously in your code you then need to dynamically at runtime determine if these "optional" dependencies exist and not use them. And you need to remember to always run composer update and COMPOSER=composer-max.json composer update, but the upshot is that this is a portable solution that will work anywhere, and is not proprietary to Heroku.

Hope that helps,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment