diff mbox series

[master,v2,3/3] fetch2: npm: Remove special caracters that causes recipe tool to fail

Message ID 20230604013919.13904-3-m.belouarga@technologyandstrategy.com
State New
Headers show
Series [master,v2,1/3] bitbake: fetch2: npmsw: Add support for the new format of the shrinkwrap file | expand

Commit Message

belouargamohamed@gmail.com June 4, 2023, 1:39 a.m. UTC
From: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>

Packages like @(._.)/execute causes problems because they generate names
that are not supported by yocto

Signed-off-by: BELOUARGA Mohamed <m.belouarga@technologyandstrategy.com>
---
 lib/bb/fetch2/npm.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index e6d0598f5d..f83485ad85 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -44,9 +44,12 @@  def npm_package(package):
     """Convert the npm package name to remove unsupported character"""
     # Scoped package names (with the @) use the same naming convention
     # as the 'npm pack' command.
-    if package.startswith("@"):
-        return re.sub("/", "-", package[1:])
-    return package
+    name = re.sub("/", "-", package)
+    name = name.lower()
+    name = re.sub(r"[^\-a-z0-9]", "", name)
+    name = name.strip("-")
+    return name
+
 
 def npm_filename(package, version):
     """Get the filename of a npm package"""