mirror of
https://github.com/composer/composer
synced 2025-05-11 01:22:54 +00:00
Make plugins have actual constraints instead of fixed versions
Instead of developing plugins against a single, fixed Plugin API version - `"composer-plugin-api": "1.0.0"`, this change will allow plugin developers to use versions like `"composer-plugin-api": "~1.1"` or `"composer-plugin-api": ">=2.1 <3.0"`, aka actual Composer-compatible constraints. Only the "1.0", "1.0.0" and "1.0.0" Plugin API versions will be regarded as BC versions, and internally converted to "^1.0"; every other declared version string will be kept as it is. Because of this new constraint flexibility, plugin version mismatches will be skipped, which means those plugin will NOT be registered to the system. Previously, a mismatch triggered a warning, but plugins were still registered.
This commit is contained in:
parent
d4dbeeacc4
commit
eb2aa14830
13 changed files with 350 additions and 11 deletions
|
@ -122,6 +122,7 @@ class PluginManager
|
|||
foreach ($package->getRequires() as $link) { /** @var Link $link */
|
||||
if ('composer-plugin-api' === $link->getTarget()) {
|
||||
$requiresComposer = $link->getConstraint();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,14 +130,17 @@ class PluginManager
|
|||
throw new \RuntimeException("Plugin ".$package->getName()." is missing a require statement for a version of the composer-plugin-api package.");
|
||||
}
|
||||
|
||||
if (!$requiresComposer->matches(new VersionConstraint('==', $this->versionParser->normalize(PluginInterface::PLUGIN_API_VERSION)))) {
|
||||
$this->io->writeError("<warning>The plugin ".$package->getName()." requires a version of composer-plugin-api that does not match your composer installation. You may need to run composer update with the '--no-plugins' option.</warning>");
|
||||
$currPluginApiVersion = $this->composer->getConfig()->getPluginApiVersion();
|
||||
$currPluginApiConstraint = new VersionConstraint('==', $this->versionParser->normalize($currPluginApiVersion));
|
||||
if (!$requiresComposer->matches($currPluginApiConstraint)) {
|
||||
$this->io->writeError('<warning>The "' . $package->getName() . '" plugin was skipped because it requires a Plugin API version ("' . $requiresComposer->getPrettyString() . '") that does not match your Composer installation ("' . $currPluginApiVersion . '"). You may need to run composer update with the "--no-plugins" option.</warning>');
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->registerPackage($package);
|
||||
}
|
||||
|
||||
// Backward compatibility
|
||||
if ('composer-installer' === $package->getType()) {
|
||||
} elseif ('composer-installer' === $package->getType()) {
|
||||
$this->registerPackage($package);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue