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

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

(Bitbake rev: 7c9573cb6ea2081bc585eb65267f3124fd4d7e43)

Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Leonard Göhrs
2024-08-23 07:46:34 +02:00
committed by Richard Purdie
parent 58414305b2
commit ee6bf285d7

View File

@@ -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