From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 112A1158017 for ; Wed, 29 Sep 2021 13:08:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2F1E3E0916; Wed, 29 Sep 2021 13:08:32 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0CF52E0916 for ; Wed, 29 Sep 2021 13:08:32 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 36AB2342A5D for ; Wed, 29 Sep 2021 13:08:31 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C2647114 for ; Wed, 29 Sep 2021 13:08:29 +0000 (UTC) From: "Alessandro Barbieri" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Alessandro Barbieri" Message-ID: <1632920907.cdfa791730db5da61da7bb4df88f8fede81e7711.Alessandro-Barbieri@gentoo> Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/ X-VCS-Repository: repo/proj/guru X-VCS-Files: eclass/node.eclass X-VCS-Directories: eclass/ X-VCS-Committer: Alessandro-Barbieri X-VCS-Committer-Name: Alessandro Barbieri X-VCS-Revision: cdfa791730db5da61da7bb4df88f8fede81e7711 X-VCS-Branch: dev Date: Wed, 29 Sep 2021 13:08:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 3cf1dbfb-2ebe-4cb5-9500-bb395bd040fc X-Archives-Hash: d2282858cfdbf3cd338f7fa680aa3936 commit: cdfa791730db5da61da7bb4df88f8fede81e7711 Author: Alessandro Barbieri gmail com> AuthorDate: Wed Sep 29 13:05:40 2021 +0000 Commit: Alessandro Barbieri gmail com> CommitDate: Wed Sep 29 13:08:27 2021 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=cdfa7917 node.eclass: new eclass Signed-off-by: Alessandro Barbieri gmail.com> eclass/node.eclass | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/eclass/node.eclass b/eclass/node.eclass new file mode 100644 index 000000000..aeff2f3c7 --- /dev/null +++ b/eclass/node.eclass @@ -0,0 +1,135 @@ +# Copyright 1999-2021 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: node.eclass +# @MAINTAINER: Alessandro Barbieri +# @AUTHOR: +# Alessandro Barbieri +# msirabella +# @BLURB: Eclass used to create and maintain node based packages +# @DESCRIPTION: Node eclass for nodejs' based packages + +EXPORT_FUNCTIONS src_prepare src_compile src_install src_test src_configure + +SLOT="0" +PN_LEFT="${PN%%+*}" +PN_RIGHT="${PN#*+}" +NODEJS_DEPEND="net-libs/nodejs" +NODEJS_RDEPEND="${NODEJS_DEPEND}" +NODEJS_BDEPEND=" + app-misc/jq + net-misc/rsync + + net-libs/nodejs[npm] +" +# || ( net-libs/nodejs[npm] dev-node/npm ) + +DEPEND="${NODEJS_DEPEND}" +RDEPEND="${NODEJS_RDEPEND}" +BDEPEND="${NODEJS_BDEPEND}" + +NODE_MODULE_PREFIX="${T}/prefix" +NPM="npm" +#NPM_FLAGS="" + +case "${PN}" in + *+*) + SRC_URI="mirror://npm/@${PN_LEFT}/${PN_RIGHT}/-/${PN_RIGHT}-${PV}.tgz -> ${P}.tgz" + ;; + + *) + SRC_URI="mirror://npm/${PN}/-/${P}.tgz" + ;; +esac +case "${PN}" in + *types+*) + S="${WORKDIR}/${PN_RIGHT}" + ;; + + *) + S="${WORKDIR}/package" + ;; +esac + +node_src_prepare() { + #remove version constraints on dependencies + jq 'if .dependencies? then .dependencies[] = "*" else . end' package.json > package.json.temp || die + mv package.json.temp package.json || die + jq 'if .devDependencies? then .devDependencies[] = "*" else . end' package.json > package.json.temp || die + mv package.json.temp package.json || die + + #here we trick npm into believing there are no dependencies so it will not try to fetch them + jq 'with_entries(if .key == "dependencies" then .key = "deps" else . end)' package.json > package.json.temp || die + mv package.json.temp package.json || die + jq 'with_entries(if .key == "devDependencies" then .key = "devDeps" else . end)' package.json > package.json.temp || die + mv package.json.temp package.json || die + + # are those useful? + rm -fv npm-shrinkwrap.json package-lock.json yarn.lock pnpm-lock.yaml || die + + #delete some trash + find . -iname 'code-of-conduct*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'code_of_conduct*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'contributing*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'contribution*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'dockerfile*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'issue_template*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'license*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'licence*' -maxdepth 1 -exec rm -rv "{}" \; || die + find . -iname 'pull_request_template*' -maxdepth 1 -exec rm -rv "{}" \; || die + + default +} + +node_src_configure() { + export PATH="${PATH}:/opt/node-debian/usr/bin" + #path to the modules + export NODE_PATH="/usr/$(get_libdir)/node_modules:/opt/node-debian/usr/share/nodejs" + export npm_config_prefix="${NODE_MODULE_PREFIX}" + #path to the headers needed by node-gyp + export npm_config_nodedir="/usr/include/node" +# export npm_config_tmp="${T}" + + in_iuse test || export NODE_ENV="production" + + "${NPM}" config set offline true || die + "${NPM}" config set audit false || die + "${NPM}" config set fund false || die +} + +node_src_compile() { + "${NPM}" install ${NPM_FLAGS} --global || die +} + +node_src_install() { + #restore original package.json + jq 'with_entries(if .key == "deps" then .key = "dependencies" else . end)' package.json > package.json.temp || die + mv package.json.temp package.json || die + jq 'with_entries(if .key == "devDeps" then .key = "devDependencies" else . end)' package.json > package.json.temp || die + mv package.json.temp package.json || die + + #should I delete all the dotfiles? + rm -rvf $(find . -iname ".[!.]*") || die + + #install some files in the docdir + find . -iname "authors*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "changelog*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "changes*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "copyright*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "history*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "notice*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "readme*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + find . -iname "security*" -maxdepth 1 -exec dodoc "{}" \; -exec rm "{}" \; || die + + #copy files instead of symlinks + rsync -aLAX "${NODE_MODULE_PREFIX}/" "${ED}/usr" --exclude /bin || die + + if [ -d "${NODE_MODULE_PREFIX}/bin" ] ; then + #keep the symlinks + rsync -aAX "${NODE_MODULE_PREFIX}/bin/" "${ED}/usr/bin" || die + fi +} + +node_src_test() { + npm test || die +}