Composer is a dependency management system for PHP packages. This patch adds Composer support to the LESS module. Having this means that the module can specify the following in its composer.json to depict a dependency on LessPHP:

  "require": {
    "leafo/lessphp": "0.3.5"
  }

Once this patch is committed, using the Composer Drush integration makes installing the LESS module VERY easy, as the LessPHP library is installed for you.

$ drush dl composer
$ drush dl less

The LESS module now has a vendor directory with LessPHP in it. The _less_inc() function will register the lessc class to be autoloaded when needed.

To test out composer.json, you can run the following:

$ drush dl composer
$ drush composer install

It will download LessPHP and set up autoload.php for you. Attached is a screenshot of it running on the Symfony and xCSS modules.

Note: This patch does not remove the Libraries API support to LESS. It just adds support for you to use Composer to handle LessPHP instead of Libraries. If you still want to use Libraries module, that still works just fine.

CommentFileSizeAuthor
#6 less-composer.png33.42 KBrobloach
composer.patch2.98 KBrobloach
drushdl.png89 KBrobloach

Comments

corey.aufang’s picture

After looking at your patch, this is what I came up with:


function _less_inc() {
  static $loaded = NULL;
  
  if (!isset($loaded)) {
    
    $include_locations = array();
    
    // Composer created path
    $include_locations[] = dirname(__FILE__) . '/vendor/autoload.php';
    
    // load libraries module for during install
    module_load_include('module', 'libraries');
    
    if (function_exists('libraries_get_path')) {
      $include_locations[] = libraries_get_path('lessphp') . '/lessc.inc.php';
    }
    
    // add legacy path as final possible location
    $include_locations[] = dirname(__FILE__) . '/lessphp/lessc.inc.php';
    
    foreach ($include_locations as $include_location) {
      if (file_exists($include_location)) {
        require_once $include_location;
        break;
      }
    }
    $loaded = class_exists('lessc', TRUE);
  }

  return $loaded;
}

Forcing an auto-load to check for class presence at this point is not a problem since the only time that _less_inc() is called is immediately before compiling a file or on the Drupal status report.

Also, I had to run "drush composer install" form the LESS module directory, which seems to counter intuitive when dealing with Drush. Is this a bug?

robloach’s picture

That looks great!

Also, I had to run "drush composer install" form the LESS module directory, which seems to counter intuitive when dealing with Drush. Is this a bug?

It's not require to do this once composer.json is committed and in a release. A composer installation is run when drush dl less is executed when it finds a composer.json file.

We've also been playing around with the idea of a #1452984: drush composer-mass install, which would go though each module and run a composer install from all their directories. Would love your thoughts on that.

corey.aufang’s picture

This should be in the latest dev.

Will be pushing new version soon.

corey.aufang’s picture

Status: Needs review » Fixed

Forgot to mark as mixed.

robloach’s picture

mixed indeed!

robloach’s picture

StatusFileSize
new33.42 KB

Thanks a lot! It's working :-) .

less-composer.png

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 9cac362 on 7.x-2.x, 7.x-3.x, 7.x-4.x by corey.aufang:
    by pirog, robloach, corey.aufang: [#1624970] fix issue with wrong...