Reputation: 4049
How can I modify an external package's composer.json file by only modifying my own project's composer.json file?
This is for testing purposes only. I need to test if a package is compatible with a very new version of another package.
My project composer.json:
{
"require": {
"foo/framework": "1.2.0",
"bar/extension": "1.1.0"
}
}
External package (bar/extension
) composer.json:
{
"require": {
"foo/framework": "1.2.0"
}
}
So this obviously works. But let's say I want to have the new version of foo/framework
, which is 1.3.0
. This won't work because bar/extension
depends on the older version.
Using only my project's composer.json, how can I change the requirement for the bar/extension
package?
Upvotes: 4
Views: 716
Reputation: 22174
You may override composer.json
of dependency using repository with package
type. In your composer.json
add something like this (URLs should to be adjusted):
"repositories": [
{
"type": "package",
"package": {
"name": "bar/extension",
"version": "1.1.0",
"dist": {
"url": "https://github.com/bar/extension/archive/1.1.0.zip",
"type": "zip"
},
"require": {
"foo/framework": "1.2.0 || 1.3.0"
}
// rest of necessary settings from original bar/extension composer.json
}
}
],
Note that package
type is very inflexible and creates many problems - I would not recommend using this for anything else than testing. In practice it may be better idea to just fork the package and use vcs
repository to use it in your project - you will be able to make necessary adjustments in package and propose as pull request to upstream (or just use fork permanently).
Upvotes: 3
Reputation: 718
The main idea, if bar/extension
depends on older versions, you should not use newer versions of foo/framework
, because it could be not compatible with a newer version and will cause bugs in your application.
But if bar/extension
on the range of version and you want to use the newest from this range, you could specify this with conflict directive.
Or even you can try the replace directive.
Upvotes: 0