Skip to content

Commit

Permalink
Issue #2673: switch to CSS::Minifier::XS
Browse files Browse the repository at this point in the history
Comments which contain copyright are preserved, which is fine.
  • Loading branch information
bschmalhofer committed Nov 17, 2023
1 parent cce1bcb commit be8b34e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 33 deletions.
5 changes: 0 additions & 5 deletions COPYING-Third-Party
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ o Name: CPAN JSON::PP
License: GNU v2 - http://www.gnu.org/licenses/gpl.html
Note: Copyright 2007-2009 by Makamaka Hannyaharamitu

o Name: CPAN CSS::Minifier
Web: n/a
License: GNU v2 - http://www.gnu.org/licenses/gpl.html
Note: Copyright (C) 2007 by Peter Michaux

o Name: CPAN YAML
Web: n/a
License: GNU v2 - http://www.gnu.org/licenses/gpl.html
Expand Down
5 changes: 0 additions & 5 deletions Kernel/System/Environment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,6 @@ sub BundleModulesDeclarationGet {
'Required' => 1,
'VersionExact' => '0.14',
},
{
'Module' => 'CSS::Minifier',
'Required' => 1,
'VersionExact' => '0.01',
},
{
'Comment' => 'needed by Kernel::System::CheckItem',
'Module' => 'Email::Valid',
Expand Down
15 changes: 3 additions & 12 deletions Kernel/System/Loader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use utf8;
# core modules

# CPAN modules
use CSS::Minifier qw();
use CSS::Minifier::XS qw();
use JavaScript::Minifier::XS qw();

# OTOBO modules
Expand Down Expand Up @@ -409,20 +409,11 @@ sub MinifyCSS {
Priority => 'error',
Message => 'Need Code Param!',
);

return;
}

my $Result = CSS::Minifier::minify( input => $Param{Code} );

# a few optimizations can be made for the minified CSS that CSS::Minifier doesn't yet do

# remove remaining linebreaks
$Result =~ s/\r?\n\s*//smxg;

# remove superfluous whitespace after commas in chained selectors
$Result =~ s/,\s*/,/smxg;

return $Result;
return CSS::Minifier::XS::minify( $Param{Code} );
}

=head2 MinifyJavaScript()
Expand Down
2 changes: 0 additions & 2 deletions Kernel/cpan-lib/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ requires 'Crypt::PasswdMD5', "== 1.40";
# needed by Math::Random::Secure, needed in Kernel::System::Main
requires 'Crypt::Random::Source', "== 0.14";

requires 'CSS::Minifier', "== 0.01";

# needed by Kernel::System::CheckItem
requires 'Email::Valid', "== 1.202";

Expand Down
12 changes: 12 additions & 0 deletions bin/otobo.CheckModules.pl
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ =head1 DESCRIPTION
},
],
},
{
Module => 'CSS::Minifier::XS',
Required => 1,
VersionRequired => '0.09', # released in 2013
Comment => 'A CSS minifier written in XS',
InstTypes => {
aptget => 'libcss-minifier-xs-perl',
emerge => 'dev-perl/CSS-Minifier-XS',
zypper => 'perl-CSS-Minifier-XS',
ports => 'textproc/p5-CSS-Minifier-XS',
},
},
{
Module => 'Convert::BinHex',
Required => 1,
Expand Down
3 changes: 3 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ requires 'Date::Format';

requires 'DateTime', ">= 1.08";

# A CSS minifier written in XS
requires 'CSS::Minifier::XS', ">= 0.09";

requires 'Convert::BinHex';

requires 'DBI';
Expand Down
3 changes: 3 additions & 0 deletions cpanfile.docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ requires 'Date::Format';

requires 'DateTime', ">= 1.08";

# A CSS minifier written in XS
requires 'CSS::Minifier::XS', ">= 0.09";

requires 'Convert::BinHex';

requires 'DBI';
Expand Down
14 changes: 6 additions & 8 deletions scripts/test/Loader.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,17 @@ my $Home = $ConfigObject->Get('Home');
my $CSS = $MainObject->FileRead(
Location => "$Home/scripts/test/sample/Loader/OTOBO.Reset.css",
);

$CSS = $CSS->$*;

my $ExpectedCSS = $MainObject->FileRead(
Location => "$Home/scripts/test/sample/Loader/OTOBO.Reset.min.css",
);

$ExpectedCSS = ${$ExpectedCSS};
$ExpectedCSS = $ExpectedCSS->$*;
chomp $ExpectedCSS;

my $MinifiedCSS = $LoaderObject->MinifyCSS( Code => $CSS );

is( $MinifiedCSS || '', $ExpectedCSS, 'MinifyCSS()' );
is( $MinifiedCSS, $ExpectedCSS, 'MinifyCSS()' );

# empty cache
$Kernel::OM->Get('Kernel::System::Cache')->CleanUp(
Expand Down Expand Up @@ -101,9 +99,9 @@ my $Home = $ConfigObject->Get('Home');
my $ExpectedJS = $MainObject->FileRead(
Location => "$Home/scripts/test/sample/Loader/OTOBO.Agent.App.Login.min.js",
);
$ExpectedJS = ${$ExpectedJS};
$ExpectedJS = $ExpectedJS->$*;
$ExpectedJS =~ s{\r\n}{\n}xmsg;
$ExpectedJS =~ s{\n$}{}; # newline after the last line
chomp $ExpectedJS; # newline after the last line

is( $MinifiedJS, $ExpectedJS, 'MinifyJavaScript()' );
}
Expand Down Expand Up @@ -142,14 +140,14 @@ my $Home = $ConfigObject->Get('Home');
my $MinifiedJS = $MainObject->FileRead(
Location => $Location
);
$MinifiedJS = ${$MinifiedJS};
$MinifiedJS = $MinifiedJS->$*;
$MinifiedJS =~ s{\r\n}{\n}xmsg;
chomp $MinifiedJS;

my $Expected = $MainObject->FileRead(
Location => "$Home/scripts/test/sample/Loader/CombinedJavaScript.min.js",
);
$Expected = ${$Expected};
$Expected = $Expected->$*;
$Expected =~ s{\r\n}{\n}xmsg;
$Expected =~ s{\n$}{}; # newline after the last line

Expand Down
15 changes: 14 additions & 1 deletion scripts/test/sample/Loader/OTOBO.Reset.min.css

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

0 comments on commit be8b34e

Please sign in to comment.