Composer Commands

Action Command
Download Package #Download or install a package or library
composer require <vendor>/<package>:<version>

#Download a drupal module
composer require drupal/<module>:<version>
composer require drupal/cypher_link
Remove Package #Remove a package or library
composer remove <vendor>/<package>:<version>

#Remove a drupal module
composer remove drupal/<module>:<version>
composer remove drupal/cypher_link
// Search available libraries or packages.
List of packages Packagist

Comments

  1. Download multiple libraries at once:
    composer require lib1 lib2 lib3

    ReplyDelete
  2. Download Drupal-7
    composer create-project drupal-composer/drupal-project:7.x-dev drupal7

    ReplyDelete
    Replies
    1. Download Drupal-8
      lando composer create-project drupal-composer/drupal-project:8.x-dev trydrupal

      Delete
  3. Memory issue
    Check PHP memory:
    php -r "echo ini_get('memory_limit').PHP_EOL;"
    for a particular command say 'composer install' temporary make php memory_limit -1 (unlimited):
    php -d memory_limit=-1 /usr/local/bin/composer install

    ReplyDelete
  4. Composer Update & Rollback:
    composer self-update

    Updating to version 1.10.8 (stable channel).
    Downloading (100%)
    Use composer self-update --rollback to return to version 1.9.0
    composer --version
    Composer version 1.10.8 2020-06-24 21:23:30

    ReplyDelete
  5. Install recommended Drupal on current directory
    php -d memory_limit=5G /usr/local/bin/composer create-project drupal/recommended-project .

    ReplyDelete
  6. # Update composer to latest version
    composer self-update

    To a specific version (say, composer-v2)
    composer self-update --2

    # How to use different versions of composer?
    Create a copy of exisitng composer
    sudo cp `which composer` /usr/local/bin/composer1

    Now, command 'composer1' will be available
    To use it as latest composer-v1 version
    sudo composer1 self-update --1

    Alias the versions of composers
    sudo ln -s `which composer` /usr/local/bin/composer2
    sudo ln -s `which composer1` /usr/local/bin/composer-old

    May be you need to run above commands with 'sudo'

    ReplyDelete
  7. composer update --dry-run
    Outputs the operations but will not execute anything (implicitly enables --verbose).

    ReplyDelete
  8. Applying patches with composer:
    "extra": {
    "patches": {
    "drupal/core": {
    "Accidentily looking for X-CSRF-Token when OAuth method used": "https://www.drupal.org/files/issues/2019-07-05/3055260-skip-csrf-token-check-when-using-bearer-auth-11-8.8.x.patch"
    }
    }
    }

    Also to work it requires :
    "cweagans/composer-patches": "^1.6"

    composer require cweagans/composer-patches
    composer install

    ReplyDelete

Post a Comment

Drupal Contribution
Git Commands
RESTful Services
Lando Commands
Docker Commands
MySQL
Database Quick Code
Drush Commands
Drupal Console
PHP Quick Code
Drupal Quick Code
Composer Commands
Linux Commands
Linux Shell Scripting
Drupal Hooks
Twig Tricks
PHPUnit Test
PhpMyAdmin
Drupal Constants
CSS Clues
BLT Commands
Vagrant Commands
Localhost
127.0.0.1
Drupal Interview
Drupal Certifications
Concept & Definitions
Mac Tips
Windows Tips
Browser Tips

Best Practice

Use 'elseif' instead of 'else if'
#CodingTips

As of PHP 5.4 you can also use the short array syntax, which replaces array() with []
#CodingTips

Functions in general shall be named using snake_case(say, my_function()), and using camelCase(say, myFunction()) when declared within a plugin class
#CodingTips

Variables in general shall be named using snake_case(say, $my_variable), and using camelCase(say, $myVariable) when declared within a plugin class
#CodingTips

Manage automatically assigning of new permissions whenever a module is enabled here- admin/config/people/accounts
#ConfigurationTips

Manage source of Main-menu and User-menu links here- admin/structure/menu/settings
#ConfigurationTips

Helper function(s) shall be named prefixing an underscore(say, _my_helper_function()), which can prevent hooks from being called
#CodingTips

Ideally, configuring of 'Private file system path' at admin/config/media/file-system should be located outside of your Drupal root folder(say, ../my_private_files)
#ConfigurationTips

You should be aware that uploading files as 'Private file' will slow down the process of loading the files as Drupal has to be bootstrapped for every file that needs to be downloaded
#ConfigurationTips #BeAware

Code should always be pushed up(dev -> staging -> production) and databases should only be pushed down(production -> staging -> dev)
#DevelopmentTips

Get Raw SQL Query of drupal dynamic queries before executing it using $query->__toString();
#DebugTips

In VI-Editor, Press ESC key to come in command mode and for undo type :U and for redo type :Ctrl+R
#LinuxTips

Insert queries must always use a query builder object(layer of abstraction), allowing individual database drivers special handling for column values (if applicable), example case for LOB and BLOB fields.
#DatabaseQueryTips

Drupal uses the .inc extension to prevent files from being executed directly.
#DevelopmentTips

Popular Posts