Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect dev for install command #1413

Merged
merged 3 commits into from
Mar 11, 2024
Merged

Conversation

chr-hertel
Copy link
Contributor

Fixes #1412

$command = 'require';

/** @var Version $version */
$version = $this->getVersions()->first();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure which version to use ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view_package template already receive a version variable (which can be null). this is the version that should be used for the install command IMO (which would be done by keeping the command in the template as it is done right now, but adding a {% if version and version.hasDevTag %} --dev{% endif %})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, i know that moving it from the template to PHP feels like the more complex solution at first, but i tend to kill every if in twig that i can replace with sth that is easily unit tested.

but sure, that's a debatable design decision

Copy link
Contributor

@stof stof Jan 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Twig already has the right version to use passed to it by the controller. The Package entity does not have it. So moving this to the entity itself looks like the bad decision IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't aware of that controller code to sort out the most relevant version - thanks for that pointer!
will give it another thought later 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this function should just accept a version as argument, and then the template can pass it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy solution, true - done

@@ -635,6 +635,13 @@ public function getTags(): Collection
return $this->tags;
}

public function hasDevTag(): bool
{
return [] !== array_filter($this->getTags()->toArray(), static function (Tag $tag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looping over the tags and stopping when we find a dev tag would be more efficient than filtering the whole list all the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

$command = 'require';

/** @var Version $version */
$version = $this->getVersions()->first();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view_package template already receive a version variable (which can be null). this is the version that should be used for the install command IMO (which would be done by keeping the command in the template as it is done right now, but adding a {% if version and version.hasDevTag %} --dev{% endif %})

@Seldaek Seldaek merged commit cf52e7a into composer:main Mar 11, 2024
3 checks passed
@Seldaek
Copy link
Member

Seldaek commented Mar 11, 2024

Thanks!

@@ -46,7 +46,7 @@

<div class="row">
<div class="col-md-8">
<p class="requireme"><i class="glyphicon glyphicon-save"></i> <input type="text" readonly="readonly" value="composer {% if package.type == 'project' %}create-project{% else %}require{% endif %} {{ "#{package.vendor}/#{package.packageName}" }}" /></p>
<p class="requireme"><i class="glyphicon glyphicon-save"></i> <input type="text" readonly="readonly" value="{{ package.installCommand(expandedVersion) }}" /></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this use version instead of expandedVersion to be consistent with the sidebar showing the support action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes true it should be version, I'll fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect 'dev' keyword in packagist UI to show composer require --dev
3 participants