composer is ignoring installer-paths configuration - php

I'm try using CakePHP for the first time with composer, but I have some problems.
I have this composer.json:
{
"name": "example.com.br",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"config": {
"vendor-dir": "Vendor/"
},
"require": {
"php": ">=5.4",
"pear-cakephp/cakephp": ">=2.4.3",
"cakephp/debug_kit": "2.2.*",
"smottt/wideimage": "dev-master"
},
"extra": {
"installer-paths": {
"app/Plugin/DebugKit": ["cakephp/debug_kit"],
"app/Vendor/Wideimage": ["smottt/wideimage"]
}
}
}
When I run composer install (or update) --prefer-dist, everything works except smottt/wideimage.
This package is being installed in the /Vendor folder instead /app/Vendor, so, installer-paths was ignored.

Of course, what Danack has said is true: the composer-installers plugin only supports a select list of package types.
In response to that, I have written an extension for the composer-installers plugin which allows any arbitrary package type to be handled by the "installer-paths" directive.
Simply require oomphinc/composer-installers-extender in your composer.json and add support for any additional arbitrary package types:
"extra": {
"installer-types": ["library"],
"installer-paths": {
"special/package/": ["my/package"],
"path/to/libraries/{$name}/": ["type:library"]
}
}
For packages that don't specify a type, use the default type library.

From the documentation.
You cannot use this to change the path of any package. This is only
applicable to packages that require composer/installers and use a
custom type that it handles.
From one of the packages you're installing:
{
"name": "smottt/wideimage",
"description": "An open-source PHP library for image manipulation. (With namespaces, PHP 5.3+)",
"homepage": "http://wideimage.sourceforge.net",
"type": "library",
"license": ["GPL-2.0","LGPL-2.1"],
"version": "11.02.19",
"autoload": {
"psr-0" : {
"WideImage" : "lib/"
}
}
}
So basically the package you're trying to install doesn't support custom install paths.

Use option "script" of composer (work only with linux) :
"scripts": {
"post-install-cmd": [
"php -r \"system('mv '.getcwd().'/Vendor/smottt/wideimage '.getcwd().'/Vendor/Wideimage');\""
]
}

Add your custom types to the installer-types:
{
"installer-types": ["library", "myttype-1", "mytype-2"]
}
https://packagist.org/packages/oomphinc/composer-installers-extender

Related

Composer Path Repositories without a package manager

Since composer merge plugin is deprecated and the alternative is use of composer path repositories I found a problem transitioning to the later.
My structure is:
/composer.json
/local/composer.json
Where /composer.json is main composer with all setup and /local/composer.json is a file managing only private repositories.
Contents of each file are:
#/composer.json
{
"name": "main/project",
"type": "project",
"repositories": [
{
"type": "path",
"url": "local"
}
],
"require": {
"sub/project": "dev-main"
},
"extra": {
"installer-paths": {
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
]
}
}
}
#/local/composer.json
{
"name": "sub/project",
"autoload": {},
"repositories": {
"test_repo": {
"type": "git",
"url": "git#github.com:rotari/test_repo.git"
}
},
"require": {
"rotari/test_repo": "dev-main"
}
}
As you can see the plan is simple: main composer requires sub/project and sub/project requires rotari/test_repo. However on install I'm prompted with error
sub/project dev-main requires rotari/test_repo dev-main -> could not be found in any version
Running composer install in /local is a success so there is no problem accessing rotari/test_repo.
Any idea or suggestions how this issue could be solved?
This part from documentation answers my quetion:
https://getcomposer.org/doc/faqs/why-cant-composer-load-repositories-recursively.md
Composer in not able to load repositories recursively.

The requested package ... could not be found in any version

