# Copyright 1999-2026 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: npm-bundle.eclass # @MAINTAINER: # Emily Love Watson # @AUTHOR: # Emily Love Watson # @BLURB: Just put all the npm dependencies in SRC_URI # @DESCRIPTION: # This eclass relies on the ebuild to embed a list of all dependencies required # to run a node package. The ebuild will add every package to the SRC_URI list. # The packages are added to the npm cache to enable an offline install. This # overlay provides a script bin/enpm-dump-modules.sh, this can be run in a # local environment where you have already installed dependencies online using # npm, yarn, etc. The ebuild is still responsible for the compile and install # phases. if [[ -z ${_NPM_BUNDLE_ECLASS} ]]; then _NPM_BUNDLE_ECLASS=1 fi case ${EAPI} in 8) ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; esac inherit npm # @ECLASS_VARIABLE: ENPM_BUNDLE_NODE_MODULES # @DESCRIPTION: # An IFS separated list of modules that needs to be fetched in order to install # offline. Generated with bin/enpm-dump-modules.sh after installing # dependencies online with existing tools. This is not parsed as a package-spec # version range! Only one exact version per entry is allowed. Must be specified # before eclass is inherited. Defaults to none. : "${ENPM_BUNDLE_NODE_MODULES:=}" for node_module in ${ENPM_BUNDLE_NODE_MODULES}; do PKG_NAME=${node_module%=*} PKG_SHORTNAME=${PKG_NAME#*/} PKG_VERSION=${node_module#*=} PKG_ENCODED_NAME="${PKG_NAME//\//%2f}" SRC_URI="${SRC_URI} http://${ENPM_REGISTRY}/${PKG_NAME}/-/${PKG_SHORTNAME}-${PKG_VERSION}.tgz -> ${ENPM_REGISTRY}-${PKG_ENCODED_NAME}-${PKG_VERSION}.tgz" done # @FUNCTION: npm-bundle_src_unpack # @DESCRIPTION: # Preloads npm dependencies into cache npm-bundle_src_unpack() { ${ENPM} cache add $(for node_module in ${ENPM_BUNDLE_NODE_MODULES}; do PKG_NAME=${node_module%=*} PKG_SHORTNAME=${PKG_NAME#*/} PKG_VERSION=${node_module#*=} PKG_ENCODED_NAME="${PKG_NAME//\//%2f}" echo " ${DISTDIR}/${ENPM_REGISTRY}-${PKG_ENCODED_NAME}-${PKG_VERSION}.tgz" done) } # @FUNCTION: npm-bundle_src_prepare # @DESCRIPTION: # Installs dependencies into node_modules npm-bundle_src_prepare() { default ${ENPM} install || die } # @FUNCTION: npm-bundle_src_install # @DESCRIPTION: # Prunes unneeded packages before installing npm-bundle_src_install() { # Remove unnecessary build dependencies ${ENPM} prune --production || die } EXPORT_FUNCTIONS src_unpack src_prepare src_install