# Contributor: Hygna <hygna@proton.me>
# Contributor: Fabricio Silva <hi@fabricio.dev>
maintainer="Fabricio Silva <hi@fabricio.dev>"
pkgname=pnpm
pkgver=10.9.0
pkgrel=0
pkgdesc="Fast, disk space efficient package manager"
url="https://pnpm.io"
arch="noarch"
license="MIT"
depends="nodejs"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
source="https://registry.npmjs.org/pnpm/-/pnpm-$pkgver.tgz
	0001-no-check-for-updates.patch
	0002-no-self-update.patch
	"
builddir="$srcdir/package"

prepare() {
	default_prepare

	# remove node-gyp
	rm -rf dist/node-gyp-bin dist/node_modules/node-gyp
	# remove windows files
	rm -rf dist/vendor/*.exe

	# remove other unnecessary files
	find . -type f \( \
		-name '.*' -o \
		-name '*.cmd' -o \
		-name '*.bat' -o \
		-name '*.map' -o \
		-name '*.md' -o \
		-name '*.darwin*' -o \
		-name '*.win*' -o \
		-iname 'README*' \) -delete
}

check() {
	./bin/pnpm.cjs --help
}

package() {
	local destdir="$pkgdir"/usr/share/node_modules/$pkgname

	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname

	install -Dm644 dist/templates/completion.bash \
		"$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 dist/templates/completion.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_$pkgname
	install -Dm644 dist/templates/completion.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish

	install -Dm644 package.json -t "$destdir"
	install -Dm755 bin/pnpm.cjs bin/pnpx.cjs -t "$destdir"/bin
	cp -r dist "$destdir"/dist

	mkdir -p "$pkgdir"/usr/bin
	ln -sf ../share/node_modules/pnpm/bin/pnpm.cjs "$pkgdir"/usr/bin/pnpm
	ln -sf ../share/node_modules/pnpm/bin/pnpx.cjs "$pkgdir"/usr/bin/pnpx
}

sha512sums="
0486e394640d3c1fb3c9d43d49cf92879ff74f8516959c235308f5a8f62e2e19528a65cdc2a3058f587cde71eba3d5b56327c8c33a97e4c4051ca48a10ca2d5f  pnpm-10.9.0.tgz
f53903c506a676393dd8b31e1194b92612bfa877a8e17edc530e308921caf454248e181a3e620a17a941eba126349128963b2b0b1e48f8d927307c9cf335290e  0001-no-check-for-updates.patch
5582d11fcd1782f40a4f9269b477af25057e3a3d60cddef8b64a8592fafdc7a572822c8267a7abf9e8bfa4b726dcb291885642070a838e360fc542cee10c9569  0002-no-self-update.patch
"
