Tower
Tower

Reputation: 102925

Custom package installation path in Composer?

Is it possible to specify that our own packages in Composer are installed to a different folder than vendor/. I know that I can specify a folder where all packages are installed, but that's not what I want. I want third party packages to end up in vendor/ and our own within src/ folder.

Is this possible? We are using Symfony 2 if that matters.

Upvotes: 7

Views: 5348

Answers (3)

mina.nsami
mina.nsami

Reputation: 431

I have implemented this composer plugin to install packages into user (custom) defined folders you can just include it in your composer.json, follow the example and tell me if you have more questions :)

https://github.com/mnsami/composer-custom-directory-installer

composer-custom-directory-installer

A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

This is not another composer-installer library for supporting non-composer package types i.e. application .. etc. This is only to add the flexability of installing composer packages outside the vendor folder. This package only supports composer package types,

https://getcomposer.org/doc/04-schema.md#type

The type of the package. It defaults to library.

Package types are used for custom installation logic. If you have a package that needs some special logic, you can define a custom type. This could be a symfony-bundle, a wordpress-plugin or a typo3-module. These types will all be specific to certain projects, and they will need to provide an installer capable of installing packages of that type.

How to use

  • Include the composer plugin into your composer.json require section::
"require":{
    "php": ">=5.3",
    "mnsami/composer-custom-directory-installer": "1.1.*",
    "monolog/monolog": "*"
  }
  • In the extra section define the custom directory you want to the package to be installed in::
  "extra":{
    "installer-paths":{
      "./monolog/": ["monolog/monolog"]
    }

by adding the installer-paths part, you are telling composer to install the monolog package inside the monolog folder in your root directory.

  • As an added new feature, we have added more flexibility in defining your download directory same like the composer/installers, in other words you can use variables like {$vendor} and {$name} in your installer-path section:
"extra": {
    "installer-paths": {
        "./customlibs/{$vendor}/db/{$name}": ["doctrine/orm"]
    }
}

the above will manage to install the doctrine/orm package in the root folder of your project, under customlibs.

Note

Composer type: project is not supported in this installer, as packages with type project only make sense to be used with application shells like symfony/framework-standard-edition, to be required by another package.

Upvotes: 5

Bartosz Pachołek
Bartosz Pachołek

Reputation: 1318

If still a case consider testing my library (based on a plugin by mina.nsami ):

https://github.com/ideaconnect/composer-custom-directory

Allows custom paths:

"extra":{
    "installer-paths":{
      "./monolog/": ["monolog/monolog"]
}

and even dynamic name replacements:

"extra": {
    "installer-paths": {
        "./packages/{$name}": ["sourcepackage/package_A","sourcepackage/package_B","sourcepackage/package_B"]
    }
},

and with flags chain which allows a simple manipulation of the variables on runtime:

Currently supported flags are:

F - capitalizes first letter.
P - changes all entries of a _ or - followed by a character to only that character, capitalized.

Upvotes: 0

l3l0
l3l0

Reputation: 3393

You should probably make own installer: http://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-path-for-my-framework.md and use own installer-paths

Upvotes: 6

Related Questions