Skip to content

Commit

Permalink
Boost: Update minify-library (#37728)
Browse files Browse the repository at this point in the history
* Don't minify files that already has a .min extension

* changelog

* Swap JS minification library

* Fix

* Don't require the previously used library

* Fix expected output in test
  • Loading branch information
haqadn authored Jun 6, 2024
1 parent d74c4fa commit 499212a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 30 deletions.
7 changes: 3 additions & 4 deletions projects/plugins/boost/app/lib/class-minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Automattic\Jetpack_Boost\Lib;

use JShrink\Minifier as JSMinifier;
use MatthiasMullie\Minify\JS as JSMinifier;
use tubalmartin\CssMin\Minifier as CSSMinifier;

/**
Expand All @@ -30,10 +30,9 @@ class Minify {
* @return string String with whitespace stripped.
*/
public static function js( $js ) {
require_once JETPACK_BOOST_DIR_PATH . '/vendor/tedivm/jshrink/src/JShrink/Minifier.php';

try {
$minified_js = JSMinifier::minify( $js );
$minifier = new JSMinifier( $js );
$minified_js = $minifier->minify();
} catch ( \Exception $e ) {
return $js;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/boost/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"automattic/jetpack-status": "@dev",
"automattic/jetpack-sync": "@dev",
"automattic/jetpack-wp-js-data-sync": "@dev",
"tedivm/jshrink": "1.4.0",
"matthiasmullie/minify": "^1.3",
"tubalmartin/cssmin": "^4.1"
},
"require-dev": {
Expand Down
116 changes: 92 additions & 24 deletions projects/plugins/boost/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/boost/tests/php/lib/test-class-minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function test_js() {
var two = "two";
var three = "three";';

$minified_js = 'var one="one";var two="two";var three="three";';
$minified_js = 'var one="one";var two="two";var three="three"';

$this->assertEquals( $minified_js, Minify::js( $expanded_js ) );
}
Expand Down

0 comments on commit 499212a

Please sign in to comment.