drupol / composer-local-repo-plugin
A plugin for Composer which provides a command to create local Composer repository for your projects.
Fund package maintenance!
drupol
Installs: 280
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 2
Type:composer-plugin
Requires
- php: ^8.0 || ^8.1
- composer-plugin-api: ^2
Requires (Dev)
- composer/composer: ^2.6
This package is auto-updated.
Last update: 2023-10-10 08:52:20 UTC
README
This plugin, built for Composer, facilitates the creation of
a local composer
type repository (refer to
documentation) from an existing package.
The repository type composer
is identical to the format used by
Packagist. It uses a specific structure, featuring a
manifest file named packages.json
and a unique directory structure. Each
version of the package within the repository has its own corresponding source.
Created with the goal of installing a PHP package in a repeatable manner, this plugin eliminates the need for network access post repository creation.
The plugin is currently used within Nix. More information can be found in the corresponding PR, marking the project's inception.
This project has been heavily inspired of
fossar/composition-c4
from Jan Tojnar.
Requirements
- Composer 2
Installation
Install the plugin globally once:
composer global require loophp/composer-local-repo-plugin
Usage
- Navigate to the package directory, or use the
--working-dir
option. - Make sure the
composer.json
andcomposer.lock
files are present. - Generate the local repository using the command:
composer build-local-repo /path/to/local/repository
. This will create a localcomposer
repository in the specified directory and generate a manifest filepackages.json
in the same location. Use the-r
or-m
options to generate only a repository or a manifest file, respectively. For more details, refer to the command help:composer build-local-repo --help
. - The combination of the package sources and the local repository we just
created are now strictly enough to build the
vendor
directory necessary for the package to work. Therefore at this stage, we can disable the network as no further network access is required or you can use the environment variableCOMPOSER_DISABLE_NETWORK
set to1
to do so. - Disable Packagist by entering the command:
composer config repo.packagist false
. - Integrate the newly created local
composer
repository into thecomposer.json
file using the command:composer config repo.local composer file:///path/to/local/reposity/packages.json
. - Refresh the lock file using the command:
composer update --lock --no-install --no-scripts --no-plugins --no-interaction
. - Finally, install the package by entering the command:
composer install
.
In Nix
The plugin is used in Nix to build Composer based PHP packages. The combination of the source package and the local repository built with this plugin is unique and Nix uses that for ensuring reproducibility.
Note
By default, Composer will create symbolic links to the packages, if you want to
copy the packages instead, set the environment variable
COMPOSER_MIRROR_PATH_REPOS
to 1