# Template file for 'pnpm'
pkgname=pnpm
version=5.9.3
revision=1
# We won't use wrksrc, but it's needed to silence "cannot access wrksrc directory" error
create_wrksrc=yes
build_style=meta
hostmakedepends="nodejs jq"
depends="nodejs>=10.14"
short_desc="Fast, disk space efficient package manager"
maintainer="reback00 <reback00@protonmail.com>"
license="MIT"
homepage="https://pnpm.js.org/"
distfiles="https://registry.npmjs.org/${pkgname}/-/${pkgname}-${version}.tgz"
checksum=1bf71590e5408dea53ef21861d22b8e69e6da3b5b0340c340994b846328bb603
skip_extraction="${pkgname}-${version}.tgz"
python_version=3

do_install() {
	npm install -g --user root --prefix "${DESTDIR}/usr" "${XBPS_SRCDISTDIR}/${pkgname}-${version}/${pkgname}-${version}.tgz"
	local _npmdir="${DESTDIR}/usr/lib/node_modules/${pkgname}"

	# Sort and cleanup package.json
	local tmppackage="$(mktemp)"
	jq '.|=with_entries(select(.key|test("_.+")|not))' "$_npmdir/package.json" > "$tmppackage"
	mv "$tmppackage" "$_npmdir/package.json"
	chmod 644 "$_npmdir/package.json"

	# Delete JS SourceMaps
	find "${DESTDIR}/usr/lib" -depth -name '*.map' -delete

	vlicense "$_npmdir/LICENSE"
	vdoc "$_npmdir/README.md"
	rm -rf "${DESTDIR}/usr/etc" "$_npmdir/LICENSE" "$_npmdir/README.md"
}
