Composer Require Local Package

Composer require local package

You can use Composer's repositories feature

https://getcomposer.org/doc/05-repositories.md#path

{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*"
}
}

Instead of using the http format, specify a file path on disk.

Force composer to symlink local package

Why Command 1 downloads package from packagist despite minimum-stability option? Version constraint @dev lets you enforce different stability but it already down to dev with project config.

My best educated guess would be that when no version constraint is provided in composer require sample/package, Composer will still try to find a stable version to install, because of "prefer-stable": true. When you set this option to false (or provide @dev version constraint for the package explicitly) you should see Composer using the latest available version (dev-master on commit bbbbbb).

Will Command 2 create symlink to local package in every case?

Not in every case. You can force Composer to always symlink packages using "symlink": true option.

From https://getcomposer.org/doc/05-repositories.md#path:

The local package will be symlinked if possible, in which case the output in the console will read Symlinked from ../../packages/my-package. If symlinking is not possible the package will be copied. In that case, the console will output Mirrored from ../../packages/my-package.

Instead of default fallback strategy you can force to use symlink with "symlink": true or mirroring with "symlink": false option. Forcing mirroring can be useful when deploying or generating package from a monolithic repository.

Is there a better way than Command 2 to make sure local package gets symlinked?

You should probably avoid dropping "prefer-stable": true from composer.json as this would affect all dependencies.

I'd suggest to just make sure you explicitly require @dev version for sample/package and set "symlink": true for the local repository. This would result in something like:

{
"name": "Some project",
"type": "project",
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [{
"type": "path",
"url": "packages/*/*",
"symlink": true
}],
"require": {
"sample/package": "@dev"
}

}

How to force Composer to download a local package?

"require": {
"my/package": "*"
}

In case of VCS or path repository types, you need to specify version of the package you request. So instead of using *, as you have currently, use @dev:

"require": {
"my/package": "@dev"
}

Composer - installing local packages in development with dependencies error

This issue is described in the composer FAQs.
https://getcomposer.org/doc/faqs/why-can't-composer-load-repositories-recursively.md

In your case this means, that the composer.json of packageC has to include the info where to find the repository for packageA:

[
"name": "vendor/packageC",
"repositories": [
{
"type": "path",
"url": "/vendor/packageB/"
},
{
"type": "path",
"url": "/vendor/packageA/"
}
],
"require": {
"vendor/packageB": "*"
},
"minimum-stability": "dev"
]


Related Topics



Leave a reply



Submit