Search by

wecodemore / composer-linked-packages

gmazzap

Composer plugin to develop packages locally against a project: link packages, update with them into composer.local.lock, and install from it.

Package info

github.com/wecodemore/composer-linked-packages

Type:composer-plugin

pkg:composer/wecodemore/composer-linked-packages

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.0 2026-12-02 23:42 UTC

This package is auto-updated.

Last update: 2026-12-03 08:14:04 UTC


README

Lint Code styles Static analysis Tests

A Composer plugin to solve local development with Composer.

Installation

The recommended way is to install the plugin globally and allow it globally:

composer global config allow-plugins.wecodemore/composer-linked-packages true
composer global require wecodemore/composer-linked-packages

Because both .linked-packages.json and composer.local.lock are meant to be VCS-ignored, when using Git the suggestion is to add them both to the global Git ignore file (by default at ~/.config/git/ignore).

Quick Start

  1. Link the packages you work on
cd ~/code/acme-foo
composer link
  1. Use the linked packages in the project
cd ~/code/my-project # this is the project that requires acme-foo
composer use-links   # this is executed once per project
composer update

Now my-project will install acme-foo, symlinking it from its local path. my-project's composer.json and composer.lock are untouched.

Workflow

  • composer use-links generates or updates a .linked-packages.json, which lists the packages to be linked and their paths.
  • composer update, in the presence of a .linked-packages.json, besides installing the linked packages, generates a composer.local.lock file, so the default composer.lock is not messed with. The first time, composer.local.lock is generated from a copy of composer.lock (if it exists). Subsequent updates work on composer.local.lock, unless .linked-packages.json changes.
  • When composer.local.lock exists, composer install automatically installs from it, without asking for confirmation or offering options. It only emits an info message saying it is using the local lock.
  • composer require / remove keep working on composer.json and composer.lock as usual, and do not update the local lock. This means that after a require/remove, an explicit composer update is required to update both the vendor folder and composer.local.lock. When working with linked packages, composer require <packages> --no-install && composer update is preferable and faster.
  • When a .linked-packages.json exists, there's no flag to ignore linked packages on install or update. Deleting the file is always an option, but for a less permanent approach, it is possible to run use-links --disable. After that, both install and update will behave as if this plugin were not active, ignoring linked packages. Please note that this command does not change the vendor folder content, so an install or update might be needed to reflect the setting.

Commands Reference

link

Adds a package to the list of available links in the global (or provided) local repository. To be executed in the package's root folder (or wherever its composer.json is). Linking an already linked package replaces the link.

composer link [--as-version=VERSION] [--linked-repo-path=DIR]
  • --as-version=VERSION: the version to install the package as, e.g. 1.x-dev or 2.0.x-dev.
  • --linked-repo-path=DIR: the directory holding linked-packages.json. Defaults to the Composer home directory.

unlink

Removes a package from the list of available links in the global (or provided) local repository. To be executed in the package's root folder (or wherever its composer.json is).

composer unlink [--linked-repo-path=DIR]

use-links

Makes the project in the current directory use the linked packages by writing .linked-packages.json. Running it again replaces the file, unless --add is used.

composer use-links [--linked-repo-path=DIR]|[--add] [PACKAGES...]
composer use-links --disable|--enable
composer use-links --purge-links [--linked-repo-path=DIR]
  • PACKAGES: only uses the linked packages matching these names. Wildcards are supported. Without them, all the linked packages are used. It fails if no linked package matches.
  • --linked-repo-path=DIR: uses the links stored in a directory other than the Composer home directory.
  • --add can be used to add new linked packages instead of replacing the file content on each run. This is not compatible with --linked-repo-path, which always replaces the file.
  • --disable can be used as the only flag to temporarily disable linked packages for the project. That is equivalent to deleting the .linked-packages.json file. Note that the command does not update the vendor folder content. Also note that, when disabled, a new use-links call re-creates the .linked-packages.json file (unless --add is used), but as disabled. Only an explicit --enable call (or a manual edit) can re-enable a disabled configuration.
  • --enable is used to enable linked packages after a --disable.
  • --purge-links removes from the global (or provided via --linked-repo-path) repository the links whose directory does not exist anymore, for example because the package was deleted or moved without running unlink. It lists them and asks for confirmation, defaulting to yes. In non-interactive mode (-n) it removes them without asking. It can only be combined with --linked-repo-path, and it does not need a project, so it can run from any directory.

require-link

Adds entries to config.linked-packages.require to add or override a linked-package requirement. Similarly to how require updates composer.lock, it will update composer.local.lock and will update dependencies after updating the requirement, unless the --no-install or --no-update flags are used. It requires linked packages to be in use, that is, a .linked-packages.json file must exist (it is created by use-links).

composer require-link PACKAGE[:VERSION] \
  [--no-update] [--no-install] \
  [--prefer-stable] [--prefer-lowest] [--minimal-changes] \
  [--update-no-dev] [--update-with-dependencies|-w] [--update-with-all-dependencies|-W] \
  [--ignore-platform-reqs] [--ignore-platform-req] [--no-progress] [--sort-packages] \
  [--optimize-autoloader|-o] [--classmap-authoritative|-a] \
  [--apcu-autoloader] [--apcu-autoloader-prefix] \
  [--no-audit] [--audit-format] [--no-security-blocking] [--no-blocking] [--no-cooldown]
  • --sort-packages will sort packages in config.linked-packages.require and will not touch packages in top-level require or require-dev.

