Coming up: 17 Oct - Magento 2 Merchant training

Yireo - Trainings & extensions

Open main menu

4 October 2019

CLI access to Magento Marketplace details

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 module.xml and 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 ^101.0.1|^101.1|^102.0.

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:

bash USERNAME=your-marketplace-username PASSWORD=your-marketplace-password curl --basic --user $USERNAME:$PASSWORD https://repo.magento.com/packages.json > magento-packages.json

The file 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.

Meet jq

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:

bash cat magento-packages.json | jq '.packages | keys'

Or, how many packages are contained within the Magento Marketplace by default:

bash 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 magento/framework:

bash cat magento-packages.json | jq '.packages."magento/product-community-edition"."2.2.9".require."magento/framework"'

Answer: 101.0.9.

More

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.

Written on 4 October 2019 by Jisse Reitsma

About the author

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and two times Magento Master. His passion is for technology and open source. And he loves talking as well.

Looking for a training in-house?

Let's get to it!

Proud member of

  Latest blog

Extensions

Legal information

Other Yireo sites

Get Social

About Yireo