server: fix scoped package install

Installing a scoped npm package with thelounge install lead to an error,
because the original split that was used to split the version from the
package, split at the first @ from scoped packages.
This commit is contained in:
arminius-smh 2024-09-03 19:20:18 +02:00
parent a61bc14456
commit 0a4adc4592
No known key found for this signature in database

View file

@ -47,9 +47,15 @@ program
.readFile(path.join(packageName.substring("file:".length), "package.json"), "utf-8") .readFile(path.join(packageName.substring("file:".length), "package.json"), "utf-8")
.then((data) => JSON.parse(data) as typeof packageJson); .then((data) => JSON.parse(data) as typeof packageJson);
} else { } else {
const split = packageName.split("@"); // properly split scoped and non-scoped npm packages
packageName = split[0]; // into their name and version
const packageVersion = split[1] || "latest"; let packageVersion = "latest";
const atIndex = packageName.indexOf("@", 1);
if (atIndex !== -1) {
packageVersion = packageName.slice(atIndex + 1);
packageName = packageName.slice(0, atIndex);
}
readFile = packageJson.default(packageName, { readFile = packageJson.default(packageName, {
fullMetadata: true, fullMetadata: true,