When I want to require my project, the following errors shows up:
The requested package mvc-php/framework could not be found in any version, there may be a typo in the package name.
The "mvc-php/framework" is a git folder.
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
Project i want to require:
{
"name": "mvc-php/framework",
"description": "PHP MVC framework",
"autoload": {
"psr-4": {
"Mvc\\" : "src/"
}
},
"require": {
"php": ">=7.0"
}
}
Instead of just the branch name, you must require branchName#dev
https://getcomposer.org/doc/articles/versions.md#branches
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "master#dev"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
The requested package X/Y could not be found in any version.
The requested package needs to be a git folder with the committed and existing composer.json file. Then to reference specific branch, you need to add the dev- prefix, so dev-master, not master.
Example
Here is the minimal working example:
File: composer.json
{
"require": {
"local/my_package": "dev-master"
},
"repositories": [
{
"packagist.org": false
},
{
"type": "path",
"url": "my_package/"
}
]
}
File: my_package/composer.json
{
"name": "local/my_package",
"require-dev": {
"symfony/console": "*"
}
}
Note: Above file is under local Git repository. To create one, run: git init && git commit -am 'Files'.
Troubleshooting
To troubleshoot the issue, run:
composer install -vvv
Also consider running: composer diagnose to identify common Composer errors.
As this is the first response when searching the error text on Google, I will also put my fix here, despite not being 100% relevant to the OP.
When you are requiring the repo, you need to make sure that your requires statement matches the name of the project in the composer.json of the project.
So if the name had been "name": "mvc-php/app-framework", in the framework project, then the require would need to be:
"require": {
"mvc-php/app-framework": "dev-master"
},
This is more applicable when you are adding a git repo. Especially when forking, as sometimes the git url might be different from the composer.json name.
Additionally (and this is the part relevant to OP), you now need to do dev-branch_name instead of branch_name#dev when requiring. I don't know when this changed, or if the old method is unusable. But this is what the current composer docs now say.
If you want Composer to check out a branch instead of a tag, you need to point it to the branch using the special dev-* prefix
Composer Documentation - Versions and Constraints - Branches
Another Gotcha to be Aware Of:
I changed the name of a package I developed and was just testing a branch on it. I had followed all the correct naming conventions mentioned above but was still getting the given error.
It turns out that for the name change to be picked up, you have to update the package name in composer.json on the main branch of the package repo (Master for me) even if you are not using that branch within your project.
It is important to note that if you do not add your own mirror source to the global variable, an error will occur where the sub-scene is not found.
You can add this in composer.json:
"repositories":[
{
"type":"composer",
"url":"https://packag"
}
],

Version Git Repo for Composer Use - Git/Composer

Scenario
I have a Plugin in PHP that I've written and want to keep it as a private repository. I want to set up the versioning in Git. I know there are tags for this, but don't know how the convention works for Composer.
Current composer.json for my package/plugin:
{
"name": "Test/Upload",
"description": "Useful functions for image uploading.",
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
}
}
Current composer.json for my project to include the above package/plugin:
{
"name": "multistepform",
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}
Currently I have no tags in the package/plugin.
Qs
1) Does Composer require tags in a repository in order for it to use it?
2) How should one tag their private repository for use with Composer?
3) How to include this package in a different project (using the above context)?
Just to add to #tigrang's comment and list out the explicit steps:
add your git repo using "repositories" in your composer.json
tag your package with a version number (I suggest using Semantic versioning, Keep A Changelog and my git plugin git-semver)
VERSION=0.1.0 && git tag ${VERSION} && git push origin ${VERSION}
add your package under require
you can also use "dev-master" in your require if you don't want to add version tags and want to get the latest changes to package when running composer update. This requires setting:
minimum-stability: dev
Final composer.json:
{
"name": "multistepform",
"repositories": [
{
"type": "git",
"url": "https://github.com/Test/Upload.git"
}
],
"require": {
"cakephp/cakephp": "2.6.*",
"cakephp/debug_kit": "2.2.*",
"Test/Upload": "0.1.*"
},
"config": {
"vendor-dir": "Vendor/"
}
}

Composer hook to fix package version

I need to hook in composer installation process to fix versions of second level dependencies of root package. I.e. my package depends on some packages (with correct versions) but these packages depends on other packages and its versions are "wrong". I try to use pre-package-install hook to patch such versions but it is not working for me, code inside Installer::prePackageInstall is not executed.
Root package composer.json looks like this:
{
"name": "***/root-package",
"repositories": [ { "type": "composer", "url": "http://***/packages.json" } ],
"require": {
"***/first-level-dep-1": "dev-release-XX",
"***/first-level-dep-2": "dev-release-XX"
},
"scripts": {
"pre-package-install": [
"root-package\\Installer::prePackageInstall"
]
}
}
First level dependency composer.json looks like this:
{
"name": "***/first-level-dep-1",
"repositories": [ { "type": "composer", "url": "http://***/packages.json" } ],
"require": {
"***/second-level-dep-1": "*", // !!! here is my problem
"***/second-level-dep-2": "*"
}
}
I need to replace * to appropriate version during installation process.
You don't have to "fix" that version. You should simply add that second-level-dep as your own dependency in the correct version, and the case is solved.
If the first-level-dependency requires ANY version of that package, then YOU depending on the correct version will restrict the installable versions to the one you allow.

