joachim
joachim

Reputation: 30761

How can I install a dependency from source with composer?

While I am developing, there are certain dependencies that I want to have as git clones.

(Partly in case I find bugs and want to submit patches, also because when I'm trying to work things out I pepper code with debug statements, and git lets me clean them all up in one go!).

But all the packages that composer downloads are plain files.

How do I get composer to save packages as git clones? Ideally just some of them, not all of them.

Upvotes: 0

Views: 877

Answers (1)

localheinz
localheinz

Reputation: 9582

Install all dependencies from source

Run

$ composer install --prefer-source 

to install all dependencies from source (where available).

See https://getcomposer.org/doc/03-cli.md#install:

--prefer-source: There are two ways of downloading a package: source and dist. For stable versions Composer will use the dist by default. The source is a version control repository. If --prefer-source is enabled, Composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly.

Install selected dependencies from source

Alternatively, configure selected dependencies to be installed from source (or dist) under the preferred-install section in composer.json:

{
    "config": {
        "preferred-install": {
            "foo/bar": "source",
            "bar/baz": "source",
            "*": "dist"
        }
    }
}

See https://getcomposer.org/doc/06-config.md#preferred-install:

Defaults to auto and can be any of source, dist or auto. This option allows you to set the install method Composer will prefer to use. Can optionally be a hash of patterns for more granular install preferences.

Upvotes: 4

Related Questions