composer-normalize: Make "paths that should not be sorted" configurable
Some elements of composer.json
are highly sensitive to order, such as extra.patches
with https://github.com/cweagans/composer-patches, which applies patches in the order specified and can therefore fail if it changes. See another example #699. I need a way to exclude arbitrary paths from sorting. I see that the current exclusions are hardcoded in \Ergebnis\Json\Normalizer\Vendor\Composer\ConfigHashNormalizer::PROPERTY_PATHS_THAT_SHOULD_NOT_BE_SORTED
. I would like this value to be configurable like the other options. I could take a stab at a PR. Alternatively, a few specific additions to the current hardcoded list would temporarily unblock my customers. I would gladly send a PR for that, too.
-
extra.installer-paths
(https://github.com/ergebnis/json-normalizer/pull/777) -
extra.patches
(https://github.com/ergebnis/json-normalizer/pull/780) -
scripts.auto-scripts
(https://github.com/ergebnis/json-normalizer/pull/776)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 25 (13 by maintainers)
Yes, it’s safe to sort children of
extra.patches
, but not their children. That’s to say that grandchildren ofextra.patches
should retain their order.I also am experiencing problems with this in the “scripts” section - I define various commands to be run via the install and update hooks (via the “auto-scripts” block shown below), but these commands need to be in a specific order, whereas when normalized they are placed in alphabetical order which is not what we want!
When normalized changes the order and becomes:
Hello,
About composer-patches, a workaround is to use put number at the beginning of the description like in
Best regards,
@localheinz Which property paths should be added to the hardcoded exclusions? Off the top of my head I know of the following order-dependent paths:
extra.patches
is the one specifically blocking my customers.extra.installer-paths
was mentioned in https://github.com/ergebnis/composer-normalize/issues/699.repositories
already seems to be excluded.Hi,
@localheinz, about https://github.com/ergebnis/composer-normalize/issues/704#issuecomment-1346841515, I confirm, direct children of
extra.patches
can be sorted (and I like to sort it) but not their own children.So ok with you comment result.
extra
is arbitrary data that can be “virtually anything”. I don’t think a generic tool can make assumptions about its structure. At most, sort direct subkeys.Regarding
scripts
, my own use case is like:Scripts are listed in logical blocks (build actions first, linters last). Linters are shown in order of importance/preference for the project. Each linter displays lint command first, fix command second. Order conveys information, I’m not fond of having it discarded blindly.
On the other side,
composer list
itself couldn’t care less and alphabetises scripts nonetheless.Would some generic opt-in/opt-out setting be a solution? Can it be flexible enough without adding too much complexity?
@benr77
Fixing
scripts.auto-scripts
with https://github.com/ergebnis/json-normalizer/pull/776.Hi,
@localheinz don’t blame yourself, this tool is amazing! Thanks for providing it in open source with free usage possible!
Thanks for your efforts - it really is appreciated a lot!
One point to consider - I see in the PR you are referring to
auto-scripts
but this is just what I have called the group - I think you can call it anything (this is just a Symfony convention IIRC).In the
scripts
block at least, it is OK to sort the first level of children, but anything past that should not be sorted.Cheers!
@benr77 Working on this!
Also using https://github.com/cweagans/composer-patches and experiencing the same issue: patches are re-ordered, but some of them need to be applied in a specific order. I’m currently working around this issue by defining my patches in a separate file (explained @ https://github.com/cweagans/composer-patches#using-an-external-patch-file).