Managing your Drupal project with Composer

  • Published on

  • View

  • Download


Managing Your Drupal Project with Composermatt glaman | @nmdmatt | mglamanMatt GlamanSenior Drupal Consultant @ Commerce GuysCo-maintainer of Drupal CommerceAuthor of Drupal 8 Development Cookbook ain't new.PIPDependency management is not a new concept.NodeJS: npmFrontend JS/CSS: BowerRuby: Bundler/GemsPython: pipJava: MavenC#/.NET: nugetGo: theres like 10. cocoapodscomposerThe de facto dependency management tool for PHPInspired by npm and bundlerProvides a way to easily share and use librariesNot like PEAR - which installed to global includes directory and didnt use PSR standards for autoloading.composer.jsondefines metadata about the project and dependencies for the projectPackage informationDependenciesDeveloper dependenciesAdditional metadatacomposer.lockcomputed information about dependencies and expected install stateSee Gemfile.lockContains installable package informationProvides a repeatable install across instancescomposer installdownloads and installs dependencieswill install off of lock fileif no lock file, acts as updatedownloads and installs dependencies, builds the class autoloader. If a .lock file is available it will install based off of the metadata. Otherwise it will calculated and resolve the download information for dependencies.composer updateupdates defined dependenciesrebuilds the lock filegenerates autoloadercomposer requireadds a new dependency, updates the JSON and .lock file.updates autoloadercomposer removeremoves a dependency, updates the JSON and .lock fileupdates autoloaderNew to DrupalDrupal never had dependency management. Drush kind of helped.Still a little rockyDrush en -y panels_ipe thx Drush for downloading and enabling everything.Everything isnt worked out yet for working with Drupal and ComposerInstalling DrupalInstall from packaged has a packaging system which provides zip and tar archives. These archives come with all third party dependencies downloaded.Install via Composer templatecomposer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interactionCreates your project in some-dirContains vendor and web directoryFollows current standard application structure dependencies to DrupalWithout Composer (or any tools.)Wanted hunt and peck but this was more suitable.With Composercomposer require drupal/panels"require": { "drupal/panels": "3.0-beta4",}Use Composer require command to add the dependencyYour composer.json should have the followingBUT WAIT. Theres currently a Composer Faade endpoints provide provides a repository endpoint (beta)Allows projects to be installed via composerAllows projects to specify 3rd party librariesInitial community initative: Glaman () - How do we know what the packages are named and available on Glaman () - but with ... it's hard to know what is available.Matt Glaman () - version namingAdding the endpoint to composer.jsoncomposer config repositories.drupal composer composer.json will now have "repositories": { "drupal": { "type": "composer", "url": "" } },Version constraints~8.2.1: >=8.2.1 =8.2 =8.2.1