How can I composer global require hirak/prestissimo (or anything else) to DDEV-Local? (DON'T: Use Composer 2) - ddev

Edit: This question has gotten quite old and is no longer useful. Prestissimo isn't really useful any more now that Composer 2 is out. The way to use composer 2 in DDEV-Local v1.16 is ddev config --composer-version=2. In DDEV-Local v1.17 Composer 2 will be the default.
Original question:
I'd like to use hirak/prestissimo to speed up the downloads for my DDEV-Local composer builds on all my projects, but I don't know how to install it globally. How can I install it?

In DDEV-Local v1.15+ you can globally put anything you want in the web container home directory using the homeadditions feature, and in the web container the composer global configuration is in ~/.composer. So the simple way to create the files you need (and hirak/prestissimo is just an example) is to
ddev composer global require hirak/prestissimo # This installs prestissimo into global composer (home directory)
docker cp ddev-<your-project-name>-web:/home/$(id -un)/.composer ~/.ddev/homeadditions/
ddev start
Of course, you can also do this on the project level instead of the global level using your project's .ddev/homeadditions directory instead of the ~/.ddev/homeadditions directory.

In addition to what rfay said, and based on his solution here is another approach.
In your .ddev/web-build/Dockerfile add RUN composer global require hirak/prestissimo.
This will install hirak/prestissimo in the /root/.composer directory.
Then, in the .ddev/homeadditions/.bash_aliases add the following:
sync_global_composer() {
sudo rsync -a /root/.composer/ /home/$(id -un)/.composer
sudo chown -R 1000:1000 /home/$(id -un)/.composer
}
sync_global_composer
The first time you execute ddev ssh will take a bit longer because of the rsync, but the followings are quick.
The reason of this approach is not having prestissimo (and in my case some others global libraries) in git, and the idea is to have this transparent for the rest of the dev team.
PD: I'm still thinking in how to improve it.

You can also update to composer 2 since it is fast enough to not need hirak. Update using composer self-update --2 and then remove hirak/prestissimo with composer global remove hirak/prestissimo
resources:
https://github.com/hirak/prestissimo
https://blog.packagist.com/composer-2-0-is-now-available/ - speed increases

Related

Composer: how to let composer to know that I have the package locally already?

I know that we can always install a package via command:
composer require packageA
But I don't know if you guys ever have a situation like this:
You want to install a big size package "packageB" that your teammate added to composer.json and your wifi is slow so composer would take very very long to get the packageB. Then you have an idea:
"Maybe I try get the packageB zip from my teammate via flash drive and paste
it into my project."
And you did that, the package works as expected. Wonderful!
But then, you think again:
What if now I want to do the composer update other packages in my
project?
You try:
composer update
and then, what happen is composer will get the package again because you didn't use "composer install" or "composer update" to install packageB so composer doesn't know you have it.
(Sorry for the long explanation).
So my question is:
How do we let composer know that we have the package already so composer don't re-download the package again? Or this is the behavior of composer and I must always use "composer install/update", there is no other way?
And sorry, change to another wifi or find a faster internet connection is really not what I'm looking for. And I also know that we can install the package locally (see here: How to update a single composer package?).
Thanks in advance!
If we don't want to use repositories.
In my knowledge, the only option is to update you composer.json and composer.lock. Friend give you version 1.2 to vendor? Write in exactly version in composer.json and for composer.lock, you will need data from your friend too.
Run install then.
Should check, but not download any file. Still, problem is that all required libraries by this library, could be updated - you can only write down exactly version of them in file.
As default, I think, the didn't predict scenarios for that way.
This is the only solution for you, i know should work.
Composer does use caching heavily to reduce the amount of data to download. However this does not remove the need to download the package at least once.
Basically Composer has two modes to download: --prefer-dist will try to obtain a download URL for an archive file, and --prefer-source will try to obtain a copy of the version control system being used.
Both variants put the result into Composer's cache directory.
Over time you'll collect a couple of archive files locally, which allow for quick switches back and forth between existing version downloads, and newer versions will have to be downloaded once.
Also you can clone a git repository once, and Composer will try to reuse it when updating, by simply fetching new commits and checking out the appropriate tags. This still requires to clone the repository once.
You can work around cloning the repository by manually placing it at the correct spot, either by physically putting it there, or by symlinking the correct vendor directory. You can also make Composer aware of an official copy by adding the local copy as an entry to repositories. This will add this source to the existing collection of packages available from Packagist.

what's the purpose of composer's `require` command

Here is the definitions from the docs:
The require command adds new packages to the composer.json file from
the current directory. If no file exists one will be created on the
fly. After adding/changing the requirements, the modified requirements
will be installed or updated.
If you do not want to choose requirements interactively, you can just
pass them to the command.
I can't seem to understand the purpose of the require command and the difference from install. Can you elaborate on that?
And here is the example of using the command:
composer global require "fxp/composer-asset-plugin:~1.0.3"
Can you tell me what's the difference from:
composer global install "fxp/composer-asset-plugin:~1.0.3"
It's just a convention. There might be some fallbacks in other commands for common people missuses, but every command is optimized for a different feature. It's just better user experience.
Same goes for similarity of composer install and composer update.
As for conventions, in order of common workflow:
composer install is for installing all packages of new application (all mentioned in composer.json), use: composer install
composer require is for adding a new package, use: composer require symfony/symfony
composer update is for updating current dependencies, use: composer update
composer require->It will write the modules in composer.json file and install the module.
composer install->It will install the modules which are already present in the composer.json file.

Composer - restore deleted file?

I use composer to manage packages. But I delete one of files from package (I use composer status -v to check this).
Is it possible to restore changed/deleted files to it base (installed) state via composer (composer install doing nothing in my case) ?
Thanks.
ps. It's look like there no way to restore separate file from repo, after his been changed/deleted. Of course, it's possible to delete entire vendor dir, and reinstall some package totally.
I edit dependant package source code all the time and run into the issue of my local being out of sync with the remove source.
When things get really sideways and nothing works: delete the package providers dir inside the ./vendor (exp: ./vendor/author-name). Then composer will see the package is missing when running composer install. It will re-download the version specified in composer.lock.
If you want the latest version of all the packages when re-installing; composer update is what you want.
I also recommend using -o -vvv to generate the AuoLoader file and provide verbose output.

Different handling of composer update

Me and my team are working on a project that uses Composer for dependency management. There seems to be a difference in how a composer update is handled on several machines (running the same latest build version of Composer), but we can't figure out why.
When my teammate runs a composer update on a dependency it tries to remove a lot of data/nodes from the composer.lock file (like the entire dist and support nodes):
When I run the same update, it tries to re-add all those keys again:
We can't figure out why this is happening. Is this a certain setting?
Update: On further inspection, it appears that the "(dis)appearing" nodes all contain https links, could it have something to do with a (missing) SSL library or something?
It seems that one Composer prefers dist and one prefers source.
Look into ~/.composer/config.json if you defined a preferred install in any of your two composers. Or if you defined different preferred installs in the composer.json.
"config": {
"preferred-install": "dist"
}
You can force composer to use either dist or source with
composer update --prefer-dist
or
composer update --prefer-source
--prefer-source: There are two ways of downloading a package: source and dist. For stable versions composer will use the dist by default. The source is a version control repository. If --prefer-source is enabled, composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly.
--prefer-dist: Reverse of --prefer-source, composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup.

composer update ignore deps

How can i tell composer to ignore certain deps while running update?
I know i can update certain packages with:
php composer.phar update vendor/package vendor/package2
But i would like to have it the other way around by telling composer to update all except these packages.
In my case the command would be much shorter than the above, since i just want to ignore some experimental bundle.
And i dont want to delete it fully, which would probably happen, if I clear the bundle from the require list.
I think this is not possible by now.
However you can try to shorten the explicit update calls with wildcards:
php composer.phar update doctrine/*
As described here: http://getcomposer.org/doc/03-cli.md#update
But composer will ask you if you want to keep local changes if composer detects such.
The package has modified files:
D code/controller/yourFile.php
Discard changes [y,n,v,s,?]?
Also you can use the stash/apply mechanism for git repos which is featured in composer.
https://github.com/composer/composer/pull/1188
Also helpful:
Composer: Develop directly in vendor packages
Maybe it wasn't possible at that time, but nowadays you can do it like this
composer update --ignore-platform-reqs vendor/package

Resources