Debian solving Drupal's third-party library challenge

The tremendously successful Drupal community observes stringent requirements about many things, in particular, licensing and the prohibition of bundling third-party JavaScript.

While these policies may seem onerous at first glance, it turns out there is another project with a written guarantee to provide third-party code in a form that meets the expectations of Drupal and does so in a way that completely automates all that tedious effort into one-click oblivion. I'm talking about the Debian GNU/Linux operating system.

Drupal's libraries module

The libraries module for Drupal appeared as an initial attempt to help track third-party JavaScript.

The module has been available in Debian for almost a year and has recently been provided in the wheezy-backports distribution for people running the stable version of Debian.

The library provides a standard way for other modules to reference third-party JavaScript but it still leaves the web master with some manual work to go out and download all the necessary JavaScript and copy it into the right place. This is where Debian comes to the rescue.

Using the module in practice

I've recently uploaded JSCommunicator to Debian and wanted to provide a convenient way for people to get it in Drupal.

Therefore, in addition to providing the JSCommunicator packages, I created an extra package, drupal7-mod-jscommunicator.

JSCommunicator itself depends on other JavaScript, specifically, the JsSIP library. I repeated the same process for JsSIP. This gives us the following collection of four related packages:

Third-party library Library itself Drupal module, packaged
JSCommunicator libjs-jscommunicator drupal7-mod-jscommunicator
JsSIP libjs-jssip drupal7-mod-jssip

If you explore the package details in Debian's package catalog you will notice that each package depends on the other packages it requires.

Debian's package management utility, apt-get, can transitively resolve all the relationships between this set of packages. In fact, on a newly built server, you can simply run the command:

apt-get install drupal7-mod-jscommunicator

and the apt-get utility will install Apache, MySQL, Drupal itself, the libraries module, all the related JavaScript libraries and the final Drupal module of JSCommunicator itself. It really is that easy. Here is an example of the output displayed by the command on a freshly built server:

# apt-get -d install drupal7-mod-jscommunicator
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  apache2 apache2-bin apache2-data curl dbconfig-common drupal7
  drupal7-mod-jssip drupal7-mod-libraries fontconfig-config fonts-dejavu-core
  javascript-common libaio1 libapache2-mod-php5 libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap libarchive-extract-perl libc6
  libcurl3 libdbd-mysql-perl libdbi-perl libedit2 libfontconfig1 libgcrypt11
  libgd3 libhtml-template-perl libjbig0 libjpeg8 libjs-jssip libjson-c2
  liblocale-gettext-perl liblog-message-simple-perl liblua5.1-0
  libmodule-pluggable-perl libmysqlclient18 libonig2 libperl4-corelibs-perl
  libpng12-0 libpod-latex-perl libqdbm14 librtmp0 libssh2-1 libterm-ui-perl
  libtext-charwidth-perl libtext-iconv-perl libtext-soundex-perl libtiff5
  libuuid-perl libvpx1 libxml2 libxpm4 locales mysql-client mysql-client-5.5
  mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 perl
  perl-base perl-modules php5 php5-cli php5-common php5-gd php5-json
  php5-mysql php5-readline ssl-cert wwwconfig-common
Suggested packages:
  apache2-doc apache2-suexec-pristine apache2-suexec-custom apache2-utils
  php-pear glibc-doc libclone-perl libmldbm-perl libnet-daemon-perl
  libplrpc-perl libsql-statement-perl rng-tools libgd-tools
  libipc-sharedcache-perl libterm-readkey-perl tinyca perl-doc
  libterm-readline-gnu-perl libterm-readline-perl-perl make libb-lint-perl
  libcpanplus-dist-build-perl libcpanplus-perl libfile-checktree-perl
  liblog-message-perl libobject-accessor-perl php5-user-cache
  openssl-blacklist postgresql-client
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data curl dbconfig-common drupal7
  drupal7-mod-jscommunicator drupal7-mod-jssip drupal7-mod-libraries
  fontconfig-config fonts-dejavu-core javascript-common libaio1
  libapache2-mod-php5 libapr1 libaprutil1 libaprutil1-dbd-sqlite3
  libaprutil1-ldap libarchive-extract-perl libcurl3 libdbd-mysql-perl
  libdbi-perl libfontconfig1 libgd3 libhtml-template-perl libjbig0 libjpeg8
  libjs-jssip libjson-c2 liblog-message-simple-perl liblua5.1-0
  libmodule-pluggable-perl libmysqlclient18 libonig2 libperl4-corelibs-perl
  libpng12-0 libpod-latex-perl libqdbm14 librtmp0 libssh2-1 libterm-ui-perl
  libtext-soundex-perl libtiff5 libvpx1 libxpm4 mysql-client mysql-client-5.5
  mysql-common mysql-server mysql-server-5.5 mysql-server-core-5.5 php5
  php5-cli php5-common php5-gd php5-json php5-mysql php5-readline ssl-cert
  wwwconfig-common
The following packages will be upgraded:
  libc6 libedit2 libgcrypt11 liblocale-gettext-perl libtext-charwidth-perl
  libtext-iconv-perl libuuid-perl libxml2 locales perl perl-base perl-modules
12 upgraded, 60 newly installed, 0 to remove and 222 not upgraded.
Need to get 37.2 MB of archives.
After this operation, 152 MB of additional disk space will be used.
Do you want to continue [Y/n]? 

Libraries API in Drupal 8

Contrary to an earlier version of this blog, the libraries module is not joining the core in Drupal 8 however its use has been strongly encouraged for any new modules submitted through the Drupal community approval process. This means there will be further opportunity for Drupal users to consolidate on their use of Debian to completely automate the management of all third-party libraries and modules throughout their Drupal system(s).

Comments

I'm not sure why you think the Libraries API module is in Drupal 8 core?

Maybe because of the $element['#attached']['library'][] = array('', ''); code all across core? That already was part of Drupal 7, but not yet used consistently everywhere.

Libraries API exists to have a single way to incorporate external libraries into Drupal sites, but it's not the same as the above code example.

Yes, you are correct - some library-related functions are in core, just as in Drupal 7 but the full libraries API module remains a module. Even so, whenever Drupal 8 is packaged for Debian, I will make sure the matching library module package is also available for it.

Wouldn't it be better if drupal7-mod-* wasn't required at all? It seems to just include a tiny file which could easily be included elsewhere.

I hope Drupal doesn't need this for every other package it could depend-on (drupal7-mod-mysqlclient, ... ;) ).

Just imagine the alternatives: if the glue code (which is very tiny, no question about that) was included with the third-party package (e.g. in the libjs-jssip.deb package or in the libmysqlclient.deb package) then everybody who installed those packages would end up with some Drupal directories under /usr/share even if they don't use Drupal. On the other hand, if all this glue code was bundled up into Drupal itself then Drupal would suck in many more dependencies than it does now.

Disk space is however cheap. Cheaper than having to look after more packages.

But even just looking at disk space: shipping the file in libjs-* would only use disk space for people who have the package installed. Shipping an extra package, takes away disk space from people who don't have it installed (via the Packages indices).

If included in the drupal package itself, it would mean more dependencies, but then I assume drupal doesn't get installed on machines that starve for disk space.