changing name of project in composer.json in fork/branch impossible? - php

i currently ran into a problem with renaming a project in composer.json.
the previos status was like the following:
{
"name": "old/name",
"license": "Business",
"type": "library",
"description": "description",
"autoload": {},
"minimum-stability":"dev",
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"sensio/generator-bundle": "~2.5",
"phpunit/phpunit": "~4.6",
"mockery/mockery": "0.9.4",
"leaphub/phpcs-symfony2-standard": "~2.0.0"
},
"scripts": {
},
"extra": {
},
"branch-alias": {
"dev-master": "2.6-dev",
}
}
}
now i need to change this to
{
"name": "new/name",
"license": "Business",
"type": "library",
"description": "description",
....
}
therefore i created a new branch, changed the information, created a branch-alias to reference it in the target-project.
...
"repositories": [
{
"type": "vcs",
"url": "git#github.com:matthias-chlechowitz/forked-repo.git"
}
],
"require": {
"new/name":"dev-matthias/rewrite-branchname"
}
...
but when running composer update to fetch the updated version, the old version with the previous project name is fetched and the following error message appears:
Problem 1
- The requested package new/name could not be found in any version, there may be a typo in the package name.
so it's not possible to rename projects within one repo or even forks? or am i missing a major part?
best regards,
matthias

thank you for your answer, but referencing a new branch was not the problem (which was working perfectly fine). The problem was really changing the name of the project (name-property in the composer.json).
According to Christophe Coevoet [1], composer always fetches the name from the master branch, so my changes in forked or derived branches doesn't affect the outcome.
Best regards,
Matthias
[1] https://github.com/composer/composer/issues/4677

Related

Composer does not respect installer-paths

Here is the scenario:
I have two projects driven by composer. The first one looks like this:
{
"name": "myusername/composer_test",
"description": "Composer project for CircleK Drupal 8",
"type": "project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Name Surname",
"role": "webdeveloper"
}
],
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"php": ">=5.6",
"composer/installers": "^1.2",
"drupal-composer/drupal-scaffold": "^2.5",
"drupal/core": "^8.7.0",
"vlucas/phpdotenv": "^2.4",
"webflo/drupal-finder": "^1.0.0",
"webmozart/path-util": "^2.3",
"zaporylie/composer-drupal-optimizations": "^1.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"]
}
}
}
Second one requires the first one and it's pretty straight forward:
{
"name": "user/site",
"description": "Composer for Site",
"type": "project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Name Surname",
"role": "webdeveloper"
}
],
"repositories": [
{
"type": "git",
"url": "git#github.com:myusername/composer_test.git"
},
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"myusername/composer_test": "dev-drupal_only"
},
"minimum-stability": "dev",
"prefer-stable": true
}
As you can see the first one defines where drupal core should be placed at by defining installer-paths. It turns out that when I run composer install just for the first composer.json file drupal core ends up in ./web directory as should, however when I run composer install for second file it does download every package from first composer.json just fine, but drupal core ends up in main directory instead of ./web. I know I can put installer-paths into the last composer file and overwrite it, but that's not the point. I want first file to define where stuff should be place at.
The extra settings only work for the root package. Consider user/site requiring 2 different packages that both specifiy different installer paths. Which one should composer use and how should it know? By ignoring those settings, unless they are specified in your root composer.json, composer circumvents any surprises/problems.
There is a way around this, you can create a post-install script that determines the correct path for you, e.g. by checking if myusername/composer_test is installed and the variable is set. This is a bit similar to how Symfony's Install-Script in the SensioDistributionBundle used to do it. It provides a fallback to determine the right directory to use based on configs and folder structure (due to changes in how the default directory structure looks at ~2.8, e.g. moving app/console to bin/console).
You could write your own install script that inspects the installed composer packages. The downside is, that just like you now have to specify the extra config in your second composer.json, you will have to specify the install scripts, plus you have to write the install script itself. So it might be a lot of extra work without gaining a lot from it.

Composer Install Package Dependencies

