diff options
author | Alessandro Barbieri <lssndrbarbieri@gmail.com> | 2021-10-01 02:18:56 +0200 |
---|---|---|
committer | Alessandro Barbieri <lssndrbarbieri@gmail.com> | 2021-10-03 20:30:43 +0200 |
commit | 170efe131e0668df7aeab52d7affd35ac2d28c71 (patch) | |
tree | 7bcd316abf82baab57046fc2c4edf18657560579 /eclass | |
parent | profiles: mask mbdyn[mpi,superlu] (diff) | |
download | guru-170efe131e0668df7aeab52d7affd35ac2d28c71.tar.gz guru-170efe131e0668df7aeab52d7affd35ac2d28c71.tar.bz2 guru-170efe131e0668df7aeab52d7affd35ac2d28c71.zip |
node.eclass: allow packaged to bundle dev dependencies
this is useful to reduce the number of ebuilds
Signed-off-by: Alessandro Barbieri <lssndrbarbieri@gmail.com>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/node.eclass | 112 |
1 files changed, 98 insertions, 14 deletions
diff --git a/eclass/node.eclass b/eclass/node.eclass index 47b7a57b1..f885e51eb 100644 --- a/eclass/node.eclass +++ b/eclass/node.eclass @@ -9,7 +9,7 @@ # @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 +EXPORT_FUNCTIONS src_unpack src_prepare src_compile src_install src_test src_configure SLOT="0" PN_LEFT="${PN%%+*}" @@ -17,12 +17,11 @@ PN_RIGHT="${PN#*+}" NODEJS_DEPEND="net-libs/nodejs" NODEJS_RDEPEND="${NODEJS_DEPEND}" NODEJS_BDEPEND=" + app-editors/vim-core app-misc/jq - net-misc/rsync - net-libs/nodejs[npm] + net-misc/rsync " -# || ( net-libs/nodejs[npm] dev-node/npm ) DEPEND="${NODEJS_DEPEND}" RDEPEND="${NODEJS_RDEPEND}" @@ -55,17 +54,22 @@ 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 + if [[ "${NODE_BUNDLE}" != 1 ]]; then + jq 'if .devDependencies? then .devDependencies[] = "*" else . end' package.json > package.json.temp || die + mv package.json.temp package.json || die + fi #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 + if [[ "${NODE_BUNDLE}" != 1 ]]; then + 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 + fi #delete some trash find . -iname 'code-of-conduct*' -maxdepth 1 -exec rm -rv "{}" \; || die @@ -87,9 +91,11 @@ node_src_configure() { 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}" + #export npm_config_tmp="${T}" - in_iuse test || export NODE_ENV="production" + if [[ "${NODE_BUNDLE}" != 1 ]]; then + in_iuse test || export NODE_ENV="production" + fi "${NPM}" config set offline true || die "${NPM}" config set audit false || die @@ -97,6 +103,9 @@ node_src_configure() { } node_src_compile() { + if [[ "${NODE_BUNDLE}" == 1 ]]; then + "${NPM}" ci ${NPM_FLAGS} || die + fi "${NPM}" install ${NPM_FLAGS} --global || die } @@ -104,12 +113,21 @@ 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 + if [[ "${NODE_BUNDLE}" != 1 ]]; then + jq 'with_entries(if .key == "devDeps" then .key = "devDependencies" else . end)' package.json > package.json.temp || die + mv package.json.temp package.json || die + fi #should I delete all the dotfiles? rm -rvf $(find . -iname ".[!.]*") || die + if [[ "${NODE_BUNDLE}" == 1 ]]; then + rm -fv npm-shrinkwrap.json package-lock.json yarn.lock pnpm-lock.yaml || die + + # delete dev dependencies + rm -rf node_modules || die + fi + #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 @@ -132,3 +150,69 @@ node_src_install() { node_src_test() { npm test || die } + +# ugh +sha256sum() { + command sha256sum "$@" | cut -d ' ' -f 1 +} + +sha1sum() { + command sha1sum "$@" | cut -d ' ' -f 1 +} + +sha512sum() { + command sha512sum "$@" | cut -d ' ' -f 1 +} + +hex2base64() { + xxd -r -p | base64 -w 0 +} + +splithash() { + echo "${1:0:2}/${1:2:2}/${1:4}" + +} + +newcacheline() { + read -r -d '' JSON <<-EOF + {"key":"pacote:tarball:file:$1","integrity":"sha1-$(sha1sum "$1" | hex2base64)","time":1604617124075,"size":$(wc -c < "$1")} + EOF + echo + echo -n "$(echo -n "$JSON" | sha1sum)" + echo -n ' ' + echo "$JSON" +} + +addsha1file() { + SHA1="$CACHEDIR/content-v2/sha1/$(splithash "$(sha1sum "$1")")" + mkdir -p "$(dirname "$SHA1")" || die + cp "$1" "$SHA1" || die +} + +addsha512file() { + SHA="$CACHEDIR/content-v2/sha512/$(splithash "$(sha512sum "$1")")" + mkdir -p "$(dirname "$SHA")" || die + cp "$1" "$SHA" || die +} + +# end ugh + +npm_packages_uris() { + packages=("${@}") + for p in "${packages[@]}"; do + url="mirror://npm/${p} -> ${p//\//_}" + echo "${url}" + done +} + +node_src_unpack() { + unpack "${P}.tgz" + if [[ "${NODE_BUNDLE}" == 1 ]]; then + CACHEDIR="$(npm config get cache)/_cacache" + for file in "${DISTDIR}"/*.tgz; do + addsha1file "${file}" || die + addsha512file "${file}" || die + done + #npm cache verify || die # just for good luck + fi +} |