Distributing via Packagist

Packagist is a free online repository service for Composer packages. We can use it to easily distribute our free Magento modules. The fact that Packagist is a default Composer repository, makes it the de facto repository for any Composer user. This is why having our free Magento modules available via Packagist is a preferred way of distribution.

Pushing our Magento module to Packagist is quite easy. Assuming we have our account created, we should start by clicking on the Submit button, which will land us on the following screen:

We need to provide a link to our Git repository here, and click the Check button, followed by the Submit button, if the valid repository was found. This should create our package, as per the following screen:

The Packagist says that our created package is now available for use via the composer require magelicious/module-royal-trek command. However, running this command now would be likely to give us the following error:

[InvalidArgumentException] 
Could not find a matching version of package magelicious/module-royal-trek. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable).

Notice the dev-master label on our Packagist screen. Our branches automatically appear as dev versions in Packagist. Therefore, we can use the composer require magelicious/module-royal-trek:dev-master command to fetch the package. To change that, we need to specifically tag our git commits, as follows:

git add .
git commit -a -m 'The RoyalTrek shipping module, first version.'
git tag 1.0.0
git push origin 1.0.0

Once we have done that, we can go back to the Packagist package screen and hit the Update button. This should now show our 1.0.0 version:

If we specify a version when requiring the package, Composer fetches the latest tagged version from the master. For example, composer require magelicious/module-royal-trek:2.4.x takes the latest 2.4 tagged version from the master branch.

When it comes to versioning, it is worth noting that setup_version found in module.xml, and version found in composer.json are two different types of versioning. Magento refers to them as marketing version and composer version. Marketing version might be thought of as something the merchant interacts with, while Composer version is something that developers interact with. The Magento_Catalog module, for example, uses the 2.2.4 marketing version for marketing, whereas its Composer version is 102.0.4. This is not to say that we cannot use the same versioning for both, as long as we remember that the setup_version, found in module.xml, is what drives our setup scripts.

Distributing future new versions of our Magelicious_RoyalTrek module would, therefore, come down to:

  1. Bumping up the setup_version found in module.xml
  2. Bumping up the version found in composer.json
  3. Addressing any necessary Magento setup scripts
  4. Committing our changes to Git, with proper version tagging
  5. Making sure the Update is triggered on the Packagist screen of our module edit screen
Using the Packagist's service hook we can ensure that our package will always be updated automatically. See https://packagist.org/about#how-to-update-packages for more information.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.9.7