Skip to content

Commit

Permalink
Item14874: Deprecate old compressors
Browse files Browse the repository at this point in the history
for js: use terser, at least uglify-js, warn on all others
for css: use cssmin, warn on all others
  • Loading branch information
MichaelDaum committed Nov 18, 2019
1 parent 340725b commit 077d833
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 40 deletions.
2 changes: 1 addition & 1 deletion BuildContrib/create_new_extension.pl
Expand Up @@ -3,7 +3,7 @@
#
# Author: Crawford Currie http://c-dot.co.uk
#
# Copyright (C) 2008-2013 FoswikiContributors. All rights reserved.
# Copyright (C) 2008-2019 FoswikiContributors. All rights reserved.
# FoswikiContributors are listed in the AUTHORS file in the root of
# the distribution.
#
Expand Down
18 changes: 9 additions & 9 deletions BuildContrib/data/System/BuildContrib.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1512466074" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1573735696" format="1.1" version="1"}%
%META:TOPICPARENT{name="Contribs"}%
---+!! Foswiki Developer Environment
<img src="%ATTACHURLPATH%/logo.gif" alt="WikiRing" class="foswikiRight" />
Expand Down Expand Up @@ -178,14 +178,14 @@ Usually only used if your extension includes Javascript or CSS, this target
to generate another that is functionally identical, but smaller for faster
download. It will search for an avaliable minifier:

