Skip to content

Commit

Permalink
[mms] If compressing/packaging javascript files, don't use pre-compre…
Browse files Browse the repository at this point in the history
…ssed version (if one exists) when generating.

2 reasons:

- Compressed versions may use advanced JS "tricks" that breaks the
  compression binary
- We needed the uncompressed source to create a useful sourcemap
  • Loading branch information
slusarz committed Jan 13, 2015
1 parent e9a39df commit 3b9f846
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
22 changes: 19 additions & 3 deletions framework/Core/lib/Horde/Script/Compress.php
Expand Up @@ -147,13 +147,29 @@ public function __get($name)
public function getMinifier($scripts, $sourcemap = null)
{
$js_files = array();

foreach ($scripts as $val) {
switch ($this->_driver) {
case 'Horde_JavascriptMinify_Null':
break;

default:
$val = $val->uncompressed;
break;
}

$js_files[strval($val->url_full)] = $val->full_path;
}

return new $this->_driver($js_files, array_merge($this->_params, array(
'sourcemap' => $sourcemap
)));
return new $this->_driver(
$js_files,
array_merge(
$this->_params,
array(
'sourcemap' => $sourcemap
)
)
);
}

}
6 changes: 6 additions & 0 deletions framework/Core/lib/Horde/Script/File.php
Expand Up @@ -29,6 +29,9 @@
* @property integer $priority Script priority
* @property-read string $tag HTML script tag to relative URL.
* @property-read string $tag_full HTML script tag to full URL.
* @property-read Horde_Script_File $uncompressed Return the object
* representing the
* uncompressed script.
* @property-read Horde_Url $url URL to script.
* @property-read Horde_Url $url_full Full URL to script.
*/
Expand Down Expand Up @@ -125,6 +128,9 @@ public function __get($name)
(($name == 'tag') ? $this->url : $this->url_full) .
'"></script>';

case 'uncompressed':
return $this;

case 'url':
case 'url_full':
return $this->_url($this->_file, ($name == 'url_full'));
Expand Down
10 changes: 10 additions & 0 deletions framework/Core/lib/Horde/Script/File/JsDir.php
Expand Up @@ -31,6 +31,16 @@ public function __get($name)
case 'path':
return $GLOBALS['registry']->get('jsfs', $this->_app) . '/';

case 'uncompressed':
if (($pos = strripos($this->file, '.min.js')) !== false) {
$cname = get_class();
return new $cname(
substr($this->file, 0, $pos) . '.js',
$this->app
);
}
break;

case 'url':
case 'url_full':
return $this->_url($GLOBALS['registry']->get('jsuri', $this->_app) . '/' . $this->_file, ($name == 'url_full'));
Expand Down
4 changes: 2 additions & 2 deletions framework/Core/package.xml
Expand Up @@ -39,7 +39,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] If compressing/packaging javascript files, don&apos;t use pre-compressed version (if one exists) when generating.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -3814,7 +3814,7 @@
<date>2015-01-08</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] If compressing/packaging javascript files, don&apos;t use pre-compressed version (if one exists) when generating.
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 3b9f846

Please sign in to comment.