How to update a single library with Composer? - symfony

I need to install only 1 package for my SF2 distribution (DoctrineFixtures).
When I run
php composer.phar update
I get
- Updating twig/twig (dev-master 39d94fa => v1.13.0)
The package has modified files:
M CHANGELOG
M doc/filters/batch.test
M doc/filters/index.rst
M doc/filters/url_encode.rst
M doc/functions/index.rst
M doc/tags/index.rst
M doc/tests/index.rst
M lib/Twig/Autoloader.php
M lib/Twig/Compiler.php
M lib/Twig/CompilerInterface.php
-10 more files modified, choose "v" to view the full list
It appears the last developer edited a lot of files inside vendor.
In order to get around this, I tried
php composer.phar update <package_name>
But that doesn't seem to work. How can I update/install only one library from composer.json?

To install doctrine/doctrine-fixtures-bundle with version 2.1.* and minimum stability #dev use this:
composer require doctrine/doctrine-fixtures-bundle:2.1.*#dev
then to update only this single package:
composer update doctrine/doctrine-fixtures-bundle

If you just want to update a few packages and not all, you can list them as such:
php composer.phar update vendor/package:2.* vendor/package2:dev-master
You can also use wildcards to update a bunch of packages at once:
php composer.phar update vendor/*
As commented by #ZeroThe2nd ZSH users may need to wrap their vendor/* in quotation marks:
php composer.phar update "vendor/*"
--prefer-source: Install packages from source when available.
--prefer-dist: Install packages from dist when available.
--ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. See also the platform config option.
--dry-run: Simulate the command without actually doing anything.
--dev: Install packages listed in require-dev (this is the default behavior).
--no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
--no-autoloader: Skips autoloader generation.
--no-scripts: Skips execution of scripts defined in composer.json.
--no-plugins: Disables plugins.
--no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
--optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
--lock: Only updates the lock file hash to suppress warning about the lock file being out of date.
--with-dependencies: Add also all dependencies of whitelisted packages to the whitelist.
--prefer-stable: Prefer stable versions of dependencies.
--prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.

Difference between install, update and require
Assume the following scenario:
composer.json
"parsecsv/php-parsecsv": "0.*"
composer.lock file
"name": "parsecsv/php-parsecsv",
"version": "0.1.4",
Latest release is 1.1.0. The latest 0.* release is 0.3.2
install: composer install parsecsv/php-parsecsv
This will install version 0.1.4 as specified in the lock file
update: composer update parsecsv/php-parsecsv
This will update the package to 0.3.2. The highest version with respect to your composer.json. The entry in composer.lock will be updated.
require: composer require parsecsv/php-parsecsv
This will update or install the newest version 1.1.0. Your composer.lock file and composer.json file will be updated as well.

You can use the following command to update any module with its dependencies
composer update vendor-name/module-name --with-dependencies

You can basically do following one to install new package as well.
php composer.phar require
then terminal will ask you to enter the name of the package for searching.
$ Search for a package []: //Your package name here
Then terminal will ask the version of the package (If you would like to have the latest version just leave it blank)
$ Enter the version constraint to require (or leave blank to use the latest version) []: //your version number here
Then you just press the return key. Terminal will ask for another package, if you dont want to install another one just press the return key and you will be done.

Just use
composer require {package/packagename}
like
composer require phpmailer/phpmailer
if the package is not in the vendor folder.. composer installs it and if the package exists, composer update package to the latest version.
Update:
require install or update the latest package version. if you want update one package just use update.

To ensure that composer update one package already installed to the last version within the version constraints you've set in composer.json remove the package from vendor and then execute :
php composer.phar update vendor/package

Because you wanted to install specific package
"I need to install only 1 package for my SF2 distribution (DoctrineFixtures)."
php composer.phar require package/package-name:package-version
would be enough

Related

How to install patched modules in fresh Drupal 10 Installation?

I have a fresh Drupal 10 Installation und would like to install some modules with more ore less simple patches. I tried it in different ways and get allways the same errors with composer require.
This are my steps:
manual changed files for exampe in superfish for this patch:
https://www.drupal.org/files/issues/2022-08-01/superfish-%233.patch and manually put the module in module/contrib folder. Than I tried composer require drupal/superfish:~1.4 with different versions and with and without parameter -W.
I wrote patch in composer.json and tried composer install. There comes the message nothing to install or update. I used also composer update --lock
I downloaded last dev-Version and patch and tried with git apply.
The result with composer require is more ore less the same error like this:
Problem 1 - drupal/block_content_permissions[1.0.0, ..., 1.8.0]
require drupal/core ^8 -> found drupal/core[8.0.0, ..., 8.9.20] but
these were not loaded, likely because it conflicts with another
require. - drupal/block_content_permissions[1.9.0, ..., 1.10.0]
require drupal/core ^8 || ^9 -> found drupal/core[8.0.0, ..., 8.9.20,
9.0.0, ..., 9.5.0] but these were not loaded, likely because it conflicts with another require. - Root composer.json requires
drupal/block_content_permissions * -> satisfiable by
drupal/block_content_permissions[1.0.0, ..., 1.10.0].
You can also try re-running composer require with an explicit version
constraint, e.g. "composer require drupal/block_content_permissions:*"
to figure out if any version is installable, or "composer require
drupal/block_content_permissions:^2.1" if you know which you need.
If I enable the patched modules manualy in backend, they work normaly. But they are not under composer controll.
How to do in the right way?
Drupal.org has a documented process for allowing a lenient composer install.
For Drupal 10:
Try the Lenient Composer Plugin
The lenient composer plugin lets you specify an allowlist of packages
where you are willing to break the version constraint, using a command
like:
composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/token"]'
Together with the Composer Patches Plugin, this allows you to install
any Drupal extension, even if the version constraint hasn't been
officially updated yet. Of course the code may still need to be
patched for deprecations.

Unpack symfony/symfony

I started working in a huge project written in Symfony which is at version 2.8. Upgrading the whole project to SF 3 would take hundreds of hours and it's not possible right now. I came up with an idea to unpack symfony/symfony package to single packages it replaces (key replace in composer.json). It would unlock all 45 packages that are locked on self.version and allow us to upgrade any package step by step if possible.
Example: I have doctrine/orm locked at 2.5.* and cannot ugrade to 2.6 (what will get rid of few bugs and also allow me to upgrade PHP 7.2 --> 7.3) because I have symfony/console locked by symfony/symfony at version 2.8 and doctrine/orm:2.6 requires symfony/console:~3.0.0. However my project would allow to have symfony/console even at version ^3.2 so you can see my point.
I would like to ask you if there are any dangers to the application when attempting to unpack symfony/symfony? So far I can't see any.
P.S. Info for those how want to answer "just require a single package with higher version". Since Composer 1.7.3 it's not possible and will trigger a version conflict.
In such case it will be better to walk in a tiny steps and carefully check results of each step. Of course if whole your project is covered by tests it would be much simpler to do such change, but I don't know if it is.
I would probably do something like this:
Copy composer.json into separate directory
Get exact versions of packages by running composer info
Look into list of packages provided by symfony/symfony e.g. by looking into its own composer.json or by looking at its page on Packagist.
Replace symfony/symfony in copied composer.json with individual packages of same versions as you currently have.
Run composer install and compare resulted set of actually installed packages with packages installed for your project. Simplest way is to compare output of composer info from both directories. You can also use something like composer info | awk -F ' ' '{print $1 " " $2}' | sort to get sorted list of packages and their versions so it will be easier to compare.
Tune packages list and version constraints until you will achieve same results from composer info for both actual project and your new composer.json.
Copy composer.json back into main project. By this time you will be able to install same vendor packages but will be able to control them separately.
Go on with package versions tuning but don't forget to apply minimal changes at a time and test (hopefully by running auto-tests) each change separately.
I hope you know composer why command that allows you to examine package dependencies so you will understand better which packages will get affected by changing version of some particular package.
Good luck with this task because careful upgrade may take quite some time.

Why composer updates all existent deps?

I added a new bundle dependency to my composer.json file and when running composer update command, the composer updates all existent deps while I just want to install the new bundle.
Is there a command option to install just the new deps without updating existent ones ?
Is there a command option to install just the new deps without updating existant ones?
Yes, there is: composer require.
Simply run composer require vendor/package.
From the docs
In order to get the latest versions of the dependencies and to update the composer.lock file, you should use the update command.
php composer.phar update
This will resolve all dependencies of the project and write the exact versions into composer.lock.
If you just want to update a few packages and not all, you can list them as such:
php composer.phar update vendor/package vendor/package2
You can also use wildcards to update a bunch of packages at once:
php composer.phar update vendor/*

How to Meteor package auto install / add / update?

Is there a way for Meteor to automatically install and/or update a package i.e. if you just add the package name to the .meteor/packages file ?
In the case of local (and core) packages, meteor add is the same as appending the package name to .meteor/packages. Any updates you make to a local package will automatically be propagated to your app (there is no need to subsequently run an update command).
In the case of atmosphere packages, you must use mrt add and mrt update. These commands manipulate smart.json, smart.lock, and the links in the packages directory. All of which are necessary for meteor to find and fetch atmosphere packages.
You can upgrade versions of all your packages with following command:
meteor update
To update one or more packages, must be passed the name of the packages to meteor update package-name (replace package-name) or just run meteor update --all-packages.

Symfony2 Composer Not Downloading Packages

I was recently trying to re-install the fos:userbundle and noticed the docs have changed. They are no longer using the deps file are now referencing the new package manager composer.
I found some info about integrating composer with sf2.0.* here:
http://knplabs.com/blog/symfony2-with-composer
After downloading the src: https://github.com/KnpLabs/symfony-with-composer
I tried adding the following to my composer.json: "friendsofsymfony/user-bundle": "*"
as per the instructions: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
When I run bin/vendors update I get the following:
Updating dependencies
Nothing to install or update
Writing lock file
Generating autoload files
It does not appear to be installing the fos package. Am I missing something?
Thanks
Composer is a PHAR archive that takes care of installing dependencies, update them, create projects, etc. It has nothing to do with the old bin/vendors.
What you need to do is to download Composer:
curl -s http://getcomposer.org/installer | php
And install your dependencies:
php composer.phar install
By the way, the symfony-with-composer thing you downloaded is an old version of Symfony2 Standard Distribution that isn't maintained anymore, as mentioned on the repository itself.

Resources