This composer plugin allows you to share your selected packages between your projects by creating symlinks

Overview

Composer - Shared Package Plugin

Code Climate Scrutinizer Code Quality Build Status Test Coverage

This composer plugin allows you to share your selected packages between your projects by creating symlinks.
All shared packages will be in the same dedicated directory for all of your projects (ordered by versions) and a symlink directory container will be created on your projects (vendor-shared by default).

This plugin will improve your work process to avoid to work into the vendor folder or to avoid to force you to push your package to work/test it with another project.

How it works

A shared package is flagged by two ways :

  • By setting the root project composer.json extra configuration package-list with the selected package name (works only with the >= 2.x version).
  • By setting the composer.json package type to shared-package (the <= 1.x version way, still works on 2.x).

If this composer plugin is required in the root project composer.json : the package will be downloaded in the dedicated dependencies directory that you provided and a symlink will be created in the project vendor-shared directory (by default).

This plugin allows you to work with many versions at the same time for a package by creating a sub-directory named by the version of your package (dev-master, dev-develop, 1.0.x-dev, etc).

A packages.json file is created in the dependencies sources directory to know which projects use a package version and be able to ask you if you want to delete the version directory during the Composer uninstall process, if no project seems to use it.

Installation

Step 1 : edit your root composer.json

Add, to your root project composer.json, this require (in dev only) :

// composer.json (project)
{
    "require-dev": {
        "letudiant/composer-shared-package-plugin": "~2.0"
    }
}

Note: this plugin works fine in production mode, but it has been created for development purpose.

Step 2 : set your dependencies vendor path

Your dependencies vendor path is the path where all your shared packages will be downloaded. This path should be at the same level (or above) of all your projects.
If you IDE doesn't handle symlinks, you may use this directory to work on your development packages. Otherwise, you'll be able to work directly on your symlinks with modern IDE (PHP Storm, SublimeText, ...).

Add, to your root project composer.json, this extra configuration :

// composer.json
{
    "extra": {
        "shared-package": {
            "vendor-dir": "/path/to/your/dependencies/directory"
        }
    }
}

Note: you can pass a relative path (foo/bar) or absolute path (starts with "/" : /foo/bar).
If your path is relative, your symlink directory base path will be relative too.

Note for VM users: you can manually override the symlink directory base path with the configuration symlink-base-path if your host machine dependencies directory path is not the same as your guest machine, see all available configurations page for more information.

Step 3 : select your shared packages

Add, in your own package composer.json, which one you want to share between your projects :

// composer.json
{
    "extra": {
        "shared-package": {
            "vendor-dir": "/path/to/your/dependencies/directory",
            "package-list": [
                "foo/bar",
                "bar/*"
            ]
        }
    }
}

Note: as you can see, you can pass a wild card * to the package name. So, in this example, all packages that starts with bar/ will be shared. Note²: you can set a package name to * to share all packages.

Step 4 : (re)install your dependencies

If you already have installed your project dependencies, you have to fully delete your vendor/ directory and your composer.lock file.
Run the composer install command.

You should see a new vendor-shared folder with all shared packages symlinks.

Step 5 : play with require-dev :

You can avoid to have two project composer.json by setting your require dependencies on a stable version (~x.x.x) and work on dev environement with a your working in progress version by setting, in your require-dev with your development version, like this :

// composer.json (project)
{
    "require": {
        "acme/foo-bar": "~1.0"
    },
    "require-dev": {
        "acme/foo-bar": "dev-develop as 1.0"
    }
}

Thanks to that, you will be able to work with development version in dev environement and have stable version in production.

Note: the alias * as 1.0 may avoid a Composer version solver error, because this behavior is not handled by default.
Note²: Composer has not been created to work with development version/branch, so when you run a composer install, the current package branch HEAD commit will flagged in your composer.lock.
So, the next time you'll run this command on dev environement, and if you already have a composer.lock file, Composer will checkout the flagged commit and not the new HEAD (if you made new commit) of your branch : your shared packages won't be up to date. To avoid this behavior, please read "How to use - Update only your own packages".

