Skip to content

Instantly share code, notes, and snippets.

@pwillis-els
Created January 13, 2021 02:55
Show Gist options
  • Save pwillis-els/2dae3e54c363c6f6342342764615ec77 to your computer and use it in GitHub Desktop.
Save pwillis-els/2dae3e54c363c6f6342342764615ec77 to your computer and use it in GitHub Desktop.
Composer: Add a package repository for code that doesn't live in a repository to your composer.json

If you need to track a package with Composer but it doesn't exist in a repository, you can still manage it with Composer. Simply create a custom repository of type 'package', add it to your required packages, and proceed as normal.

  1. Open your composer.json and add a a block to the 'repositories' array like the following.
{
  "repositories": [
    {
      "type": "package",
      "package": {
        "name": "magic-fields-team/magic-fields-2",
        "version": "2.3.3.1",
        "dist": {
          "url": "https://github.com/magic-fields-team/Magic-Fields-2/archive/2.3.3.1.zip",
          "type": "zip"
        },
        "source": {
          "url": "https://github.com/magic-fields-team/Magic-Fields-2.git",
          "type": "git",
          "reference": "2.3.3.1"
        }
      }
    }
  ]
}
  1. Add the new repository to your 'require' section.
{
  "require": {
    "magic-fields-team/magic-fields-2": "2.3.3.1"
  }
}
  1. Install as normal with Composer.
$ composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 4 updates, 0 removals
  - Locking magic-fields-team/magic-fields-2 (2.3.3.1)
  - Upgrading roave/security-advisories (dev-master d596191 => dev-master a2c04f8)
  - Upgrading symfony/polyfill-ctype (v1.18.1 => v1.22.0)
  - Upgrading symfony/polyfill-mbstring (v1.20.0 => v1.22.0)
  - Upgrading symfony/polyfill-php80 (v1.20.0 => v1.22.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 4 updates, 0 removals
  - Downloading magic-fields-team/magic-fields-2 (2.3.3.1)
  - Downloading symfony/polyfill-php80 (v1.22.0)
  - Downloading symfony/polyfill-mbstring (v1.22.0)
  - Downloading symfony/polyfill-ctype (v1.22.0)
  - Installing magic-fields-team/magic-fields-2 (2.3.3.1): Extracting archive
  - Upgrading roave/security-advisories (dev-master d596191 => dev-master a2c04f8)
  - Upgrading symfony/polyfill-php80 (v1.20.0 => v1.22.0): Extracting archive
  - Upgrading symfony/polyfill-mbstring (v1.20.0 => v1.22.0): Extracting archive
  - Upgrading symfony/polyfill-ctype (v1.18.1 => v1.22.0): Extracting archive
Generating optimized autoload files
11 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment