Factored out into https://github.com/composer/composer/pull/2666