# Copyright 1999-2026 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 inherit edo DESCRIPTION="Pythonic JavaScript that doesn't suck" HOMEPAGE="https://github.com/kovidgoyal/rapydscript-ng" # ::gentoo's 0.7.22 ships node_modules as a second, hand-rolled tarball hosted on # dev.gentoo.org, generated by running `npm install` in the live ebuild. That is # not reproducible from SRC_URI alone and nobody produced one for 0.8.x. # # It is also no longer necessary. 0.8.6 declares exactly one runtime dependency # (terser) and no devDependencies, so `npm install --omit=optional` resolves to # the eleven packages below -- measured, not guessed. Listing them as ordinary # distfiles keeps the whole build fetchable, mirrorable and hash-verified by # Portage, with no npm run at build time and no self-hosted blob. # # The optional dependency (v8-profiler) is deliberately absent: it drags in # node-pre-gyp, request and ~130 further packages, and rapydscript runs without # it. That is the same choice ::gentoo makes with --omit=optional. # # When bumping, regenerate this list rather than editing versions by hand: # npm install --omit=optional --ignore-scripts (in an extracted tarball) # then read the name/version out of every node_modules/*/package.json NPM_DEPS=( "@jridgewell/gen-mapping:0.3.13" "@jridgewell/resolve-uri:3.1.2" "@jridgewell/source-map:0.3.11" "@jridgewell/sourcemap-codec:1.5.5" "@jridgewell/trace-mapping:0.3.31" "acorn:8.18.0" "buffer-from:1.1.2" "commander:2.20.3" "source-map:0.6.1" "source-map-support:0.5.21" "terser:5.49.2" ) SRC_URI="https://github.com/kovidgoyal/rapydscript-ng/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz" # Scoped names carry a slash, and two of the tarballs are called source-map-*, # so the DISTDIR name has to be flattened and prefixed or they collide. _rsng_distfile() { local n=${1%:*} v=${1#*:} flat flat=${n//@/} flat=${flat//\//-} echo "npm-${flat}-${v}.tgz" } _rsng_dep= for _rsng_dep in "${NPM_DEPS[@]}"; do _rsng_n=${_rsng_dep%:*} _rsng_v=${_rsng_dep#*:} SRC_URI+=" https://registry.npmjs.org/${_rsng_n}/-/${_rsng_n##*/}-${_rsng_v}.tgz -> $(_rsng_distfile "${_rsng_dep}")" done unset _rsng_dep _rsng_n _rsng_v # rapydscript-ng and terser are BSD-2, source-map is BSD-3, everything else MIT. LICENSE="BSD-2 BSD MIT" SLOT="0" KEYWORDS="~amd64 ~arm64" BDEPEND="net-libs/nodejs" RDEPEND="net-libs/nodejs" src_unpack() { unpack "${P}.tar.gz" local dep n v dest for dep in "${NPM_DEPS[@]}"; do n=${dep%:*} v=${dep#*:} dest="${S}/node_modules/${n}" mkdir -p "${dest}" || die # npm tarballs all extract to a directory literally named "package", # so they are unpacked one at a time into their final home instead of # through unpack(), which would land them all on top of each other. tar -xf "${DISTDIR}/$(_rsng_distfile "${dep}")" \ -C "${dest}" --strip-components=1 || die "failed to unpack ${n}" done } src_compile() { edo bin/rapydscript self --complete rm -r release/ || die mv dev/ release/ || die } src_test() { edo bin/rapydscript test } src_install() { local modulesdir=/usr/$(get_libdir)/node_modules/rapydscript-ng insinto "${modulesdir}" doins -r * fperms +x "${modulesdir}"/bin/rapydscript dosym -r "${modulesdir}"/bin/rapydscript /usr/bin/rapydscript }