Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Stefano Tondo <stondo@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Alexander Kanavin <alex.kanavin@gmail.com>,
	Joshua Watt <JPEWhacker@gmail.com>,
	Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>,
	Peter Marko <peter.marko@siemens.com>,
	stefano.tondo.ext@siemens.com
Subject: [PATCH 07/10] npm-update-dependencies: Add a class to list the npm dependencies
Date: Fri, 20 Nov 2026 14:53:38 +0100	[thread overview]
Message-ID: <20261120135342.2628228-8-stondo@gmail.com> (raw)
In-Reply-To: <20261120135342.2628228-1-stondo@gmail.com>

From: Stefano Tondo <stefano.tondo.ext@siemens.com>

Add a class with the task do_update_npm_deps. The task reads
npm-shrinkwrap.json in ${S} and writes one SRC_URI entry for each
dependency to ${THISDIR}/${BPN}-npm-deps.inc. The recipe requires this
file. This is the same model as the cargo and Go update tasks.

Then the recipe does not need npmsw://. The fetchers see each
dependency as a normal SRC_URI entry with its own checksum.

Signed-off-by: Stefano Tondo <stefano.tondo.ext@siemens.com>
---
 .../npm-update-dependencies.bbclass           | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 meta/classes-recipe/npm-update-dependencies.bbclass

diff --git a/meta/classes-recipe/npm-update-dependencies.bbclass b/meta/classes-recipe/npm-update-dependencies.bbclass
new file mode 100644
index 0000000000..43b00b9b1b
--- /dev/null
+++ b/meta/classes-recipe/npm-update-dependencies.bbclass
@@ -0,0 +1,48 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+##
+## Purpose:
+## This class is used to update the list of npm dependencies in SRC_URI
+## by reading npm-shrinkwrap.json in the source tree. It writes one entry
+## with a checksum for each dependency, so that no fetcher has to read the
+## shrinkwrap file. npm.bbclass checks that SRC_URI matches the shrinkwrap
+## file.
+##
+## To perform the update: bitbake -c update_npm_deps recipe-name
+
+addtask do_update_npm_deps after do_patch
+do_update_npm_deps[nostamp] = "1"
+do_update_npm_deps[doc] = "Update the recipe by reading npm-shrinkwrap.json and write in ${THISDIR}/${BPN}-npm-deps.inc"
+
+RECIPE_UPGRADE_EXTRA_TASKS += "do_update_npm_deps"
+
+python do_update_npm_deps() {
+    import json
+    import oe.npm
+
+    shrinkwrap_file = d.expand("${S}/npm-shrinkwrap.json")
+    with open(shrinkwrap_file) as f:
+        shrinkwrap = json.load(f)
+
+    destdir = os.path.relpath(d.getVar("S"), d.getVar("UNPACKDIR"))
+    dev = bb.utils.to_boolean(d.getVar("NPM_INSTALL_DEV"), False)
+    try:
+        entries = oe.npm.shrinkwrap_src_uri(shrinkwrap, destdir, dev)
+    except ValueError as e:
+        bb.fatal("%s: %s" % (shrinkwrap_file, e))
+
+    lines = ["# Autogenerated with 'bitbake -c update_npm_deps %s'" % d.getVar("PN"), ""]
+    lines.append('SRC_URI += " \\')
+    lines.extend("    %s \\" % entry for entry in entries)
+    lines.append('"')
+
+    target_file = d.expand("${THISDIR}/${BPN}-npm-deps.inc")
+    with open(target_file, "w") as f:
+        f.write("\n".join(lines) + "\n")
+
+    bb.note("Successfully updated %d npm dependencies inside %s" % (len(entries), target_file))
+}
-- 
2.56.1


  parent reply	other threads:[~2026-11-20 13:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:53 [PATCH 00/10] npm: list the dependencies in SRC_URI Stefano Tondo
2026-11-20 13:53 ` [PATCH 01/10] recipetool: create_npm: Give the fallback licenses as a string Stefano Tondo
2026-11-20 13:53 ` [PATCH 02/10] recipetool: create: Get the checksum of npm packages from the registry Stefano Tondo
2026-11-20 13:53 ` [PATCH 03/10] recipetool: create_npm: Give the package fallback licenses as strings Stefano Tondo
2026-11-20 13:53 ` [PATCH 04/10] recipetool: create_npm: Remove the "@" of a scope from generated names Stefano Tondo
2026-11-20 14:04   ` Patchtest results for " patchtest
2026-11-20 13:53 ` [PATCH 05/10] oeqa/selftest: recipetool: Expect the npm source in UNPACKDIR Stefano Tondo
2026-11-20 13:53 ` [PATCH 06/10] lib/oe/npm: Add SRC_URI entries for the dependencies of a shrinkwrap file Stefano Tondo
2026-11-20 13:53 ` Stefano Tondo [this message]
2026-11-20 13:53 ` [PATCH 08/10] npm: Check that SRC_URI lists all dependencies of the " Stefano Tondo
2026-11-20 13:53 ` [PATCH 09/10] recipetool: create: Clean the recipe after its tasks Stefano Tondo
2026-11-20 13:53 ` [PATCH 10/10] recipetool: create_npm: List the npm dependencies in SRC_URI Stefano Tondo

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=20261120135342.2628228-8-stondo@gmail.com \
    --to=stondo@gmail.com \
    --cc=JPEWhacker@gmail.com \
    --cc=alex.kanavin@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=peter.marko@siemens.com \
    --cc=stefan.herbrechtsmeier@weidmueller.com \
    --cc=stefano.tondo.ext@siemens.com \
    /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