From 938b9d00b1b538dbcee8d3c4357dc8de2435cf57 Mon Sep 17 00:00:00 2001 From: Ariel Barreiro Date: Tue, 11 Dec 2018 13:38:56 -0300 Subject: [PATCH] Improving composer cheatsheet --- composer.md | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/composer.md b/composer.md index 9b08ef348..52d2132b5 100644 --- a/composer.md +++ b/composer.md @@ -12,38 +12,47 @@ description: | All composer commands, depending on your install, may need to use `php composer.phar` in the install folder for composer, instead of plain `composer`. -### Package management - +### Installing dependencies + | Command | Description | | --- | --- | -| `composer install` | Install everything in composer.json | +| `composer install` | Downloads and installs all the libraries and dependencies outlined in the `composer.lock` file. If the file does not exist it will look for composer.json and do the same, creating a `composer.lock` file. | | --- | --- | -| `composer install laravel` | Install a package | -| `composer install laravel --dry-run` | Simulates the install without installing anything | -| `composer install laravel --no-scripts`| Skips post-download scripts | +| `composer install --dry-run` | Simulates the install without installing anything | -### Updating +This command doesn't change any file. If `composer.lock` is not present, it will create it. -| Command | Description | -| --- | --- | -| `composer update` | Update all packages | -| --- | --- | -| `composer update laravel` | Update a certain package | -| `composer update vendor/*`| Update all packages in a folder | -| `composer update --lock` | Update lock file hash without updating any packages | +`composer.lock` **should always** be committed to the repository. It has all the information needed to bring the +local dependencies to the last committed state. If that file is modified on the repository, you will need to run +`composer install` again after fetching the changes to update your local dependencies to those on that file. +### Updating packages +| Command | Description | +| --- | --- | +| `composer update` | Updates all packages | +| `composer update --with-dependencies` | Updates all packages and its dependencies | +| --- | --- | +| `composer update vendor/package` | Updates a certain `package` from `vendor` | +| `composer update vendor/*` | Updates all packages from `vendor` | +| `composer update --lock` | Updates `composer.lock` hash without updating any packages | -### Requiring +This command changes only the `composer.lock` file. + +### Adding packages | Command | Description | | --- | --- | -| `composer require laravel`. | Add new package to composer.json and install it | +| `composer require vendor/package`. | Adds `package` from `vendor` to composer.json's `require` section and installs it | | --- | --- | -| `composer require laravel --dev` | Add new package to `require-dev` and install it. | +| `composer require vendor/package --dev` | Adds `package` from `vendor` to composer.json's `require-dev` section and installs it. | -### Removing +This command changes both the `composer.json` and `composer.lock` files. + +### Removing packages | Command | Description | | --- | --- | -| `composer remove laravel` | Remove new package from composer.json and uninstall it | +| `composer remove vendor/package` | Removes `vendor/package` from composer.json and uninstalls it | + +This command changes both the `composer.json` and `composer.lock` files.