* [[https://npmjs.org/package/uglify-js][UglifyJS]] *Recommended*
* [[http://www.yuiblog.com/blog/2012/10/16/state-of-yui-compressor/][yuicompressor]]
* CPAN:JavaScript::Minifier and CPAN:CSS::Minifier
* [[https://npmjs.org/package/terser][terser]] *Recommended*
* [[https://npmjs.org/package/uglify-js][uglifyjs]]
* [[https://npmjs.org/package/cssmin][cssmin]]

To make the recommended compressor avaliable on your system, first install
[[http://nodejs.org/][Node.js]], and then use "npm" to install the
compressors: =npm install -g uglifyjs= and =npm install -g cssmin=
This will install both uglify and !MinCSS.
compressors: =npm install -g terser= and =npm install -g cssmin=
This will install both terser and !MinCSS.

The compression can work with a number of different naming schemes, depending
on what files you refer to in your MANIFEST. For example, the name mappings
Expand Down Expand Up @@ -657,11 +657,11 @@ Another great Foswiki extension from the <img src="%ATTACHURLPATH%/wikiringlogo2
See the repository for full change history.


%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" comment="" date="1512466074" size="1343" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attr="" comment="logo" date="1512466074" size="14169" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" comment="" date="1573735696" size="1343" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attr="" comment="logo" date="1573735696" size="14169" user="ProjectContributor" version="1"}%
%META:FORM{name="PackageForm"}%
%META:FIELD{name="Author" title="Author" value="[[http://c-dot.co.uk][Crawford Currie]]"}%
%META:FIELD{name="Copyright" title="Copyright" value="Foswiki Contributors 2004-2015, All Rights Reserved"}%
%META:FIELD{name="Copyright" title="Copyright" value="Foswiki Contributors 2004-2019, All Rights Reserved"}%
%META:FIELD{name="Description" title="Description" value="%25$SHORTDESCRIPTION%25"}%
%META:FIELD{name="Home" title="Home" value="http://foswiki.org/Extensions/BuildContrib"}%
%META:FIELD{name="License" title="License" value="GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]])"}%
Expand Down
2 changes: 1 addition & 1 deletion BuildContrib/lib/Foswiki/Contrib/Build.pm
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2014 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2014 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
4 changes: 2 additions & 2 deletions BuildContrib/lib/Foswiki/Contrib/BuildContrib.pm
@@ -1,8 +1,8 @@
package Foswiki::Contrib::BuildContrib;
use strict;

our $VERSION = '1.91';
our $RELEASE = '12 Dec 2017';
our $VERSION = '2.00';
our $RELEASE = '14 Nov 2019';

our $SHORTDESCRIPTION =
'Automates build and packaging process, including installer generation, for extension modules.';
Expand Down
1 change: 1 addition & 0 deletions BuildContrib/lib/Foswiki/Contrib/BuildContrib/BaseBuild.pm
@@ -1,5 +1,6 @@
#
# Copyright (C) 2004 C-Dot Consultants - All rights reserved
# Copyright (C) 2004-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
Expand Up @@ -2,7 +2,7 @@
#
# Install script for %$MODULE%
#
# Copyright (C) 2004-2015 Foswiki Contributors. All Rights Reserved.
# Copyright (C) 2004-2019 Foswiki Contributors. All Rights Reserved.
# Foswiki Contributors are listed in the AUTHORS file in the root of
# this distribution. NOTE: Please extend that file, not this notice.
#
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
Expand Up @@ -131,7 +131,7 @@ HERE
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2019 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Expand Down
65 changes: 56 additions & 9 deletions BuildContrib/lib/Foswiki/Contrib/BuildContrib/Targets/compress.pm
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -62,7 +62,14 @@ sub target_compress {
sub _build_js {
my ( $this, $to ) = @_;

# First try uglify
if ( !$minifiers{js} ) {
if ( $this->_haveterser() ) {
$minifiers{js} = sub {
return $this->_terser( @_, 'js' );
};
}
}

if ( !$minifiers{js} ) {
if ( $this->_haveuglifyjs() ) {
$minifiers{js} = sub {
Expand All @@ -72,6 +79,7 @@ sub _build_js {
}

if ( !$minifiers{js} ) {
warn "WARNING: yuicompressor is deprecated. please install terser.\n";
my $yui = $this->_haveYUI();

if ($yui) {
Expand All @@ -83,11 +91,15 @@ sub _build_js {

# If no good, try the CPAN minifiers
if ( !$minifiers{js} && eval { require JavaScript::Minifier::XS; 1 } ) {
warn
"WARNING: JavaScript::Minifier::XS is deprecated. please install terser.\n";
$minifiers{js} = sub {
return $this->_cpanMinify( @_, \&JavaScript::Minifier::XS::minify );
};
}
if ( !$minifiers{js} && eval { require JavaScript::Minifier; 1 } ) {
warn
"WARNING: JavaScript::Minifier is deprecated. please install terser.\n";
$minifiers{js} = sub {
return $this->_cpanMinify(
@_,
Expand All @@ -97,10 +109,6 @@ sub _build_js {
);
};
}
if ( !$minifiers{js} ) {
warn "Cannot squish $to: no minifier found\n";
return;
}

return $this->_build_compress( 'js', $to );
}
Expand All @@ -115,7 +123,6 @@ sub _build_js {
sub _build_css {
my ( $this, $to ) = @_;

# First try cssmin
if ( !$minifiers{css} ) {
if ( $this->_havecssmin() ) {
$minifiers{css} = sub {
Expand All @@ -125,6 +132,7 @@ sub _build_css {
}

if ( !$minifiers{css} ) {
warn "WARNING: yuicompressor is deprecated. please install cssmin.\n";
my $yui = $this->_haveYUI();

if ($yui) {
Expand All @@ -134,11 +142,14 @@ sub _build_css {
}
}
if ( !$minifiers{css} && eval { require CSS::Minifier::XS; 1 } ) {
warn
"WARNING: CSS::Minifier::XS is deprecated. please install cssmin.\n";
$minifiers{css} = sub {
return $this->_cpanMinify( @_, \&CSS::Minifier::XS::minify );
};
}
if ( !$minifiers{css} && eval { require CSS::Minifier; 1 } ) {
warn "WARNING: CSS::Minifier is deprecated. please install cssmin.\n";
$minifiers{css} = sub {
$this->_cpanMinify(
@_,
Expand Down Expand Up @@ -194,7 +205,7 @@ sub _build_compress {
my ( $this, $type, $to ) = @_;

if ( !$minifiers{$type} ) {
warn "Cannot squish $to: no minifier found for $type\n";
warn "ERROR: Cannot squish $to: no minifier found for $type\n";
return;
}

Expand Down Expand Up @@ -342,6 +353,23 @@ sub _cssmin {
return $out;
}

sub _terser {
my ( $this, $from, $to ) = @_;
my $lcall = $ENV{'LC_ALL'};
my $cmd;

$cmd = "terser -m -c -- $from";

unless ( $this->{-n} ) {
$cmd .= " > $to";
}

warn "$cmd\n";
my $out = `$cmd`;
$ENV{'LC_ALL'} = $lcall;
return $out;
}

sub _uglifyjs {
my ( $this, $from, $to ) = @_;
my $lcall = $ENV{'LC_ALL'};
Expand Down Expand Up @@ -389,8 +417,27 @@ sub _haveYUI {

=begin TML
---++++ _haveterser
return 1 if we have terser as a command
=cut

sub _haveterser {
my $this = shift;
my $info = `echo ''|terser 2>&1`;
my $result = 0;

if ( not $? ) {
$result = 1;
}

return $result;
}

=begin TML
---++++ _haveuglifyjs
return 1 if we have uglify as a command uglify
return 1 if we have uglifyjs as a command
=cut

Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2014 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2012 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2010 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
@@ -1,6 +1,6 @@
#
# Copyright (C) 2004-2015 C-Dot Consultants - All rights reserved
# Copyright (C) 2008-2015 Foswiki Contributors
# Copyright (C) 2008-2019 Foswiki Contributors
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down

0 comments on commit 077d833

Please sign in to comment.