So, I wanted to easily see which version of the Magento Framework belongs to which major version of the Magento distribution. For instance, Magento version 2.3.2 ships with the package
magento/framework version 102.0.2. How to put a script together that finds this version information automatically? Let's use
jq for that.
Using the proper versions in composer
When releasing my Magento extensions, I always make sure that my modules have their dependencies mapped in both
composer.json. And because every Magento extension is always using specific features from the Magento Framework, the package
magento/framework should be listed there as a dependency too.
For instance, if my module is using ViewModels, I should know that these ViewModels were introduced in Magento 2.2.0 and actually improved in Magento 2.2.1. And Magento 2.2.1 ships with
magento/framework version 101.0.1. All minor and patch versions after 101.0.1 include this new feature, so does major 102. A nice way of summarizing this in semantic versioning would be
When dealing with versions this way, knowing which composer package was shipped with which Magento main release is vital.
Fetching composer information
All of this information is contained within the composer packages of Magento. While the source of Magento can be found on GitHub, composer packages are released via the Magento Marketplace (
https://repo.magento.com) so that we can collect all information using a single CURL request. The Magento Marketplace is protected by a HTTP Basic Authentication login, which we can add to a
curl command like the following:
USERNAME=your-marketplace-username PASSWORD=your-marketplace-password curl --basic --user $USERNAME:$PASSWORD https://repo.magento.com/packages.json > magento-packages.json
magento-packages.json now contains a huge JSON blob with information on Magento core packages and third party extensions (that you purchased, free or commercial). Let's play with it.
jq is a light-weight JSON processor that you can use to collect information from the command-line. For instance, we can pipe the downloaded JSON to
jq to list all of the available packages:
cat magento-packages.json | jq '.packages | keys'
Or, how many packages are contained within the Magento Marketplace by default:
cat magento-packages.json | jq '.packages | keys' | wc
Which is 299 minus 2 (the brackets of the
keys array) is 297.
Which Magento version matches which package?
We can now also use
jq to search for specific information within the JSON structure. For instance, the following oneliner fetches the specific package
magento/product-community-edition version 2.2.9 and returns the value of the requirement
cat magento-packages.json | jq '.packages."magento/product-community-edition"."2.2.9".require."magento/framework"'
Obviously, much more is possible with
jq. It supports regular expressions, simple
if statements, different parsers. It definitely is a handy tool when working with composer JSON blobs, Magento Marketplace being one of them.