Composer install path for custom package

I've read other questions about this topic and I just can't seem to get this to work. I'm trying to get a download of cforms as a custom package to install into wp-content/plugins/cforms. I've gotten this to work for the other packages that wpackagist supplies, and even some custom plugins developed in-house.
Here's what I have:
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"require": {
"deliciousdays/cforms": "14.5.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "deliciousdays/cforms",
"version": "14.5.2",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
],
"extra": {
"installer-paths": {
"wp-content/plugins/cforms": ["deliciousdays/cforms"]
}
}
}
It's downloading cforms fine, but it's still putting it into vendor/deliciousdays/cforms when I want it in (obviously) wp-content/plugins/cforms. What am I doing wrong?
Try using this composer.json, it includes Wordpress (v3.9 as of right now).
It uses fancyguy/webroot-installer to install to certain directories.
This file is meant to be in the root wordpress directory. The extra section shows the "webroot-dir" to be "."; This will install into current directory, (Do not use "/" or "./"), if you would like it to install into a specific directory simply change "." to the name of the directory you'd like to install to.
"extra": {
"webroot-dir": ".",
"webroot-package": "wordpress"
}
So after running this file you should have the normal wordpress structure with cforms placed in the wp-content/plugins directory, to install a theme, you can copy the cforms section and change the type to "wordpress-theme" to have it installed into the themes directory.
I'm by no means an expert with composer, but I was able to get this working correctly.
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"repositories": [
{
"type": "composer",
"url": "http://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "wordpress",
"type": "webroot",
"version": "3.9",
"dist": {
"type": "zip",
"url": "https://github.com/WordPress/WordPress/archive/3.9.zip"
}
}
},
{
"type": "package",
"package": {
"name": "cforms",
"type": "wordpress-plugin",
"version": "14.5.2",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
],
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0",
"wordpress": "3.9",
"fancyguy/webroot-installer": "1.0.0",
"wpackagist/wordpress-seo": "*",
"cforms": "14.5.2"
},
"extra": {
"webroot-dir": ".",
"webroot-package": "wordpress"
}
}
Note that using wpackagist, you can view a list of installable plugins/themes at these links:
http://plugins.svn.wordpress.org/
http://themes.svn.wordpress.org/
If you would like to include plugins from the Wordpress Plugin Respository, you can add them in easily. For instance, if you wanted to add the Yoast Wordpress SEO plugin, you would add the following to require (Note that you need to know the slug of the plugin to add it):
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0",
"wordpress": "3.9",
"fancyguy/webroot-installer": "1.0.0",
"wpackagist/wordpress-seo": "*",
"cforms": "14.5.2"
}
Finally figured it out after trying lots of different things. I think I was missing two things:
In the package declaration I changed it to have the "type": "wordpress-plugin", and then in the requires I had to add "composers/installers": "~1.0" like so (also note that the extra was removed entirely):
{
"name": "mycompany/wordpress-install",
"description": "Themes and plugins for our wordpress install.",
"authors": [
{
"name": "Me",
"email": "example#example.net"
}
],
"require": {
"composer/installers": "~1.0.0",
"deliciousdays/cforms": "14.5.2"
},
"repositories": [
{
"type": "package",
"package": {
"name": "deliciousdays/cforms",
"version": "14.5.2",
"type": "wordpress-plugin",
"dist": {
"url": "http://www.deliciousdays.com/download/cforms-v14.5.zip",
"type": "zip"
}
}
}
]
}
I still have been unable to figure out how to get a custom package to install to a directory of my choosing even with the composer/installers require in there. It just seems to ignore everything until I've added a type to the object, and then it forces it to download into the location defined by that type, based on how composer/installers decided to map it.
But I think this will work for now... If anyone knows how to make it download into, say, "myfolder/something/cforms" I'll accept your answer.
it happens I have got an answer for you, because I ran into the same problem. Clearly, there is a big demand now to custom install packages.
The composer/installers ONLY work on defined frameworks and CMS(s), but doesn't work for normal composer packages.
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.json require 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.

Categories