diff mbox series

fetch2/npm: allow the '@' character in package names

Message ID 20240823054634.91441-1-l.goehrs@pengutronix.de
State Accepted, archived
Commit 7c9573cb6ea2081bc585eb65267f3124fd4d7e43
Headers show
Series fetch2/npm: allow the '@' character in package names | expand

Commit Message

Leonard Göhrs Aug. 23, 2024, 5:46 a.m. UTC
The '@types/ramda' [1] npm package has recently gained a dependency on
the 'types-ramda' [2] npm package. Both have the same version number.

The name mangling results in the tarballs of both packages sharing the same
name, but different contents.

Fix that by accepting '@' as valid character in the package name,
resulting in one package named @types-ramda and one called types-ramda.

[1]: https://www.npmjs.com/package/@types/ramda
[2]: https://www.npmjs.com/package/types-ramda

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
---
 lib/bb/fetch2/npm.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index 15f3f19bc..ac76d64cd 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -42,11 +42,12 @@  from bb.utils import is_semver
 
 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.
+    # For scoped package names ('@user/package') the '/' is replaced by a '-'.
+    # This is similar to what 'npm pack' does, but 'npm pack' also strips the
+    # leading '@', which can lead to ambiguous package names.
     name = re.sub("/", "-", package)
     name = name.lower()
-    name = re.sub(r"[^\-a-z0-9]", "", name)
+    name = re.sub(r"[^\-a-z0-9@]", "", name)
     name = name.strip("-")
     return name