For all other flags, please refer to the composer require documentation.

remove-link

Removes entries from config.linked-packages.require. Similarly to how remove updates composer.lock, it will update composer.local.lock and will update dependencies after updating the requirement, unless the --no-install or --no-update flags are used. It requires linked packages to be in use, that is, a .linked-packages.json file must exist (it is created by use-links).

composer remove-link PACKAGE \
  [--no-update] [--no-install] \
  [--update-no-dev] [--update-with-dependencies|-w] [--update-with-all-dependencies|-W] \
  [--ignore-platform-reqs] [--ignore-platform-req] [--minimal-changes] \
  [--optimize-autoloader|-o] [--classmap-authoritative|-a] \
  [--apcu-autoloader] [--apcu-autoloader-prefix] \
  [--no-audit] [--audit-format] [--no-security-blocking] [--no-blocking] [--no-cooldown] \
  [--no-progress] [--sort-packages]

For all flags, please refer to the composer remove documentation.

Learn more

Filter linked packages

When calling composer use-links, all the packages required in the project that also exist as linked packages on the current system will be pulled from their local paths. Chances are we are interested in linking only a subset of those. This is done by passing the wanted packages as arguments to use-links. The Composer convention for filtering packages applies here: we can list explicit package names or use wildcards. For example:

composer use-links "foo/bar" "acme/*"

Version resolution

By default, the only thing the plugin does with regard to resolving linked packages is force dev stability for them. For example, in a project with "minimum-stability": "stable", a dependency required with ^1 would normally install only stable versions. If that package is linked, this plugin will, at runtime, set its stability to dev, which is equivalent to requiring it with ^1@dev. This allows installing the linked package from a local in-development branch, which is the entire point of linked packages. The overall minimum-stability must still be satisfied, including by the linked packages' transitive dependencies.

That said, when linking a package, it is possible to override the version Composer "sees" for it. This is done via the --as-version flag of the link command. For example:

composer link --as-version="1.x-dev"

With the above, Composer will consider the code in the path as representing that version, regardless of the package's VCS references or its branch-alias configuration.

Alternative repository location

By default, when linking a package, the information about the link is stored in a file located in the Composer global home. Via the --linked-repo-path flag of the link command, it is possible to use an alternative location. This means that multiple "linked packages repositories" can exist on a local system. For example, we might have two repositories, for personal and company projects, or even one repository per project.

When an alternative location is used to link packages, the same flag must be used for use-links or the consuming package will keep searching for linked packages in the global repository.

Combined with the --as-version flag mentioned above, this means we can have the same source code listed in multiple local repositories, with different versions.

Requiring packages only when linked

At times, it might be desirable to require a package only when working locally, or to require a package that is not released at all, and so can't be required in composer.json. This plugin makes this possible via configuration in composer.json, for example:

{
    "config": {
        "linked": {
            "require": {
                "acme/debug-tools": "~1.0.0",
                "acme/unreleased-plugin": "dev-master"
            }
        }
    }
}

With the configuration above, a regular update or install will not install the two packages. They will be installed only when a .linked-packages.json is there. Not only that, these packages must be linked, even if they are available on Packagist or in any other repository for the project.

To add and remove these requirements, the plugin provides the require-link and remove-link commands, which work similarly to Composer's require and remove, including most of their flags. A notable difference is that if no version constraint is provided, require-link, unlike require, uses * as the version constraint.

Copy instead of symlink

By default, Composer symlinks path repositories in the vendor folder, and falls back to copying if symlinking is not possible. This plugin uses path repositories for linked packages and lets Composer use its default mechanism.

However, when manually declaring a path repository, Composer supports an options.symlink setting to disable symlinking and force copying. This plugin exposes the config.linked-packages.symlink setting for the same purpose. This can be a boolean applying to all linked packages, or a map of package names (wildcards supported) to booleans. In the latter case, packages not listed get the default behavior (symlink if possible, copy otherwise).

Gotchas

  • This plugin uses the Composer locker to write the lock, so when the config.lock setting is set to false, Composer will install linked packages but will not generate a composer.local.lock. In the absence of the local lock, composer install will not use the linked packages. In short, with config.lock = false, installing linked packages always requires update.
  • The plugin uses config for its own settings because extra, which is what plugins should use, is included in the composer.lock content hash. This means that if extra were used, other users of a committed composer.lock would likely see a "lock file not in sync with composer.json" warning, even though nothing is actually out of sync, considering they don't have linked packages.
  • When the directory of a linked package is deleted or moved without running unlink, its link stays in the repository. Projects using links keep working as long as they don't require that package: its directory is only read when the package is needed. When it is required, update fails, saying the directory does not exist. Link the package again from its new location, or remove the links of missing directories with composer use-links --purge-links.
  • The --bump-after-update flag and the bump-after-update config are ignored when updating with linked packages, because we don't want changes to the local lock file to have any effect on composer.json. The bump command still works, of course, but it bumps requirements in the default composer.json based on the default composer.lock, and when using linked packages, a subsequent composer update might be needed for the installed packages to reflect the changes.

Development

composer install
composer qa

Requirements

  • Composer 2.9 or newer
  • PHP 7.4 or newer

License

MIT, see LICENSE.