Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/pie-behaviour-tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN export DEBIAN_FRONTEND="noninteractive"; \
set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
unzip curl jq wget g++ gcc make autoconf libtool bison re2c pkg-config \
unzip git curl jq wget g++ gcc make autoconf libtool bison re2c pkg-config \
ca-certificates libxml2-dev libssl-dev; \
update-ca-certificates ; \
rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -63,5 +63,6 @@ COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie
COPY --from=build_pie_phar /app/pie.phar /usr/local/bin/pie.original

ENV USING_PIE_BEHAT_DOCKERFILE=1
ENV BEHAT_ALLOW_XDEBUG=1
ENTRYPOINT ["php", "vendor/bin/behat"]
CMD ["--no-snippets"]
6 changes: 6 additions & 0 deletions features/uninstall-extensions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ Feature: Extensions can be uninstalled with PIE
Given multiple extensions were previously installed and enabled
When I run a command to uninstall multiple extensions
Then the extensions should not be installed anymore

# pie uninstall <ext>
Example: A PIE extension installed from a development branch can be uninstalled
Given an extension from a development branch was previously installed and enabled
When I run a command to uninstall an extension
Then the extension should not be installed anymore
18 changes: 18 additions & 0 deletions features/upgrade-extensions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,21 @@ Feature: PIE extensions can be upgraded with PIE
Given I have installed PIE extensions with configure options that have upgrades available
When I run a command to upgrade my extensions
Then the extension has been upgraded with the previous configure options

# pie upgrade
Example: I can upgrade a PIE extension installed from a development branch that has new commits
Given I have installed a PIE extension from a development branch with configure options that has new commits
When I run a command to upgrade my extensions
Then the extension has been upgraded to the latest commit with the previous configure options

# pie upgrade
Example: Upgrading a PIE extension installed from a development branch with no new commits does nothing
Given I have installed a PIE extension from a development branch that has no new commits
When I run a command to upgrade my extensions
Then the extension should not have been re-installed

# pie upgrade
Example: Upgrading when no PIE extensions are installed tells me there is nothing to upgrade
Given I have no PIE extensions installed
When I run a command to upgrade my extensions
Then I should see there is nothing to upgrade
10 changes: 9 additions & 1 deletion src/Command/UpgradeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
)]
final class UpgradeCommand extends Command
{
private const NOTHING_TO_UPGRADE = '<error>No PIE extensions are currently installed, so there is nothing to upgrade.</error>';

public function __construct(
private readonly ContainerInterface $container,
private readonly ComposerIntegrationHandler $composerIntegrationHandler,
Expand Down Expand Up @@ -70,7 +72,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
}

if (! file_exists(PieComposerFactory::getLockFile(Platform::getPieJsonFilename($targetPlatform)))) {
$this->io->writeError('<error>No PIE extensions are currently installed, so there is nothing to upgrade.</error>');
$this->io->writeError(self::NOTHING_TO_UPGRADE);

return Command::INVALID;
}
Expand All @@ -80,6 +82,12 @@ public function execute(InputInterface $input, OutputInterface $output): int
PieComposerRequest::noOperation($this->io, $targetPlatform),
);

if ($existingComposer->getLocker()->getLockedRepository()->getPackages() === []) {
$this->io->writeError(self::NOTHING_TO_UPGRADE);

return Command::INVALID;
}

$configureOptions = [];
foreach ($this->installedPiePackages->allPiePackages($existingComposer)->packages() as $installedPackage) {
$existingConfigureOptions = $installedPackage->installedJsonMetadata()->configureOptions();
Expand Down
22 changes: 16 additions & 6 deletions src/ComposerIntegration/AddInstalledJsonMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use function array_merge;
use function implode;
use function in_array;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
class AddInstalledJsonMetadata
Expand Down Expand Up @@ -114,15 +115,24 @@ private function addPieMetadata(
string $key,
string|null $value,
): void {
$localRepositoryPackage = $composer
->getRepositoryManager()
->getLocalRepository()
->findPackages($composerPackage->getName())[0];
$localRepository = $composer->getRepositoryManager()->getLocalRepository();
$localRepositoryPackages = $localRepository->getPackages();
$localRepositoryPackage = null;

if ($localRepositoryPackage instanceof CompleteAliasPackage) {
$localRepositoryPackage = $localRepositoryPackage->getAliasOf();
foreach ($localRepository->findPackages($composerPackage->getName()) as $candidatePackage) {
if ($candidatePackage instanceof CompleteAliasPackage) {
$candidatePackage = $candidatePackage->getAliasOf();
}

if (! in_array($candidatePackage, $localRepositoryPackages, true)) {
continue;
}

$localRepositoryPackage = $candidatePackage;
break;
}

Assert::notNull($localRepositoryPackage);
Assert::methodExists($localRepositoryPackage, 'setExtra');

$localRepositoryPackage->setExtra(array_merge($localRepositoryPackage->getExtra(), [$key => $value]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Closure;
use Composer\Composer;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
Expand Down Expand Up @@ -47,7 +48,12 @@ public function __invoke(InstallerEvent $installerEvent): void
$newOperations = array_filter(
$installerEvent->getTransaction()?->getOperations() ?? [],
function (OperationInterface $operation) use ($pieOutput): bool {
if (! $operation instanceof InstallOperation && ! $operation instanceof UninstallOperation && ! $operation instanceof UpdateOperation) {
if (
! $operation instanceof InstallOperation
&& ! $operation instanceof UninstallOperation
&& ! $operation instanceof UpdateOperation
&& ! $operation instanceof MarkAliasUninstalledOperation
) {
$pieOutput->writeError(
sprintf(
'Unexpected operation during installer: %s',
Expand Down
8 changes: 8 additions & 0 deletions src/ComposerIntegration/PiePackageInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use function array_map;
use function implode;
use function React\Promise\resolve;
use function sprintf;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
Expand Down Expand Up @@ -73,6 +74,13 @@ function (CompletePackageInterface $composerPackage): void {
));
}

/** @inheritDoc */
protected function updateCode(PackageInterface $initial, PackageInterface $target)
{
return ($this->removeCode($initial) ?? resolve(null))
->then(fn () => $this->installCode($target));
}

/** @inheritDoc */
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
Expand Down
2 changes: 2 additions & 0 deletions test/assets/pie-upgrade-no-extensions/pie.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
18 changes: 18 additions & 0 deletions test/assets/pie-upgrade-no-extensions/pie.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d751713988987e9331980363e24189ce",
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {},
"prefer-stable": false,
"prefer-lowest": false,
"platform": {},
"platform-dev": {},
"plugin-api-version": "2.9.0"
}
Loading
Loading