-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Change config command to allow empty name when adding new repositories #12388
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
Conversation
Seldaek
left a comment
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.
Looks good to me, very solid PR with good test coverage and docs, thanks!
FYI the reason for the regex mess is that this way we can edit json files without force-reformatting them, which allows us to keep diffs to a minimum.. It's a bit of a "small nice idea grown into a monstrosity" but it works for 99% of things and the code is there now so might as well keep it..
|
One more note, I think the main downside of this is that it doesn't let you unset them without knowing which index it is present at anymore.. But I guess if that is important to people they can still use named repos then. |
|
@Seldaek I guessed so, that this must be the reason for this to exist. At first I thought it has better control over "empty-object here but empty list over there" as this sometimes arise in composer files. Thank you for the explanation. Good point regarding the removal. We could have a "host" / "url" option for removal but then the arguments start to become optional or similar shenanigans :D I saw that the phpstan is pointing some things out. I will have a look at this later. Does it make sense to rebase to fix the CHANGELOG conflict or will you solve it eventually when it is merged as there will always be a conflict? |
|
Feel free to rebase anyway to get the latest build fixes from main, BUT the changelog I usually do myself at release time so I'd say you can remove it completely that's fine by me. |
|
@Seldaek I have been thinking about this whole
|
|
@dzuelke yeah I think that all sounds great, it would mirror a bit the git remote command I guess (+ ordering..). Definitely would be more sensible than adding more hacks on top of the existing. But it also sounds like quite a bit of work.. |
|
I admit that I don't really like how |
…ries configuration as either list or associative array
… list (instead of associative array) and look-up entries by name as a lineitem name attribute Solves composer#9918
d5ea9dc to
95a53d5
Compare
|
@dzuelke @Seldaek I rewrote it to integrate a new command. I hopefully added enough test coverage (which is right now mostly happy-path). I also had to adjust the json schema and force "old" structures to the new one. I tried to only make it happen, when adding new repositories so it does not annoy too much. I made sure the name attribute for repositories is now always on top. This should make sure, they are sorted correctly so @localheinz does not have to sort it afterwards. I am very glad, that there already was a list-item-approach to disable packagist. Docs where AI powered, so if you want it to have more detailed or rewritten, I am happy to do that. I am not sure about the php8.5 test. I do not see it directly why my changes would've bricked it. The pull request is now ready to review. |
|
Thanks @JoshuaBehrens again, this is great work. I did tweak some things in the few commits above but I think now we're in a pretty good spot with this! Only two areas of improvement left that I see:
"repositories": [{
"name": "foo",
"type": "path",
"url": "./"
},{
"packagist.org": false
}]to: "repositories": [
{
"name": "foo",
"type": "path",
"url": "./"
}, {
"packagist.org": false
}
]I think it would be more readable and more obvious that there is an array of objects?
|
|
@Seldaek Thank you for the guidance and review. Happy to contribute :) I can add canonical, only, exclude as options. I mean it is not that much different to the URL. I understand and also like the syntax with the |
|
@JoshuaBehrens if you want to do canonical/only/exclude feel free put please work on a new PR based on this one, as I'd rather get this one merged already. The newline stuff I am trying to look at it for a bit and if that doesn't work I'll skip, it's not that important. Edit: OK not worth the hassle I think :D |
|
Thank you for merging :) |
|
Very nice work @JoshuaBehrens and @Seldaek! Should the tests for the old object key syntax not maybe remain? They all got changed to the new Might also be useful to have tests for the "evil" case of old object key syntax but {
"repositories": {
"foo": {
"name": "bar",
"type": "composer",
"url": "https://packagist.org/"
}
}
} |
|
That sounds sensible.. @JoshuaBehrens if you have time for this be my guest 😇 |
Due to change in Composer: 1. composer/composer#12388 2. outlandishideas/wpackagist#548
Based on [my suggestions and concept for repository-related configuration updates](composer/composer#12388 (comment)), Composer 2.9 will have a [new command to modify repositories](composer/composer@f414237) in `composer.json`, and to make that possible, `repositories` entries can now have a `name` field. The struct and serde definitions already permit this, but we are adding explicit tests for it here, as well as checks to reject invalid combinations (object notation together with names, as also disallowed by Composer's schema for `composer.json`) during deserialization. GUS-W-20086506
|
Thank you for working on this! 🙏🏻 |
|
@Kocal you are welcome :) |
|
After this version reach my CI I start getting tons of warning output from composer 2.9: I believe the below config is not that uncommon and the json error message are not as clear as they should (if you don't already know what & where to look for).
{
"repositories": {
"wpengine/advanced-custom-fields-pro": {
"type": "composer",
"url": "https://connect.advancedcustomfields.com"
},
"freemius": {
"type": "composer",
"url": "https://composer.freemius.com/packages.json?authorization=Basic+...."
},
"dearflip/dearflip": {
"name": "dearflip/dearflip",
"type": "package",
"package": {
"name": "dearflip/dearflip",
"version": "2.3.30",
"type": "wordpress-plugin",
"dist": {
"url": "https://foo.gitlab.io/paid-plugins/tarballs/dflip-2.3.30.zip",
"type": "zip"
}
}
},
"gravityforms/gravityforms": {
"name": "gravityforms/gravityforms",
"type": "package",
"package": {
"name": "gravityforms/gravityforms",
"version": "2.8.16",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
"url": "https://www.gravityhelp.com/wp-content/plugins/gravitymanager/api.php?op=get_plugin&slug=gravityforms&key=...."
},
"require": {
"composer/installers": "^1.8|^2.1",
"gotoandplay/gravityforms-composer-installer": "^2.3"
}
}
},
"wpackagist": {
"type": "composer",
"url": "https://wpackagist.org"
}
}
} |
|
@drzraf the issue there is the |
|
Yeah you ideall convert repos to an array, remove the keys and move them to name properties then you can use the new repo command with it all |
When working with third-party package repositories I learned to just execute a command like
$ composer config repositories.shopware-packages '{"type": "composer", "url": "https://packages.shopware.com"}'and have access to new packages. I once was confused, that everyone is writing repositories as lists and after that one has a diff like that
{ - "repositories": [ + "repositories": { - { + "shopware-packages": { + "type": "composer", + "url": "https://packages.shopware.com" + }, + "0": { "type": "path", "url": "custom/static-plugins/*" } - ] + } }Back then I was not really questioning it. Just different styles of writing it. Now as of today I am aware of more PHP internals like arrays have three indices. Therefore I better understand warnings like these in the docs
Now coming back to this topic after some years I decided to tackle this and later noticed there is an open discussion in #9918 and the comments in https://stackoverflow.com/a/32814046 . I tried to follow up on the expected results of the discussions and have this pull request as a suggestion.
With this change you are now able to run
and get this diff instead
{ "repositories": [ + { + "type": "composer", + "url": "https://packages.shopware.com" + }, { "type": "path", "url": "custom/static-plugins/*" } ] }I do not see this a breaking change as the command line would not allow the command to work like this. Therefore this likely can just be a feature.
I hope this pull request meets requirements you expect for pull requests. I tried to update everything one might need:
If you need something else just have it part of the review.
Sidenote: at first I tried to implement the logic for the list item to subnode but noticed, that there are so many more logic branches and changes to the regex that it became less easy to read. I noticed that the regex solution must have a reason to exist so I rather not have it a breaking change and started to introduce a new method. I did not try to make a solution that can convert list to assoc and assoc to list. At this point I just expected the fallback logic to make things work right.
Fixes #9918