Structure generation example

Here, a complete example. Our own shared package is called acme/foo-bar.

// composer.json (project)
{
    "require": {
        "letudiant/composer-shared-package-plugin": "~1.0",
        "symfony/console": "~2.6",
        "acme/foo-bar": "~1.0"
    },
    "require-dev": {
        "acme/foo-bar": "dev-develop as 1.0"
    },
    "extra": {
        "shared-package": {
            "vendor-dir": "../composer-dependencies",
            "package-list": [
                "acme/foo-bar"
            ]
        }
    }
}

With this composer.json, the structure will look like :

|-- packages.json
|-- composer-dependencies/
|   +-- acme/
|       +-- foo-bar/
|           +-- dev-develop/
|               |-- src/
|               |-- composer.json
|           +-- ...
+-- project/
+-- src/
+-- vendor/
|   +-- symfony/
|       +-- console/
|           +-- ...
|-- vendor-shared/
|   +-- acme/
|       +-- foo-bar/ (symlink to "../../../composer-dependencies/acme/foo-bar/dev-develop/")
+-- ...

How to use (and known issues)

This plugin implement a new behavior which is not handled by Composer, so there are a few known issues. Here, the way to fix them :

All available configurations

See the all available configurations documentation.

Reporting an issue or a feature request

Feel free to open an issue, fork this project or suggest an awesome new feature in the issue tracker.

ChangeLog

3.1.0

  • Implement environment variables, as suggested by babwar, to allow to override the default configuration in composer.json file - More information.

3.0.0 :

  • Fix the BC update in Composer with getInstallPath method.

2.0.0 :

  • Implement the possibility to choice each package you want to share with the configuration package-list - More information.
  • Delete conditions on stable/dev version. Now a shared package is shared on stable version too (tag).

1.2.0 :

  • Rewrite installer, the installer choice process is now in a dedicated class.
  • Implement new symlink-enabled configuration to allow to enable/disable the symlink creation process - More information.

1.1.0 :

  • Implement new symlink-base-path configuration, as suggested by philbates35, to allow VM users to override the symlink directory base path, see issue - More information.

Credit

L'Étudiant

This plugin project is maintained by L'Etudiant.
The Composer project is maintained by Nils Adermann & Jordi Boggiano, see https://github.com/composer/composer#authors for more information.

License

This plugin is licensed under MIT license, see the LICENSE file for more information.
You can also read the Composer license for more information.

You might also like...
A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

This composer plugin is a temporary implementation of using symbolic links to local packages as dependencies to allow a parallel work process

Composer symlinker A Composer plugin to install packages as local symbolic links. This plugin is a temporary implementation of using symbolic links to

Ied plugin composer - Inspired Plugin Composer: Create, publish and edit plugins from within Textpattern CMS.

ied_plugin_composer Create, publish and edit plugins from within Textpattern CMS. Creates a new page under the Extensions tab where you can edit and e

Opinionated version of Wikimedia composer-merge-plugin to work in pair with Bamarni composer-bin-plugin.

Composer Inheritance Plugin Opinionated version of Wikimedia composer-merge-plugin to work in pair with bamarni/composer-bin-plugin. Usage If you are

Library for check dependency between modules inside projects

PHP Dependency analyzer PHP DA is tool for check and support dependencies inside your project clear. For example: You have project with 3 root namespa

Composer registry manager that help to easily switch to the composer repository you want

CRM - Composer Registry Manager Composer Registry Manager can help you easily and quickly switch between different composer repositories. 简体中文 Install

Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion.
Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion.

Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion. HTTP API, HTTPs support, webhook handler, scheduled builds, Slack and HipChat integration.

Private Composer registry for private PHP packages on AWS Serverless
Private Composer registry for private PHP packages on AWS Serverless

