From 0a4adc4592ac1ada9ba97c66c8034baf420ae591 Mon Sep 17 00:00:00 2001 From: arminius-smh Date: Tue, 3 Sep 2024 19:20:18 +0200 Subject: [PATCH] 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. --- server/command-line/install.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/server/command-line/install.ts b/server/command-line/install.ts index adce9618..0a64a8b0 100644 --- a/server/command-line/install.ts +++ b/server/command-line/install.ts @@ -47,9 +47,15 @@ program .readFile(path.join(packageName.substring("file:".length), "package.json"), "utf-8") .then((data) => JSON.parse(data) as typeof packageJson); } else { - const split = packageName.split("@"); - packageName = split[0]; - const packageVersion = split[1] || "latest"; + // properly split scoped and non-scoped npm packages + // into their name and version + 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, { fullMetadata: true,