-
-
Notifications
You must be signed in to change notification settings - Fork 167
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
Plugin version outside of the composer.json #5764
Plugin version outside of the composer.json #5764
Conversation
Two thoughts maybe:
|
Mainly messing up the version in the So changing the version later on in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your thoughts and the resulting order make sense to me. I had thought about index.php
as the final fallback if the dynamic Composer lookup also failed, but I came to the conclusion that using the explicitly defined versions first is easier to understand and debug. So I think your code is the right way to go. I had also thought about whether another option is worth it, but maybe we could actually recommend this in the future instead of adding the version to composer.json
(which can indeed cause problems if there is a mismatch).
Only needs tests IMO.
I think there was also the idea in discord somehwere to maybe have a Kirby specific plugin file just for holding any metadata. Not sure if something likes this would be necesseray at all. Just wanted to throw this in as well. I can try to add some tests for this. Something around these lines?
|
What's about instead of putting it in the extension array, it's rather a new argument in the plugin call? |
Not really convinced about that TBH. We need to keep it optional, so with positional arguments, the only place to put it would be at the end where it looks weird after the |
I thought about that as well. And agree with @lukasbestle that having it directly in the App::plugin('lukaskleinschmidt/snippet-controller', [
'options' => [
'name' => fn (string $name) => $name . '.controller',
],
'components' => [
'snippet' => function (App $kirby, $name, array $data = [], bool $slots = false) {
$data = snippet_controller($name, $data);
return $kirby->nativeComponent('snippet')(
$kirby,
$name,
$data,
$slots,
);
}
],
], [
'version' => '2.1.0',
'description' => 'A plugin to use controllers with snippets.',
]); |
At the moment, all metadata we need has a direct match to keys of
Thanks 💛 We already have separate tests for kirby/tests/Cms/Plugins/PluginTest.php Line 645 in 8bb22df
|
Hm. I'm always a fan of planning ahead, but TBH it looks a bit too over-engineered to me because it is so far beyond what we currently need. |
Then something like above would just mimic the composer file. So probably not worth it. And the Edit: |
I was thinking less of one third parameter with additional metadata but making use of named arguments. That way we would still add it as third parameter for backwards compatibility but in all the docs etc could make it look like this: Kirby::plugin(
name: 'my/plugin',
version: '1.0.0'
extends: [...],
license: 'paid'
); |
I like that a lot because it moves us into safer, more future-proof code and we can still keep it backwards compatible |
Should I give this a try or is this something you would like to implement separately? |
I think it makes sense to already implement it like that. Of course only the |
My take on "version as new property": v4/develop...v4/enhancement/plugin-version Still not fully sure that composer should overrule the version number that explicitly gets passed as argument to the plugin. |
Does it? I think the current order is |
Yes but that's what I mean: shouldn't the version that we explicitly pass to Kirby's method to register a plugin be the truth above all? |
There are three ways now the version gets resolved. Right now:
In my opinion if a In the end the version shown should reflect the one that composer intended to install I guess.
public function version(): string|null
{
$composerName = $this->info()['name'] ?? null;
$version = $this->info()['version'] ?? null;
try {
// if plugin doesn't have version key in composer.json file
// try to get version from "vendor/composer/installed.php"
$version ??= InstalledVersions::getPrettyVersion($composerName);
} catch (Throwable) {
return null;
}
$version ??= $this->version;
// …
} Or even check the |
I honestly disagree. If I tell Kirby the version of the plugin by passing it explicitly to the register method, that one should have the authority to- not some other version Kirby can find elsewhere. Those are great as fallbacks if I don't tell Kirby the version. But if I explicitly do, it's weird to ignore it and also hard to understand and debug for developers. |
I think this priority idea will cause confusion. I have another idea. IMHO metadata data should be retrieved from either composer.json or index.php. If a plugin does not have composer.json, it should look at the third parameter in index.php for metadata data ( |
But why is an arbitrary file like composer.json seen as more important than what the developer explicitly registers the plugin as. We don't do that for other things like the name, do we? |
I think composer.json is not an arbitrary file, it's a standard. Almost all plugins are in git. I don't think it makes much sense to look at both file (composer.json and index.php). I'm completely open to the idea of including metadata data only from the plugin registration method. Then we can do it like this; K4: New registryPlugin::register(
name: 'my/plugin',
version: '1.0.0'
extends: [...],
license: 'paid'
); Even with class (that's would awesome) class MyPlugin implements Plugin
{
public function name(): string
{
return 'My plugin';
}
public function version(): string|float
{
return 1.0;
}
public function description(): string
{
return 'My description';
}
public function extends(): array
{
return [];
}
}
K5: deprecate
|
As a note from the outside: please keep this simple and don't apply a cascade of rules to extract the version number. Noone will understand that. One place of truth would be very helpful, including this in the Kirby plugin registry sounds like a very good idea especially as Composer discourages the usage of the Plugin developers will always make mistakes and forget to update their version numbers in some places. But having only one place to look into will make things easier. |
I still think that VSC tagged version should have precendence over a potential wrong (because forgot to update) version in any file. If the version in the In a perfect world the version specified in
So having that kind of order would allow for composer installs to still show the correct (tagged) version. And custom installs via git or copy paste can simply download the latest version from git (when I almost certainly will forget to update that version in the |
I agree with Nils. This discussion clearly shows that we are adding quite a bit of complexity here. I like Ahmet's idea to migrate to a new system entirely. Maybe like:
|
Am I correct that Composer reads the current version number from Git tags? So there would be two places that matter: the plugin version definition and the Git tags. Maybe you could add a Kirby CLI command to update both at the same time? Might reduce manual oversights on the developer side. Could also be a validator: "Your version number and Git tags do not match" … |
I think so too. About adding a command to the CLI: The CLI would actually have a much easier time to update |
Not being able to keep the version in the Otherwise sticking with the |
Bringing this back to life: I think the way that @lukasbestle proposed #5764 (comment) makes a lot of sense. Yes, there could still be two sources of truth (git tag that ends up in So even if not ideal, I think it's the most sensible way forward. If we don't want it inside |
An alternative could be to have a simple text file with the version number (like The order in my comment above would still apply: First the Composer-installed version if available, otherwise the static version file. The version in |
I don't have any preference whether in |
We already do: Line 304 in 2965c31
The only thing that would change is the order and the source of secondary information.
Yes, but we shouldn't rush it either as we are introducing a new concept here that needs to work for everyone. |
I think the current PR might still tick all the boxes for fixing the issue for now.
I get that there are plans to overhaul the plugin system, but I think that could be a separate issue from the current one. The PR is backwards compatible and non breaking if not used. The current plugin register flow will stay the same. And the change would not hinder any future changes to the plugin system down the road (at least in my opinion). |
The issue is that plugin devs will use the new feature, which will prevent us from removing it again later without a breaking change. And having multiple competing ways is not great either. So I think it's important to find a good solution. |
My point being that if you overhaul the whole plugin system at some point it will probably be a breaking change no matter what. So in my opinion no harm in removing this version feature again (from the extends) and put it somewhere else. Probably depends more on the when then. I get that it does not make sense to introduce this feature and remove it again just a few months later. |
One additional thing that occurred to me today was that this "intermediate" way of adding the version could also easily be backported to Kirby v3. |
I'm not aware of plans to overhaul the plugin system, especially in this area. |
Trying to summarize a possible way forward:
My current favorite is option ii (separate file in the plugin root), although I'm not sure about the name. |
@lukasbestle do you think the regex for the version bump would be so problematic if the version is stored in the index.php? I'm not a huge fan of adding more config files. It's not like we don't have enough *.config,json .ignoreblabla etc. in modern web dev projects already :) |
You are right, simplicity-wise it would indeed be best to have the version in |
@lukasbestle I think we should no longer keep this PR unmerged though if the key is the easiest and most usable option for plugin devs who don't use composer. I'm sure we can find a solution for cli commands later to do this reliably. |
If it is, then I fully agree. Maybe we should post this suggestion on Discord and get feedback from other plugin devs. Could avoid having to backtrack and find yet another solution after releasing this. |
Hey @lukaskleinschmidt, I just really wanted to thank you for your contribution and more importantly for your patience with us :) I think the discussion on Discord really led to a good result and we are taking over from here: #6337 |
This PR …
Adds the option to specify the plugin
version
in your plugin definition outside of thecomposer.json
.You can still just use the
composer.json
. This PR just adds an additional way to specifiy the plugin version.I usually create my composer plugins without adding the
version
key.The version detection from Kirby works as long as my plugins are installed via composer.
But adding it as a git submodule or simply copy pasting it does not work.
The reason why I avoid using the
version
key in my composer packages:https://getcomposer.org/doc/04-schema.md#version
TLDR: Version of the docs:
Not a must have and I also understand arguments that prefer using solely the
composer.json
for such things but I think the solution might fit the bill to make both worlds happy.Fixes
lukaskleinschmidt/kirby-snippet-controller#2
Breaking changes
Ready?
For review team