Skip to content

Commit

Permalink
[TASK] Handle replaced packages properly
Browse files Browse the repository at this point in the history
Composer allows to define a package to replace
others. This may be used also for extensions.

Therefore, we now regonize packages replacing
other packages and store that information.
We also try to determne the replaced extension
key, albeit we do not properly check for this
during extension symlinking into test instances.

Releases: main, 7
  • Loading branch information
sbuerk committed May 11, 2023
1 parent af280b6 commit b6a4c0f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Classes/Composer/ComposerPackageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ private function processPackages(): void
{
foreach (InstalledVersions::getAllRawData() as $loader) {
foreach ($loader['versions'] as $packageName => $version) {
// We ignore replaced packages. The replacing package adds them with the final package info directly.
if (($version['replaced'] ?? false)
&& $version['replaced'] !== []
) {
continue;
}
$packagePath = $this->getPackageInstallPath($packageName);
$packageRealPath = $this->realPath($packagePath);
$info = $this->getPackageComposerJson($packagePath);
Expand Down Expand Up @@ -339,6 +345,17 @@ private function addPackageInfo(PackageInfo $packageInfo): void
if ($packageInfo->getExtensionKey() !== '') {
self::$extensionKeyToPackageNameMap[$packageInfo->getExtensionKey()] = $packageInfo->getName();
}
foreach ($packageInfo->getReplacesPackageNames() as $replacedPackageName) {
self::$packages[$replacedPackageName] = $packageInfo;
if ($packageInfo->isExtension() || $packageInfo->isSystemExtension()) {
$extensionKey = basename($replacedPackageName);
if (str_starts_with($extensionKey, 'cms-')) {
$extensionKey = substr($extensionKey, 4);
}
$extensionKey = $this->normalizeExtensionKey($extensionKey);
self::$extensionKeyToPackageNameMap[$extensionKey] = $replacedPackageName;
}
}
}

private function rootPackage(): ?PackageInfo
Expand Down
14 changes: 14 additions & 0 deletions Classes/Composer/PackageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ public function getWebDir(): string
{
return (string)($this->info['extra']['typo3/cms']['web-dir'] ?? '');
}

/**
* @return string[]
*/
public function getReplacesPackageNames(): array
{
$keys = array_keys($this->info['replace'] ?? []);
if ($this->isMonoRepository()) {
// Monorepo root composer.json replaces core system extension. We do not want that happen, so
// ignore only replaced core extensions.
$keys = array_filter($keys, static fn ($value) => !str_starts_with($value, 'typo3/cms-'));
}
return $keys;
}
}

0 comments on commit b6a4c0f

Please sign in to comment.