How to Make a Package for the Magento Marketplace in Magento 2
Denis Saltanakhmedov Avatar

If you developed some Magento 2 module and you want to publish the module on the Magento Marketplace, you need to prepare a package with the module first.
In the post, we do not describe how to publish the module on the Magento Marketplace only how to prepare the ultimate package version and validate it.

So, first, you need to make sure that the module works correctly and has some particular logic, it’s working, the structure of the module is correct and the module does not have a hard dependency especially with other none-Magento modules. Leveraging the PhpStorm AI plugin can assist in identifying structural issues and ensuring code quality before packaging your module.

Also, the module should have the valid composer.json

For example:

{
  "name": "atwix/test-package",
  "description": "Test atwix module for Magento 2",
  "require-dev": {
    "php": "~5.6.0|~7.0.0|7.0.2|7.0.4|~7.0.6|~7.1.0"
  },
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "autoload": {
    "files": [ "registration.php" ],
    "psr-4": {
      "Atwix\\TestPackage\\": ""
    }
  }
}

In the example above we specify the version of PHP, but you can describe your requirements. Also, it’s a good way to have the same versions in composer.json and module.xml.

The package is essentially a zip file, but it should be created using the command:

zip -r atwix-test_package-1.0.0.zip test-package/ -x 'test-package/.git/*'

Where atwix-test_package-1.0.0.zip is the name of the package:

“atwix” – vendor name
“test_package” – module name
“1.0.0” – version of the package, we recommend using the same version in composer.json

In the example of zip command, we run the command from the vendor folder as it’s considered to be more convenient. Also, our recommendation is to temporary rename folder of the module to have the same name as the package.

After running the command, you should have a zip file containing your module; this is your package.

Before uploading the package to the Magento 2 Marketplace, you can validate the structure of the package.

Go to repo marketplace tools and download the validate script validate_m2_package.php, the script generates a CodeSniffer report of the module.

Place the script in the same directory and run the command:

php validate_m2_package.php path_to_atwix-test_package-1.0.0.zip

We recommend putting the script in the same directory with the package.

The tool does not show any success if the debug option is not set. If the script finds any errors it will report about it.

To set the debug option use next command:

php validate_m2_package.php -d path_to_atwix-test_package-1.0.0.zip

Therefore, if there are no errors, the package is ready to be published on the Magento 2 Marketplace.
But please, note that the validation tool only checks the structure of the package.
After sending the package to the Magento 2 Marketplace the package will be checked in the different tests like code review, manual testing, installation to the different Magento version. If the package has any recommendations or remarks, the package will be returned for another revision.

Thank you for reading this one and your time.
If you have any questions, feel free to add your comments down below.