# Template file for 'esbuild'
pkgname=esbuild
version=0.28.0
revision=1
build_style=go
go_import_path=github.com/evanw/esbuild
go_package="./cmd/esbuild"
hostmakedepends="nodejs"
checkdepends="pnpm yarn"
short_desc="Extremely fast bundler for the web"
maintainer="Luca Matei Pintilie <luca@lucamatei.com>"
license="MIT"
homepage="https://esbuild.github.io/"
changelog="https://github.com/evanw/esbuild/releases"
distfiles="https://github.com/evanw/esbuild/archive/refs/tags/v${version}.tar.gz"
checksum=7aae83b197db3fd695e6f378d30fd6cbddeb93e4b1057b2c41d36ecb1dfebbc2

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" esbuild"
fi

post_build() {
	node scripts/esbuild.js npm/esbuild/package.json --version
	if [ "$CROSS_BUILD" ]; then
		node scripts/esbuild.js /usr/bin/esbuild --neutral
	else
		node scripts/esbuild.js "$GOPATH/bin/esbuild" --neutral
	fi
	vsed -e '1s#^#var ESBUILD_BINARY_PATH = "/usr/bin/esbuild";\n#' \
		-i npm/esbuild/lib/main.js
}

do_check() {
	# Skip test-deno (deno not packaged) and decorator-tests (not in a git
	# repo) and test-wasm-node (exec fail) and end-to-end-tests (fails on
	# musl) and js-api-tests (fails in CI)
	make test-go vet-go no-filepath verify-source-map plugin-tests register-test node-unref-tests ts-type-tests lib-typecheck-node lib-typecheck-node-nolib
}

post_install() {
	vlicense LICENSE.md

	vinstall npm/esbuild/package.json 644 usr/lib/node_modules/esbuild
	vmkdir usr/lib/node_modules/esbuild/lib
	vcopy "npm/esbuild/lib/*" usr/lib/node_modules/esbuild/lib
	vmkdir usr/lib/node_modules/esbuild/bin
	ln -s /usr/bin/esbuild "${DESTDIR}"/usr/lib/node_modules/esbuild/bin/esbuild
}
