Edit in GitHubLog an issue

Package a component

The Adobe Commerce and Magento Open Source applications use Composer packages to distribute, install, and upgrade components in an application instance.

To package a component, you must:

  • Create a Composer file (composer.json).
  • Register the component using registration.php
  • Package and publish your component.

Create a Composer file#

The composer.json file defines the name, requirements, version, and other basic information about the component. This file must be placed in the root directory of the module.

The composer.json uses Composer's generic schema, with the following restrictions:

ElementDescription
nameA fully-qualified component name, in the format <vendor-name>/<component-name>. All letters must be in lowercase. Use dashes in the <component-name> to separate words. Themes must use the format <vendor-name>/theme-<area>-<theme-name>.
typeFor modules, this value must be set to magento2-module. Other possible types are metapackage, magento2-theme, and magento2-language.
autoloadSpecify necessary information to be loaded, such as registration.php. For more information, see Autoloading from Composer.

The following table discusses the component types that Commerce Marketplace supports. The composer type column in the following table specifies the value of the type field you must add to composer.json for that type of component.

Friendly namecomposer.json typeDescription
MetapackagemetapackageTechnically, a Composer package type, not a Magento component type. A metapackage consists of only a composer.json file that specifies a list of components and their dependencies. For example, both Magento Open Source and Adobe Commerce are metapackages.
Modulemagento2-moduleCode that modifies application behavior. You can upload a single module to the Commerce Marketplace or your module can be dependent on some parent package.
Thememagento2-themeCode that modifies the look and feel of the storefront or Admin.
Language packagemagento2-languageTranslations for the storefront or Admin.
Librarymagento2-librarySupport for libraries located in lib/internal instead of in the vendor directory.
Componentmagento2-componentThe package formed of the files that must be located in root (.htaccess, etc). This includes dev/tests and setup as well for now.

Using metapackages#

Metapackages allow you to group an extension that consists of multiple packages into a cohesive unit. This works exactly as described in standard composer.json documentation. If you have an extension that uses more than one package you must use a metapackage as the root package. Otherwise you should not use metapackage. A metapackage that you submit to Commerce Marketplace should be a .zip file containing only the metapackage composer.json file.

Metapackage example#

The following example is a composer.json for a metapackage:

Copied to your clipboard
1
2{
3 "name": "magento/product-community-edition",
4 "description": "A sample metapackage",
5 "version": "2.0.0",
6 "type": "metapackage",
7 "require": {
8 "php": "~7.2.0||~7.3.0",
9 "zendframework/zend-stdlib": "~2.4.6",
10 "zendframework/zend-code": "~2.4.6",
11 "zendframework/zend-server": "~2.4.6",
12 "zendframework/zend-soap": "~2.4.6",
13 "zendframework/zend-uri": "~2.4.6",
14 "zendframework/zend-validator": "~2.4.6",
15 "zendframework/zend-crypt": "~2.4.6",
16 "zendframework/zend-console": "~2.4.6",
17 "zendframework/zend-modulemanager": "~2.4.6",
18 "zendframework/zend-mvc": "~2.4.6",
19 "zendframework/zend-text": "~2.4.6",
20 "zendframework/zend-i18n": "~2.4.6",
21 "ext-ctype": "*",
22 "ext-gd": "*",
23 "ext-spl": "*",
24 "ext-dom": "*",
25 "ext-simplexml": "*",
26 "ext-mcrypt": "*",
27 "ext-hash": "*",
28 "ext-curl": "*",
29 "ext-iconv": "*",
30 "ext-intl": "*",
31 "ext-xsl": "*",
32 "ext-mbstring": "*",
33 "ext-openssl": "*"
34 },
35 "license": [
36 "OSL-3.0",
37 "AFL-3.0"
38 ]
39}
40

Sample composer.json file#

The following example is a composer.json file for a module:

Copied to your clipboard
1{
2 "name": "magento/sample-module-newpage",
3 "description": "A module that creates a new page",
4 "type": "magento2-module",
5 "version": "1.0.0",
6 "license": [
7 "OSL-3.0",
8 "AFL-3.0"
9 ],
10 "require": {
11 "php": "~7.2.0||~7.3.0",
12 "magento/framework": "~100.0.4"
13 },
14 "autoload": {
15 "files": [ "registration.php" ],
16 "psr-4": {
17 "Magento\\SampleNewPage\\": ""
18 }
19 }
20}
21

Package and publish your extension#

Create a package of your extension by performing a zip operation on the directory with your extension (excluding unnecessary directories). For example:

Copied to your clipboard
zip -r vendor-name_package-name-1.0.0.zip package-path/ -x 'package-path/.git/*'

Use alphanumeric characters for the package filename with dashes to separate words. Do not use whitespaces.

The application can retrieve your extension package from any valid GitHub URL.

Hosting on GitHub and Packagist#

Prerequisite: Git must be set up on your machine.

  1. Navigate to your component directory, with the composer.json file in the root, and make it a new Git repository. See the GitHub documentation for details.

  2. When you have committed and pushed your component to your GitHub repository, you can either:

    • Use Composer to refer to it directly, or

    • Use the following steps to refer to the package through Packagist.

      1. Register an account at packagist.org.
      2. Click the Submit Package button and paste your GitHub repository link. Packagist automatically gathers the information from the component's composer.json file and link it to the GitHub repository, allowing you to reference the package as vendor/module without any additional repository information, because this is required solely using GitHub.

Hosting on a private repository#

  1. Set up your own Composer packaging repository using a system such as Satis or Private Packagist.

  2. Create the package in a way similar to the described above.

  3. Submit/register the package on your own repository. For example, it can be hosted as a reference to a code repository or submitted as a zip-archive.

  4. To use the private packaging repository in a project, add the following to your composer.json file:

    Copied to your clipboard
    1{
    2 "repositories": [
    3 {
    4 "type": "composer",
    5 "url": [repository url here]
    6 }
    7 ]
    8}

All packages on the private repository can now be referenced within the require field.

Refer to the official documentation for more details on how to configure your project to use Private Packagist.

Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.