Tug Tug is a Composer private registry for private PHP packages installable with Composer (1 and 2). The main idea of this project is to have an inter

A workbench for developing Composer packages.

studio Installation Usage Workflow Command Reference License Contributing For enterprise Develop your Composer libraries with style. This package make

Comments
  • Fixed file structure example vendor directory name

    Fixed file structure example vendor directory name

    I'm kind of new to this project so i'm sorry if this is incorrect. I think the 'dependencies" folder within the example directory structure is supposed to be named 'composer-dependencies'?

    opened by carlos-reynosa 1
  • Binaries support

    Binaries support

    This is a pull request regarding Provide binary support issue#20

    This is a first draft. I wanted to get your opinion first before I want to do the following:

    • implement an option in the config to enable this functionality ('install-binaries'), false by default.
    • update the documentation to explain the new functionality

    What it currently does is check if the package has a binary and no vendor folder is installed yet. Then create a new composer with current shared-package settings and run it within the package. This way the autoload will be created so binaries can always be executed.

    Please let me know what you think...

    Best regards, Alex

    opened by ghost 0
  • Global composer support

    Global composer support

    This is a feature request to enable global usage of the plugin. With this you can install the plugin globally and it will display the following behavior:

    • if plugin is installed in local project global shared-package settings will not be merged
    • if plugin is not installed in local project global shared-package settings will be merged
    • if plugin is installed in local project and no vendor-dir is defined the plugin will not activate
    • if plugin is installed in global but not local and no vendor-dir is defined the plugin will not activate

    The last two changes in behavior just create more flexibility for the future. We should not fail the install when the plugin is not able to perform.

    For this the tests should be adapted to the new behavior.

    opened by ghost 0
  • add disable-on-windows option

    add disable-on-windows option

    Hello, first thank for that great tool, I would like to purpose you this option for easily resolve symlink problem when working with co-workers which are working on windows.

    opened by devthejo 2
Owner
L'Etudiant
L'Etudiant
Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins.

Imposter Plugin Composer plugin that wraps all composer vendor packages inside your own namespace. Intended for WordPress plugins. Built with ♥ by Typ

Typist Tech 127 Dec 17, 2022
Modularize extensions using symlinks. Voted #1 Magento tool by @WebShopApps!

modman (Module Manager) Developing extensions for software that doesn't allow you to separate your files from core files, and keeping that extension u

Colin Mollenhour 731 Dec 29, 2022
With the phpBB extension "Hide for Guest" you can hidden selected areas for guests and bots.

phpBB-Hide for Guest Description With "Hide for guest" selected areas are hidden for guests and bots. Requirements php 7.3 or higher phpBB 3.2.0 or hi

Thorsten 2 Dec 15, 2022
Share content between your websites.

Distributor Distributor is a WordPress plugin that makes it easy to distribute and reuse content across your websites — whether in a single multisite

10up 504 Jan 3, 2023
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.

Kirby 3 Many To Many Field This plugin allows you to create many-to-many relationships between pages in Kirby.

Jonas Holfeld 41 Nov 19, 2022
Composer Repository Manager for selling Magento 2 extension and offering composer installation for ordered packages.

Magento 2 Composer Repository Credits We got inspired by https://github.com/Genmato. Composer Repository for Magento 2 This extension works as a Magen

EAdesign 18 Dec 16, 2021
YCOM Impersonate. Login as selected YCOM user 🧙‍♂️in frontend.

YCOM Impersonate Login as selected YCOM user in frontend. Features: Backend users with admin rights or YCOM[] rights, can be automatically logged in v

Friends Of REDAXO 17 Sep 12, 2022
Envbar allows you to differentiate between environments by adding a custom colored bar above the top navigation.

Envbar Envbar allows you to differentiate between environments by adding a custom colored bar above the top navigation. This should help backend users

Magenizr 6 Oct 7, 2022