Is there any way to use composer CLI command to add a repository location to composer.json but without stating its name?
You can do:
composer config repositories.<name> vcs /path/to/the/repository
But I'm interested in adding repository location without specifying its name.
Since repositories' locations can be added in composer.json without their names:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/igorw/monolog"
}
],
"require": {
"monolog/monolog": "dev-bugfix"
}
}
I'm interested to add such entry:
{
"type": "vcs",
"url": "https://github.com/igorw/monolog"
}
by using composer CLI but command:
composer config repositories vcs /path/to/the/repository
fails.
Do you know how to do that?
It's not possible at this point. If you take a look at the regex that parses your repositories argument (or repo/repos):
// handle repositories
if (preg_match('/^repos?(?:itories)?\.(.+)/', $settingKey, $matches)) {
https://github.com/composer/composer/blob/1.7.2/src/Composer/Command/ConfigCommand.php#L535
You see it's expecting the repositories.name format. My guess would be that while adding them anonymously would be fine if you don't already have repositories defined, it would break if you started trying to name some of them. Also the unset command wouldn't work because you haven't named it, and running the command repeatedly would continue to add them.
My guess is that it's a deliberate move not to support this. You could always open an issue on the repository to request it though.
I can't find a way to do that. I would just add it manually (without the cli tool). I did try using composer config repositories._ vcs /url. It worked, but it obviously set the name to be "_". Then you can go in and delete that. But if you are doing that anyway, you might as well just add it manually anyway.
Related
I'm currently trying to setup a better local development without putting information about my local structure into a project itself or into the composer.json of this project.
I found out, that there is a new way to do this by using a config.json and adding a "repositories" section to it, that points to my local projects I depend on.
My setup
So I setup two projects with a few versions (on Win10 with IIS 10 with PHP 7.0), lets call them php-project1 and php-project2. php-project1 depends on php-project2 and I want to develop both of them at the same time. Changes I make in php-project2 should therefore directly influence the first project. In addition they are git repositories and they contain tags as composer versions. They are also on packagist, but of course I want to use the local version for development.
Their composer.json look like this (2 files):
{
"name": "test/php-project1",
"description": "Some text here",
"type": "library",
"require": {
"test/php-project2": "^0.3",
}
}
{
"name": "test/php-project2",
"description": "Some other text here",
"type": "library"
}
Please note that there is no "version" entry, because I want to use this from the git tags.
Now I tried to setup a global config.json like this:
{
"repositories": [
{
"type": "path",
"url": "/somePath/php-*"
}
]
}
I'm using php-* here because I want to use it later for all my repositories/projects with this pattern.
So what's the problem now?
When running composer update on the first project it doesn't use the local version of php-project2, but instead downloads it from packagist. This only works when I add a "version" entry to the composer.json, but I don't want this!
I also tried "type": "vcs", but this creates a clone and I need a symlink, to have changes directly in other projects too.
The documentation says:
If the package is a local VCS repository, the version may be inferred by the branch or tag that is currently checked out. Otherwise, the version should be explicitly defined in the package's composer.json file.
Currently php-project2 is on tag 0.3.0 without any changes.
So what do I do wrong?
Found my mistake with help of alcohol (this sounds wrong though^^).
When you use this and need a symlink, be sure to add a "version" entry to your composer.json or (in my case) checkout the tag (not the branch!), so composer may see, that your used version matches the required.
EDIT
I think I misunderstood satis, now this is my new understanding, please correct me if I am wrong:
In satis.json, I must specify the url s of the packages I want to mirror, e.g the doctrine git repo, yaml git repo... Then satis mirrors all these packages on my server. This would mean I need to add once all packages used within my composer.json of my project to the satis json (around 20 packages/requirements ). Now, I can add my private satis repository to the composer.json file of my project and when running "composer update", it will first look within the satis mirrored packages for the required package. Did I understand that correctly?
Situation:
I am trying to use Satis for private composer repository. I have a private project on github for a website of mine. On the project, I am using composer and therefore I have a composer.json on the root of the project. It looks the following:
{
"name": "Peter North",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"": "src/"
}
},
"require": {
"php": ">=5.3.9",
"symfony/http-foundation": "dev-master"
}
...
}
Now I wanted to use my private satis repository of url: packages.ait.company, running on an apache and accessible so far. The satis.json looks the following:
{
"name": "AIT Company",
"homepage": "packages.ait.com",
"repositories": [
{
"type": "vcs",
"url": "git#github.com:north/ait.git" // this is the url of my private github project
}
],
"require-all": true,
"require-dependencies": true,
"archive": {
"directory": "dist",
"format": "tar",
"skip-dev": true
}
}
I think that I did not understand well how to structure the satis.json file and what it needs to contain, because the way I am trying, it does not download the "php" and "symfony/http-foundation" packages that I specified in the composer.json file - though it does download the correct composer.json file of the project into /satis/include directory json file.
How does the satis.json need to look like, when I want to read the composer.json of my project from github and build the private satis repository of the "require entries" ?
In my Satis update script, it is a two step process to create local copies from both external packages as well as internal, private repositories.
The first step only downloads the meta data of external dependencies and puts them into an intermediate satis repository. The configuration explicitly does not "require-all", but has explicit statements of all packages that are being used (and some that may be used, or had been used in the past) with an open-ended version wildcard, i.e. "symfony/console":">=2.4" (no tilde or caret - I want to get major version updates here). Adding require-dependencies:true scans all the dependencies of all the required packages and adds them to the meta data collection as well.
The result is stored in a directory "external".
The second step is responsible for scanning all packages from internal "repositories", and creating archives from them. This obviously is a list of all private repos, but the trick is: You can also add to the satis.json a repository of type "composer" - and this is where I add the external repository with the meta data from external packages. Adding it here adds all the external packages' versions to the list of versions that need to have ZIP files created.
Running it for the first time takes a long time because of all the packages that need to be downloaded (and created locally from the private repos). Running it after that is simply an incremental update of only the new versions that haven't been created previously.
The key is to configure collecting external packages without ZIPs and with explicit version ranges ("*" as version would work, but only use it if you really need all versions) in one Satis file, then add the resulting repository to the second Satis configuration. You cannot combine the two operations (only creating ZIPs of selected external dependencies together with ZIPs of ALL internal repositories) into one Satis run.
One more tip: You probably only want to create local copies of your external dependencies to avoid hitting a Github outage when you are deploying to production (or are developing and need that update). In order to ensure every used dependency is in my Satis, I added both the Satis repository to every composer.json, as well as "packagist":false, to turn off any direct contact to Packagist. You cannot just add a random package then, it has to be in your local Satis repository first.
I'm using a package in my Laravel application that doesn't have support for Laravel out of the box, so I added a Facade and Service Provider to it myself. Both of those files are checked into my repo (specified in .gitignore using the ! prefix). However, when composer updates a package it completely removes it first, and this is preventing automatic deployment with platforms like Codeship.
Any suggestions?
You should fork the package, create a custom repo with your changes - then include that in your composer.json.
{
"repositories": [ {
"type": "vcs",
"url": "https://github.com/YourGithubUsername/PackageName"
}
}],
"require": {
"laravel/framework": "4.0.*",
"OriginalVendor/PackageName": "1.0.*"
},
}
That way you can pull your custom changes in anytime, without having to commit it to your specific project.
You can read more about forking and loading packages here: https://getcomposer.org/doc/05-repositories.md#vcs
Never change the code of packages! In fact, never touch the vendor directory.
You should either [fork] the repository and add your code (see #TheShiftExchange's answer)
Or add the Facade and the ServiceProvider in your namespace.
I have this composer.json file
{
"require": {
"filp/whoops": "1.*"
}
}
However, I have a folder for my own project called vendor/imaqtpie/framework/src. This is not hosted anywhere, so if I do composer update to update autoload files, it gives an error.
The requested package "imaqtpie/framework" could not be found in any version, there may be a typo in package name.
I had to add this myself to autoload file to make it work.
'Framework' => array($vendorDir . '/imaqtpie/framework/src')
Is there any way to solve this?
I want to tell Composer that this local vendor folder has to be autoloaded each time regardless of checking server/version, or looking for a more elegant solution since I'm new to composer.
You have to create your own local git repository with your package code to achieve that.
After that, put something like this into your composer.json file.
"repositories": [
{
"type":"vcs",
"url":"/path/to/your/source"
}
],
"require":{
"filp/whoops":"dev-master"
}
Autoloading shouldn't be an issue if you implement it this way...
There are a few ways you can do this.
1.
I'd say the most correct way, is to host it and use Satis to produce a private 'packagist'. Then composer will behave "normally" and get the latest version, do version checking etc. but you say you don't care for this.
If you want more details I can expand on this, I have set up many satis packages and it works really well. (Note there's also the new commercial Toran Proxy which I haven't trialled yet.)
2.
If your 'imaqtpie' library is a fake vendor library (it sounds like you just have some files you've stored there, like you would an old-fashioned include library?), then you could simply use a classmap to point the autoloader to that folder from your top level application. This only makes sense if you are including that folder in your top-level app.
So your app's composer json could look like:
{
"require": {
"filp/whoops": "1.*"
},
"autoload": {
"classmap":[
"vendor/imaqtpie/framework/src"
]
}
}
So this tells composer there's a bunch of classes in that folder. When you run composer dump-autoload it will scan the folder and generate vendor/composer/autoload_classmap.php with all your files listed.
This isn't how you're supposed to use composer, but you're not asking to use composer for package management you're asking how to use composer's autoloader, which I guess is fine! as long as you understand the risks.
3.
If your package is either PSR0 or 4 (it sounds likely from the "src" folder) then you'd similarly do this in your top-level app:
{
"require": {
"filp/whoops": "1.*"
},
"autoload": {
"psr-4": {
"Imaqtpie\\Framework\\":"vendor/imaqtpie/framework/src"
}
}
}
Which again is a bit odd, but should work!
Normally, you'd specify this path in your package's composer.json and then when you do an update it gets merged into your composer.lock and then the vendor/composer/installed.json (which is the source used for the dump-autoload). But in theory you can load whatever you want from the top level app, and therefore you can 'hard code' a package into the vendor library and classpath to it.
I'd probably recommend not doing this though! The vendor folder is a tenuous location which most people and programs would assume can be destroyed and rebuilt at a whim. So it's a dangerous place to store anything which isn't in a package. It's also confusing for any other developers who will assume the same.
So I'd recommend moving your library to another location away from the vendor folder, e.g. 'lib', and then using the classpath approach above to include it in the autoloader.
I want to require only a sub portion of a git repository (instead of the full thing). The reason i want to do this is because the repository is huge.
In my case the repository is: https://github.com/pubnub/pubnub-api.git and I only want the /php directory.
I have the following package defined in composer:
{
"type": "package",
"package": {
"name": "pubnub",
"version": "dev-master",
"source" : {
"url": "https://github.com/pubnub/pubnub-api.git",
"type": "git",
"reference":"master"
}
}
},
Any tips?
Given the answer to "Is there any way to clone a git repository's sub-directory only?" Is "No" , and sub directory checkout functionality would be required by composer to satisfy the desired functionality, then I would suggest the best composer could do was checkout the whole thing and then delete what you didnt want.
In short: Not Possible.
The longer answer:
is that git can do a sparse checkout so in theory composer could someday support that feature. You can use the autoload field to only load the section of code you want (ie, not load the whole lib).
It seems that the php directory has been moved on its own repository here https://github.com/pubnub/php. That may help for this project, but no idea how to achieve this from main repo and composer...