# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=yarn
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.22.22
pkgrel=1
pkgdesc="Fast, reliable, and secure dependency management (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://yarnpkg.com/"
msys2_references=(
  "cpe: cpe:/a:yarnpkg:yarn"
  "purl: pkg:npm/yarn"
)
license=("spdx:BSD-2-Clause")
depends=("${MINGW_PACKAGE_PREFIX}-nodejs")
source=("https://github.com/yarnpkg/${_realname}/releases/download/v${pkgver}/${_realname}-v${pkgver}.tar.gz"
        "0001-fhs.patch")
sha256sums=('88268464199d1611fcf73ce9c0a6c4d44c7d5363682720d8506f6508addf36a0'
            '1f85c997390a9a83305300883a5b8b97856f748fc5b21e7ed75d47cb1ba809f4')

prepare() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  patch -Np1 -i "${srcdir}/0001-fhs.patch"
}

package() {
  cd "${srcdir}/${_realname}-v${pkgver}"

  install -dm755  "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn
  cp -R * "${pkgdir}"/${MINGW_PREFIX}/lib/node_modules/yarn

  install -dm755 "${pkgdir}"/${MINGW_PREFIX}/bin
  cp bin/yarn "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarn.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg "${pkgdir}"/${MINGW_PREFIX}/bin/
  cp bin/yarnpkg.cmd "${pkgdir}"/${MINGW_PREFIX}/bin/

  install -Dm644 LICENSE "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 README.md "${pkgdir}/${MINGW_PREFIX}/share/doc/${_realname}/README.md"
}
