Make a private Package for Composer

Categories: Development

First, what is Composer and what is a Package? Composer is a Dependency manager for PHP. Those Dependencies are what we call Packages that don’t have to be but are usually stored on Packagist.

Making a private Composer Package is really simple, But the first thing that you need to make a new repo for it. Technically this can be a public repo that you don’t load through Packagist but preferably you will be creating a private repo. For work projects I use Github¬†and personal projects, I like to use BitBucket because it’s free.

Here is a sample composer.json file to get you started. Make sure that you have all of your source code located in the /src folder.

{
  "name": "adam/core",
  "description": "Core services used by my Laravel sites.",
  "type": "library",
  "homepage": "https://github.com/adampatterson/app-core",
  "support": {
    "issues": "https://github.com/adampatterson/app-core/issues",
    "source": "https://github.com/adampatterson/app-core"
  },
  "autoload": {
    "psr-4": {
      "Adam\\Core\\": "src/"
    },
    "files": [
      "src/Helpers.php"
    ]
  },
  "authors": [
    {
      "name": "Adam Patterson",
      "email": "[email protected]"
    }
  ]
}

If you would like to future proof your package for Laravel 5.5 auto discovery then add following.

"extra": {
  "laravel": {
    "providers": [
      "Goauto\\Core\\AppServiceProvider"
    ]
  }
}

If you want to use your private package with Laravel then have a look at a previous post that I wrote here on Using a private Composer package with Laravel. Private packages allow me to continue working in a traditional manner without exposing internal code that I wish to keep private.

It also allows me to keep continuity between to private projects without the need for manual migrations between the two.