Skip to content

Commit

Permalink
Support mounting unreferenced package
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
  • Loading branch information
betterthanclay committed Nov 7, 2023
1 parent cbffdb2 commit a0f8662
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Support mounting unreferenced package
* Updated templates to target PHP8.1
* Updated gitignore template

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Mount.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function execute(): bool
$conf = Integra::getLocalManifest()->getRepositoryConfig();
/** @var array<string> $packages */
$packages = Cli::$command['packages'];
$packages = $this->lookupPackages($packages);
$packages = $this->lookupPackages($packages, true);
$requires = $devRequires = [];

if (empty($packages)) {
Expand Down
15 changes: 12 additions & 3 deletions src/Task/PackageLookupTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected function getAllPackages(): array
* @return array<string, Package>
*/
protected function lookupPackages(
array $packages
array $packages,
bool $allowUnknown = false
): array {
$output = [];

Expand All @@ -75,15 +76,16 @@ protected function lookupPackages(
continue;
}

$package = $this->lookupPackage($package);
$package = $this->lookupPackage($package, $allowUnknown);
$output[$package->name] = $package;
}

return $output;
}

protected function lookupPackage(
string $key
string $key,
bool $allowUnknown = false
): Package {
foreach ($this->getAllPackages() as $name => $package) {
if (
Expand All @@ -94,6 +96,13 @@ protected function lookupPackage(
}
}

if (
$allowUnknown &&
str_contains($key, '/')
) {
return new Package($key, 'dev-develop');
}

throw Exceptional::InvalidArgument('Unable to resolve package: ' . $key);
}

Expand Down
20 changes: 17 additions & 3 deletions src/Task/Unmount.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ public function execute(): bool
}


$requires = $devRequires = [];
$requires = $devRequires = $removes = [];

foreach ($packages as $package) {
Integra::run('config', '--unset', 'repositories.local:' . $package->name);

if (str_ends_with($package->version, '@dev')) {
if (!str_ends_with($package->version, '@dev')) {
continue;
}

if ($package->version === 'dev-develop@dev') {
$removes[] = $package->name;
} else {
$version = substr($package->version, 0, -4);
$require = $package->name . ':' . $version;

Expand All @@ -62,6 +68,13 @@ public function execute(): bool
}
}

if (
!empty($removes) &&
!Integra::run(...['remove', ...$removes, '--no-update'])
) {
return false;
}

if (
!empty($requires) &&
!Integra::run(...['require', ...$requires, '--no-update'])
Expand All @@ -78,7 +91,8 @@ public function execute(): bool

if (
!empty($requires) ||
!empty($devRequires)
!empty($devRequires) ||
!empty($removes)
) {
Integra::run('update');
} else {
Expand Down

0 comments on commit a0f8662

Please sign in to comment.