mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: "Björn Esser" <b.esser@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: "Björn Esser" <b.esser@pengutronix.de>
Subject: [ptxdist] [PATCH v3 3/3] nodejs_packages: New package.
Date: Mon, 13 Jan 2020 11:40:55 +0100	[thread overview]
Message-ID: <20200113104052.11266-3-b.esser@pengutronix.de> (raw)
In-Reply-To: <20200113104052.11266-1-b.esser@pengutronix.de>

This is a dummy package to specifiy and install the required
Node.js packages for the target system.

The management of the Node.js packages and their dependencies
are handled with Yarn (run through host-nodejs) to maintain
a reprocible offline cache.

The cache is stored in local_src/nodejs_packages, which must
be an existing path inside of the BSP.

Signed-off-by: Björn Esser <b.esser@pengutronix.de>
---
 rules/nodejs_packages.in   | 52 ++++++++++++++++++++++
 rules/nodejs_packages.make | 90 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 142 insertions(+)
 create mode 100644 rules/nodejs_packages.in
 create mode 100644 rules/nodejs_packages.make

diff --git a/rules/nodejs_packages.in b/rules/nodejs_packages.in
new file mode 100644
index 000000000..144fc6c7b
--- /dev/null
+++ b/rules/nodejs_packages.in
@@ -0,0 +1,52 @@
+## SECTION=bytecode_engines
+
+menuconfig NODEJS_PACKAGES
+	tristate
+	select HOST_YARN
+	select NODEJS
+	prompt "Node.js packages (target)     "
+	help
+	  Reproducibly install Node.js packages that will be available
+	  system-wide on the target.
+
+	  You MUST specify at least one Node.js package in the shown
+	  submenu after enabling this option.
+
+
+if NODEJS_PACKAGES
+
+config NODEJS_PACKAGES_LIST
+	string
+	prompt "Node.js packages to install"
+	help
+	  A white-space separated list of Node.js packages including
+	  its version (e.g. express@4.17.x). npm semvers are fully
+	  supported.
+
+	  The packages are managed with Yarn and are guaranteed to be
+	  reproducible and immutable as long as the download location
+	  stays accessible or the download-cache does not get altered.
+
+	  After downloading the packages and creating the package cache,
+	  by building this package the first time after altering the list
+	  of installed packages, it is highly recommended to commit the
+	  path: './local_src/nodejs_packages/' into the git repository
+	  and to lock the package cache.
+
+	  Also the path: './local_src/nodejs_packages/' must exist in the
+	  BSP *before* before building this package.
+
+config NODEJS_PACKAGES_OFFLINE
+	bool
+	prompt "lock package cache for offline / production use"
+	help
+	  This option locks the cache for installing the nodejs
+	  packages and performs their installation during the
+	  build of the BSP without any need for internet connectivity.
+
+	  Checking this option is highly recommended for production use.
+
+	  Do NOT forget to commit the path: './local_src/nodejs_packages/'
+	  into the BSP's git repository!
+
+endif
diff --git a/rules/nodejs_packages.make b/rules/nodejs_packages.make
new file mode 100644
index 000000000..7c044bd5c
--- /dev/null
+++ b/rules/nodejs_packages.make
@@ -0,0 +1,90 @@
+# -*-makefile-*-
+#
+# Copyright (C) 2020 by Bjoern Esser <bes@pengutronix.de>
+#
+# For further information about the PTXdist project and license conditions
+# see the README file.
+#
+
+#
+# We provide this package
+#
+PACKAGES-$(PTXCONF_NODEJS_PACKAGES) += nodejs_packages
+
+#
+# Paths and names
+#
+NODEJS_PACKAGES_VERSION	:= 0.0.1
+NODEJS_PACKAGES		:= nodejs_packages-$(NODEJS_PACKAGES_VERSION)
+NODEJS_PACKAGES_LOCAL	:= local_src/nodejs_packages
+NODEJS_PACKAGES_URL	:= lndir://$(NODEJS_PACKAGES_LOCAL)
+NODEJS_PACKAGES_DIR	:= $(BUILDDIR)/$(NODEJS_PACKAGES)
+NODEJS_PACKAGES_CACHE	:= $(PTXDIST_WORKSPACE)/$(NODEJS_PACKAGES_LOCAL)/yarn_cache
+NODEJS_PACKAGES_LICENSE	:= unknown
+
+NODEJS_PACKAGES_LIST	:= $(call remove_quotes, $(PTXCONF_NODEJS_PACKAGES_LIST))
+
+YARN_LOCK	:= $(PTXDIST_WORKSPACE)/$(NODEJS_PACKAGES_LOCAL)/yarn.lock
+YARN_OPTS	:= \
+	--cwd "$(NODEJS_PACKAGES_DIR)" \
+	--cache-folder "$(NODEJS_PACKAGES_CACHE)" \
+	--link-duplicates \
+	--production=true
+
+ifdef PTXCONF_NODEJS_PACKAGES_OFFLINE
+YARN_OPTS	+= \
+	--frozen-lockfile \
+	--offline
+endif
+
+# ----------------------------------------------------------------------------
+# Compile
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/nodejs_packages.compile:
+	@$(call targetinfo)
+	mkdir -p $(NODEJS_PACKAGES_CACHE)
+	printf "{ \
+		\"name\": \"nodejs_packages\", \
+		\"version\": \"$(NODEJS_PACKAGES_VERSION)\", \
+		\"license\": \"UNLICENSED\", \
+		\"private\": true \
+	}" > $(NODEJS_PACKAGES_DIR)/package.json
+	if [[ ! -f $(YARN_LOCK) ]]; then \
+		touch $(YARN_LOCK); \
+		ln -fs $(YARN_LOCK) $(NODEJS_PACKAGES_DIR)/yarn.lock; \
+	fi
+	yarn $(YARN_OPTS) add $(NODEJS_PACKAGES_LIST)
+	find $(NODEJS_PACKAGES_CACHE) -type f -name '.yarn-tarball.tgz' -delete
+	@$(call touch)
+
+# ----------------------------------------------------------------------------
+# Install
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/nodejs_packages.install:
+	@$(call targetinfo)
+	install -dm 0755 $(NODEJS_PACKAGES_PKGDIR)/usr/lib
+	cp -pr $(NODEJS_PACKAGES_DIR)/node_modules $(NODEJS_PACKAGES_PKGDIR)/usr/lib
+	@$(call touch)
+
+# ----------------------------------------------------------------------------
+# Target-Install
+# ----------------------------------------------------------------------------
+
+$(STATEDIR)/nodejs_packages.targetinstall:
+	@$(call targetinfo)
+
+	@$(call install_init, nodejs_packages)
+	@$(call install_fixup, nodejs_packages,PRIORITY,optional)
+	@$(call install_fixup, nodejs_packages,SECTION,base)
+	@$(call install_fixup, nodejs_packages,AUTHOR,"Bjoern Esser <bes@pengutronix.de>")
+	@$(call install_fixup, nodejs_packages,DESCRIPTION,missing)
+
+	$(call install_tree, nodejs_packages, 0, 0, -, /usr/lib/node_modules/)
+
+	@$(call install_finish, nodejs_packages)
+
+	@$(call touch)
+
+# vim: syntax=make
-- 
2.25.0.rc1


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

  parent reply	other threads:[~2020-01-13 10:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-13 10:40 [ptxdist] [PATCH v3 1/3] nodejs: version bump 6.9.5 -> 12.14.1 LTS Björn Esser
2020-01-13 10:40 ` [ptxdist] [PATCH v3 2/3] host-yarn: New package Björn Esser
2020-01-13 10:40 ` Björn Esser [this message]
2020-01-29 11:11 ` [ptxdist] [PATCH v3 1/3] nodejs: version bump 6.9.5 -> 12.14.1 LTS Ulrich Ölmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200113104052.11266-3-b.esser@pengutronix.de \
    --to=b.esser@pengutronix.de \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox