Skip to content Skip to sidebar Skip to footer

How To Get Multiple Vendor Directories With Composer?

My project relies on ZF and on a JS library. I wanted to be able to deploy the ZF library to the normal location (vendor/zendframework/zendframework1) but then deploy my JS library

Solution 1:

Composer is meant to manage your PHP dependencies, not JS.

Also, it only supports one vendor folder.

You might follow the way Symfony bundles use:

  • install everything in vendor
  • link (or copy) public assets to a public directory as part of your deployment process

In my opinion it's safer than installing something in a public folder (as long as you copy/link public part of a library only).

Solution 2:

I came across the symlink idea but I wanted to automate this instead of manually creating the symlinks. I was going to create a composer script to create the symlink. I then found that symlinks on Windows and *nix need to be created in different ways which made this solution get messier by the second. I found that in the composer docs they talk about this same type of issue on the custom installers page and say that to solve this to create your own custom installer.

Solution 3:

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.jsonrequire 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.

Solution 4:

By default, Composer reads composer.json schema. But, it can also use a different file. For instance, you can have zendframework.json and my-library.json.

In the zendframework.json, you can define:

"config":{"vendor-dir":"zendframework/vendor"},

In the my-library.json, you can define:

"config":{"vendor-dir":"my-library/vendor"},

Finally, you can update the libraries in this way:

COMPOSER=zendframework.json composer update
COMPOSER=my-library.json composer update

This is a simple idea. The benefit is that you solve the issue without third-party tools.

Post a Comment for "How To Get Multiple Vendor Directories With Composer?"