summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>2023-05-31 00:27:48 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-06-29 11:10:39 +0100
commitee8b906a835cf14c525bae05bfba804cf28b518d (patch)
tree093839f45d974ce2e3428112a4a21fc94b29cb6a
parent2a3888069fc516f7f1749f7123eef43994248511 (diff)
downloadpoky-ee8b906a835cf14c525bae05bfba804cf28b518d.tar.gz
classes: npm: Handle peer dependencies for npm packages
NPM changed its manner to handle peer dependencies over its versions. Before NPM 3: NPM installs automatically peer dependencies between NPM 3 and 7: NPM shows a warning about peer dependencies After NPM 3: NPM reworked its manner how to handle peer dependencies The shrinkwrap doesn't have the parameters of the peer dependencies, so we cannot fetch them. in the same time peer dependencies are not direct dependencies, they should be installed as run time dependencies. (From OE-Core rev: a5734148649be93529e5d5172cb47928957a6536) Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes-recipe/npm.bbclass18
1 files changed, 18 insertions, 0 deletions
diff --git a/meta/classes-recipe/npm.bbclass b/meta/classes-recipe/npm.bbclass
index 639f461a3a..92e59fefce 100644
--- a/meta/classes-recipe/npm.bbclass
+++ b/meta/classes-recipe/npm.bbclass
@@ -109,6 +109,7 @@ python npm_do_configure() {
109 import tempfile 109 import tempfile
110 from bb.fetch2.npm import NpmEnvironment 110 from bb.fetch2.npm import NpmEnvironment
111 from bb.fetch2.npm import npm_unpack 111 from bb.fetch2.npm import npm_unpack
112 from bb.fetch2.npm import npm_package
112 from bb.fetch2.npmsw import foreach_dependencies 113 from bb.fetch2.npmsw import foreach_dependencies
113 from bb.progress import OutOfProgressHandler 114 from bb.progress import OutOfProgressHandler
114 from oe.npm_registry import NpmRegistry 115 from oe.npm_registry import NpmRegistry
@@ -169,6 +170,7 @@ python npm_do_configure() {
169 if has_shrinkwrap_file: 170 if has_shrinkwrap_file:
170 cached_shrinkwrap = copy.deepcopy(orig_shrinkwrap) 171 cached_shrinkwrap = copy.deepcopy(orig_shrinkwrap)
171 cached_shrinkwrap.pop("dependencies", None) 172 cached_shrinkwrap.pop("dependencies", None)
173 cached_shrinkwrap["packages"][""].pop("peerDependencies", None)
172 174
173 # Manage the dependencies 175 # Manage the dependencies
174 progress = OutOfProgressHandler(d, r"^(\d+)/(\d+)$") 176 progress = OutOfProgressHandler(d, r"^(\d+)/(\d+)$")
@@ -203,6 +205,19 @@ python npm_do_configure() {
203 if has_shrinkwrap_file: 205 if has_shrinkwrap_file:
204 foreach_dependencies(orig_shrinkwrap, _count_dependency, dev) 206 foreach_dependencies(orig_shrinkwrap, _count_dependency, dev)
205 foreach_dependencies(orig_shrinkwrap, _cache_dependency, dev) 207 foreach_dependencies(orig_shrinkwrap, _cache_dependency, dev)
208
209 # Manage Peer Dependencies
210 if has_shrinkwrap_file:
211 packages = orig_shrinkwrap.get("packages", {})
212 peer_deps = packages.get("", {}).get("peerDependencies", {})
213 package_runtime_dependencies = d.getVar("RDEPENDS:%s" % d.getVar("PN"))
214
215 for peer_dep in peer_deps:
216 peer_dep_yocto_name = npm_package(peer_dep)
217 if peer_dep_yocto_name not in package_runtime_dependencies:
218 bb.warn(peer_dep + " is a peer dependencie that is not in RDEPENDS variable. " +
219 "Please add this peer dependencie to the RDEPENDS variable as %s and generate its recipe with devtool"
220 % peer_dep_yocto_name)
206 221
207 # Configure the main package 222 # Configure the main package
208 with tempfile.TemporaryDirectory() as tmpdir: 223 with tempfile.TemporaryDirectory() as tmpdir:
@@ -279,6 +294,9 @@ python npm_do_compile() {
279 args.append(("target_arch", d.getVar("NPM_ARCH"))) 294 args.append(("target_arch", d.getVar("NPM_ARCH")))
280 args.append(("build-from-source", "true")) 295 args.append(("build-from-source", "true"))
281 296
297 # Don't install peer dependencies as they should be in RDEPENDS variable
298 args.append(("legacy-peer-deps", "true"))
299
282 # Pack and install the main package 300 # Pack and install the main package
283 (tarball, _) = npm_pack(env, d.getVar("NPM_PACKAGE"), tmpdir) 301 (tarball, _) = npm_pack(env, d.getVar("NPM_PACKAGE"), tmpdir)
284 cmd = "npm install %s %s" % (shlex.quote(tarball), d.getVar("EXTRA_OENPM")) 302 cmd = "npm install %s %s" % (shlex.quote(tarball), d.getVar("EXTRA_OENPM"))