# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Felix Yan <felixonmars@archlinux.org>

pkgname=nodejs-lts-iron
pkgver=20.19.5
pkgrel=3
pkgdesc="Evented I/O for V8 javascript (LTS release: Iron)"
arch=(x86_64 aarch64)
url="https://nodejs.org/"
license=(MIT)
# maybe revert back to openssl-1.1 or internal openssl
# https://github.com/nodejs/node/issues/47852
depends=(openssl zlib icu libuv c-ares brotli libnghttp2) # http-parser v8)
makedepends=(python procps-ng)
optdepends=('npm: nodejs package manager')
options=(!lto)
provides=("nodejs=$pkgver")
conflicts=(nodejs)
source=(https://nodejs.org/dist/v${pkgver}/node-v${pkgver}.tar.xz)
# https://nodejs.org/download/release/latest-iron/SHASUMS256.txt.asc
sha256sums=('230c899f4e2489c4b8d2232edd6cc02f384fb2397c2a246a22e415837ee5da51')

_set_flags() {
  # /usr/lib/libnode.so uses malloc_usable_size, which is incompatible with fortification level 3
  CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
}

build() {
  _set_flags
  cd node-v${pkgver}

  ./configure \
    --prefix=/usr \
    --with-intl=system-icu \
    --without-corepack \
    --without-npm \
    --shared-openssl \
    --shared-zlib \
    --shared-libuv \
    --experimental-http-parser \
    --shared-brotli \
    --shared-cares \
    --shared-nghttp2
    # --shared-v8
    # --shared-http-parser

  make
}

check() {
  _set_flags
  cd node-v${pkgver}
  rm test/parallel/test-http2-client-set-priority.js
  rm test/parallel/test-http2-client-unescaped-path.js
  rm test/parallel/test-http2-max-invalid-frames.js
  rm test/parallel/test-http2-misbehaving-flow-control.js
  rm test/parallel/test-http2-misbehaving-flow-control-paused.js
  rm test/parallel/test-http2-multi-content-length.js
  rm test/parallel/test-http2-priority-event.js
  rm test/parallel/test-http2-reset-flood.js
  rm test/parallel/test-process-euid-egid.js
  rm test/parallel/test-process-initgroups.js
  rm test/parallel/test-process-setgroups.js
  rm test/parallel/test-process-uid-gid.js
  rm test/parallel/test-tls-ocsp-callback.js

  # https://github.com/nodejs/node/pull/60523
  rm test/parallel/test-datetime-change-notify.js

  rm test/parallel/test-http-client-close-with-default-agent.js

  # failing in CI
  rm test/parallel/test-fs-cp.mjs

  make test-only

}

package() {
  _set_flags
  cd node-v${pkgver}
  make DESTDIR="${pkgdir}" install
  install -Dm644 LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