I have created a custom package which is set up in a GIT repo. Composer is successfully pulling the files into a directory in the vendor directory, but I need to pull in the nested dependencies, which I cannot find the answer on how to make this happy.
This the Composer file for the main site pulling the package:
{
"name": "development/project",
"type" : "project",
"repositories": [
{
"type":"composer",
"url":"https://wpackagist.org"
},
{
"type": "package",
"package": {
"name": "development/package",
"version": "0.0.1",
"source": {
"type": "git",
"url": "https://developer#bitbucket.org/development/package.git",
"reference" : "v0.0.1"
}
}
},
],
"require": {
"php": ">=5.4",
"composer/installers": "~1.0",
},
"require-dev": {
"development/package": "~0.0"
}
}
And here is the Composer file local to the package itself:
{
"name": "development/package",
"type" : "project",
"require": {
"php": ">=5.4",
"composer/installers": "~1.0"
},
"require": {
"ellislab/codeigniter": "~3.0"
},
}
So what I would like to have happen is that when I run Composer on the main site it pulls in the 'development/package' (which it is currently doing), but also pull in the package dependencies 'ellislab/codeigniter'. Thanks for any help on this.
You have invalid composer json in your local package, it should be like this (no double require node):
{
"name": "development/package",
"type" : "project",
"require": {
"php": ">=5.4",
"composer/installers": "~1.0",
"ellislab/codeigniter": "~3.0"
}
}
Composer automatically pulls all packages defined in require node of root package, and in require node of each dependent packages, including your ellislab/codeigniter in your development/package.

How to add the component's version with specific tag from GitHub to PHP project using Composer

