Skip to content

Commit

Permalink
use JSqueeze instead of JSMin (owncloud#13052)
Browse files Browse the repository at this point in the history
The JSMin minifier is non-free. JSqueeze is free, it's also a
currently-maintained project following good development
practices, and the best-performing minifier we tested. This
requires a corresponding 3rdparty commit to drop mrclay/minify
and add JSqueeze, and also uses a backport of the latest
upstream version of the Assetic JSqueeze filter as the current
version in 1.2 does not work with JSqueeze 2.x. The backported
filter file can be dropped when our bundled copy of Assetic is
updated to a version containing the newer JSqueezeFilter.
  • Loading branch information
AdamWill committed Jan 10, 2015
1 parent 19b7911 commit 6c1a920
Showing 2 changed files with 97 additions and 2 deletions.
95 changes: 95 additions & 0 deletions lib/private/assetic/jsqueeze2filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

/**
* ownCloud
*
* Copyright (C) 2014 Robin McCorkell <rmccorkell@karoshi.org.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
/**
* This file is just a copy of Assetic's JSqueezeFilter following
* https://github.com/kriswallsmith/assetic/pull/698, with the class
* renamed to JSqueeze2Filter, namespace changed, and use statements
* adjusted. It can be dropped as soon as OC's bundled Assetic is updated
* to a version containing the JSqueezeFilter that works with JSqueeze 2.x.
*/

namespace OC\Assetic;

use Assetic\Filter\FilterInterface;
use Assetic\Asset\AssetInterface;

/**
* JSqueeze filter.
*
* @link https://github.com/nicolas-grekas/JSqueeze
* @author Nicolas Grekas <p@tchwork.com>
*/
class JSqueeze2Filter implements FilterInterface
{
private $singleLine = true;
private $keepImportantComments = true;
private $className;
private $specialVarRx = false;
private $defaultRx;

function __construct() {
// JSqueeze is namespaced since 2.x, this works with both 1.x and 2.x
if (class_exists('\\Patchwork\\JSqueeze')) {
$this->className = '\\Patchwork\\JSqueeze';
$this->defaultRx = \Patchwork\JSqueeze::SPECIAL_VAR_PACKER;
} else {
$this->className = '\\JSqueeze';
$this->defaultRx = \JSqueeze::SPECIAL_VAR_RX;
}
}

public function setSingleLine($bool)
{
$this->singleLine = (bool) $bool;
}

// call setSpecialVarRx(true) to enable global var/method/property
// renaming with the default regex (for 1.x or 2.x)
public function setSpecialVarRx($specialVarRx)
{
if (true === $specialVarRx) {
$this->specialVarRx = $this->defaultRx;
} else {
$this->specialVarRx = $specialVarRx;
}
}

public function keepImportantComments($bool)
{
$this->keepImportantComments = (bool) $bool;
}

public function filterLoad(AssetInterface $asset)
{
}

public function filterDump(AssetInterface $asset)
{
$parser = new $this->className();
$asset->setContent($parser->squeeze(
$asset->getContent(),
$this->singleLine,
$this->keepImportantComments,
$this->specialVarRx
));
}
}
4 changes: 2 additions & 2 deletions lib/private/templatelayout.php
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
use Assetic\Filter\CssImportFilter;
use Assetic\Filter\CssMinFilter;
use Assetic\Filter\CssRewriteFilter;
use Assetic\Filter\JSMinFilter;
use OC\Assetic\JSqueeze2Filter; // see note in jsqueeze2filter.php
use OC\Assetic\SeparatorFilter; // waiting on upstream

/**
@@ -170,7 +170,7 @@ public function generateAssets() {
), $root, $file);
}
return new FileAsset($root . '/' . $file, array(
new JSMinFilter(),
new JSqueeze2Filter(),
new SeparatorFilter(';')
), $root, $file);
}, $jsFiles);

0 comments on commit 6c1a920

Please sign in to comment.