Using Someone’s Module in your File

Assuming a module developer has setup a composer.json file, and you can access their source code repository, you’ll be able to use it in your project.

If the module developer has listed their package in packagist, the only thing you’ll need to add to your project’s composer.json file is the following

require:{
    //...
    "pulsestorm/module-name":"dev-master"
    //...
}

 

The above code says “add the version of pulsestorm/module-name that’s in themaster branch of the repository. If you want a specific version of the module, swap that version out for dev-master. Composer package versions are equivalent to git tags. i.e. a branch tagged with a version number becomes that version. Also, if the package is listed in packagist, its listing page should have the correct require syntax. You can also read more about composer versioning in composer’s module.

If a module developer has not listed their package in packagist, you’ll still be able to install it via composer. The only difference is you’ll need to add the module developer’s GitHub repository as a packagist repository.

For example, if you wanted to add Fooman’s same invoice number extension to your project, first you’d add the composer package to your composer.jsonfile.

require:{
    //...
    "fooman/sameorderinvoicenumber-m2":"2.0.1"
    //...
}

 

However, since there’s no package on packagist with the fooman/sameorderinvoicenumber-m2 package name, you also need to add the GitHub repository as packagist repository

require:{
    //...
    "fooman/sameorderinvoicenumber-m2":"2.0.1"
    //...
},
"repositories": {
    "fooman/sameorderinvoicenumber-m2":{
        "type": "git",
        "url": "git@github.com:fooman/sameorderinvoicenumber-m2.git"
    }
}

 

In case it’s not clear from context, the fooman/sameorderinvoicenumber-m2name comes from the composer.json file, the 2.01 version comes from the GitHub repository’s tags, and the url comes from the git ssh URL included on the GitHub repository’s main page.

Comment

There is no comment on this post. Be the first one.

Leave a comment