I have GitHub repo tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001
with example PHP component. This component does not have itself composer.json file.
My objective is getting this component to my project using project's composer.json.
I follow the Julien's answer to Contributing to open source bundles from vendor directory?
I wrote composer.json that describes component as "package"
{
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-master",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "master"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-master"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}
It is installing the last commit from master branch.
$ php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001 (dev-master master)
Cloning master
Writing lock file
Generating autoload files
My repo history gitk all branches history
fc70af [branch:master, no tag]
|
|
| 9941b7 [branch:trial, tag:"v0.0.2"]
| /
|/
c2849e [branch:master, tag:"v0.1"]
|
|
6f8ff7 [branch:master, tag:"v0.0.1"]
My composer.json file is downloading the last commit from master branch. But i want to install some previous versions of component or trial versions.
How to install
The last commit from trial branch.
Commit with specific tag (either from master or trial branch), for example "v0.1"
The Git repos have
branches,
tags
and commits.
composer.json has fields:
"version" inside "repositories"/"package"
"reference" inside "repositories"/"package"/"source"
version value after the package name in the "require"
What is their meaning and how do they relate to GitHub's branches, tags and commits?
Edit
Flosculus answer worked, but I m still a bit confuzed. Correct me, if I do wrong, but I guess "repositories"/"package"/"version" has no connection with GitHub. However it must been used during Composer's "require".
On the other hand, "repositories"/"package"/"source"/"reference" could be anything that Git can checkout, it can be branch, tag, or commit's hash. I tried defining three items in repositories array.
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-trial",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "trial"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
},
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "0.1",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "v0.1"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
},
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "1.2.3",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "fc70af"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
First defines version "dev-trial" as checkout trial branch which gives the last commit of that branch
Second defines version "0.1" as checkout tag "v0.1"
Third defines version "1.2.3" (non-existing in the GitHub) as checkout commit "fc70af"
To get them I use respectively three requires
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-trial"
},
2.
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "0.1"
},
3.
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "1.2.3"
},
When using the VCS type for repositories, Composer will scan each branch and tag for Composer files. From there, based on the branch and tag names, it can assemble a list of packages.
These packages (like the one you created to reference that repository) exist on packagist.org, which is the default lookup for Composer. The Authors of the repositories put them on Github.
In this case however, the repository is not on Packagist, and it has no composer file on any of it's versions. So what you have done, is created a generic repository. You can do the same thing with local directories, and zip files (local or remotely). However your one is a Git repository.
See modified json:
{
"repositories": [
{
"type": "package",
"package": {
"name": "tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001",
"version": "dev-master",
"source": {
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git",
"type": "git",
"reference": "v0.0.1"
},
"autoload": {
"psr-4": {
"TygrolewGmail\\Zawartosc\\Tworcy\\" : "src/Zawartosc/Tworcy/"
},
"files": [
"/src/Zawartosc/Funkcje/_d.php"
]
}
}
}
],
"require": {
"tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001": "dev-master"
},
"autoload": {
"psr-4": {
"": "src/"
}
}
}
When Packagist or Composer (Packagist also has a copy of Composer), scans a VCS repository, it flattens out all of the versions into multiple packages with the same name, but different versions. In your case "references". The modified json above uses "reference": "v0.0.1" to indicate a specific tag/branch.
https://github.com/composer/satis/issues/29
This is an issue requesting support for VCS repositories without composer files. However it doesn't work. When you modify the repository like so:
{
"type": "vcs",
"url": "https://github.com/tygrolew-gmail/przykladowy-komponent-php-tygrolewa-gmaila-0001.git"
}
This should work if the repo had the composer.json file. In fact when you run composer update with this, you can see it searching each branch and tag. But without the relevant composer file, all you will get is this:
[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of
https://github.com/tygrolew-gmail/przykladowy-komponent-p
hp-tygrolewa-gmaila-0001.git, could not load a package from it.

trying to include a specific branch of a package not on packagist

I'm trying to use a specific branch of repo but getting an error:
composer.json
{
"name": "programmingarehard/arbiter",
"license": "MIT",
"type": "library",
"description": "Convenience library to manipulate Symfony ACL's",
"authors": [
{
"name": "David Adams",
"email": "adams.david.10#gmail.com"
}
],
"autoload": {
"psr-4": {
"ProgrammingAreHard\\Arbiter\\": "src",
"ProgrammingAreHard\\Arbiter\\Spec\\": "spec"
}
},
"require": {
"php": ">=5.3.3",
"symfony/security": "2.4.*"
},
"require-dev": {
"bestform/phpspec": "dev-psr4-support"
},
"config": {
"bin-dir": "vendor/bin"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/bestform/phpspec"
}
],
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
Error:
Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package bestform/phpspec could not be found in any version, there may be a typo in the package name. Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details. Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
This is the repo/branch i'm trying to pull into my package. Not sure what i'm doing wrong.
The repository you are using does not contain a software named bestform/phpspec. Look at the composer.json that is in there, and use the value given as "name". Its phpspec/phpspec, and any branch will only ever be found if you use that name.
The name of the Github repository is irrelevant. Don't confuse it with the "composer" name.

How to install your own bundle with Composer in Symfony 2.1?

I've just moved to Symfony 2.1, and I can't understand, how can I install my own bundles with Composer?
It was very easy in 2.0.x in deps:
[MyOwnBundle]
git=git#git.weboshin.ru:weboshin_cms_bundle.git
target=/bundles/My/OwnBundle
After that I just triggered bin/vendors update and that was it!
But now there's no deps file, and I supposed to do everything with Composer. Please give me any hints.
I've found the answer.
// my_project/compose.json:
{
"repositories": [
{
"type": "vcs",
"url": "own_repository_url"
}
],
// ...
"require": {
// ...
"own/bundle": "dev-master"
}
},
 
// own_repository/own_bundle/compose.json:
{
"name": "own/bundle"
}
Add a composer.json file to your bundle. For example I have this for one of my bundles:
{
"name": "cg/kint-bundle",
"type": "symfony-bundle",
"description": "This bundle lets you use the Kint function in your Twig templates. Kint is a print_r() replacement which produces a structured, collapsible and escaped output",
"keywords": ["kint", "debug", "symfony", "bundle", "twig"],
"homepage": "http://github.com/barelon/CgKintBundle",
"license": "MIT",
"authors": [
{
"name": "Carlos Granados",
"homepage": "http://github.com/barelon"
},
{
"name": "Symfony Community",
"homepage": "http://github.com/barelon/CgKintBundle"
}
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.0.0",
"raveren/kint": "dev-master"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {
"Cg\\KintBundle": ""
}
},
"target-dir": "Cg/KintBundle"
}
Then add your bundle to packagist.org. It is very simple, basically you just have to provide your git address and it will do the rest.
Once your bundle is available in packagist, then just add it as a dependency in the composer.json file for your symfony project. In my case I have:
"require": {
....
"cg/kint-bundle": "*"
},
Then just run "composer update" in your symfony directory and that´s all! You don´t even need to update the autoload file, composer will do it for you. The only thing left would be to load the bundle in appkernel.php

Categories