%{?nodejs_find_provides_and_requires}

Name:           uglify-js
Version:        2.8.22
Release:        1%{?dist}
Summary:        JavaScript parser, mangler/compressor and beautifier toolkit
License:        BSD
URL:            https://github.com/mishoo/UglifyJS2
Source0:        https://github.com/mishoo/UglifyJS2/archive/v%{version}/uglify-js-%{version}.tar.gz
Patch0:         uglify-js-esfuzz.patch
BuildArch:      noarch
ExclusiveArch:  %{nodejs_arches} noarch
Provides:       nodejs-uglify-js = %{version}-%{release}
BuildRequires:  nodejs-packaging
BuildRequires:  web-assets-devel

Requires: js-uglify = %{version}-%{release}

%description
JavaScript parser, mangler/compressor and beautifier toolkit.

This package ships the uglifyjs command-line tool and a library suitable for
use within Node.js.

%package -n js-uglify
Summary: JavaScript parser, mangler/compressor and beautifier toolkit - core library

Obsoletes: uglify-js-common < 2.2.5-4
Provides: uglify-js-common = %{version}-%{release}

%if 0%{?fedora}
Requires: web-assets-filesystem
%endif

%description -n js-uglify
JavaScript parser, mangler/compressor and beautifier toolkit.

This package ships a JavaScript library suitable for use by any JavaScript
runtime.

%prep
%autosetup -p 1 -n UglifyJS-%{version}

%nodejs_fixdep async "^1.5.0"
%nodejs_fixdep yargs "^3.2.1"


%build
#nothing to do


%install
rm -rf %buildroot

mkdir -p %{buildroot}%{_jsdir}/%{name}-2
cp -pr lib/* %{buildroot}%{_jsdir}/%{name}-2
ln -sf %{name}-2 %{buildroot}%{_jsdir}/%{name}

#compat symlink
mkdir -p %{buildroot}%{_datadir}
ln -sf javascript/%{name} %{buildroot}%{_datadir}/%{name}

mkdir -p %{buildroot}%{nodejs_sitelib}/uglify-js@2
cp -pr bin tools package.json %{buildroot}%{nodejs_sitelib}/uglify-js@2
ln -sf %{_jsdir}/%{name} %{buildroot}%{nodejs_sitelib}/uglify-js@2/lib
# Fix for rpmlint.
sed -i -e 's|^#! */usr/bin/env node|#!/usr/bin/node|' \
  %{buildroot}%{nodejs_sitelib}/uglify-js@2/bin/*

mkdir -p %{buildroot}%{_bindir}
ln -sf ../lib/node_modules/uglify-js@2/bin/uglifyjs %{buildroot}%{_bindir}/uglifyjs

%nodejs_symlink_deps

ln -sf uglify-js@2 %{buildroot}%{nodejs_sitelib}/uglify-js


%pretrans -p <lua>
st = posix.stat("%{nodejs_sitelib}/uglify-js")
if st and st.type == "directory" then
  os.execute("rm -rf %{nodejs_sitelib}/uglify-js")
end


%pretrans -n js-uglify -p <lua>
st = posix.stat("%{_datadir}/%{name}")
if st and st.type == "directory" then
  os.execute("rm -rf %{_datadir}/%{name}")
end


%files
%{nodejs_sitelib}/uglify-js
%{nodejs_sitelib}/uglify-js@2
%{_bindir}/uglifyjs


%files -n js-uglify
%{_jsdir}/%{name}-2
%{_jsdir}/%{name}
%{_datadir}/%{name}
%doc README.md
%license LICENSE


%changelog
