From e221e708c1237eaa3088d97aebf8bf4869843dc6 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sat, 23 Jul 2022 16:40:28 +0200 Subject: [PATCH] install: expand ~ for local paths Make `thelounge install file:~/path/to/package` work rather than erroring out that the folder doesn't exists. Probably funny on Windows, but it doesn't hurt either --- server/command-line/install.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/command-line/install.ts b/server/command-line/install.ts index b5c607a5..b9053f6e 100644 --- a/server/command-line/install.ts +++ b/server/command-line/install.ts @@ -37,8 +37,11 @@ program if (packageName.startsWith("file:")) { isLocalFile = true; + // our yarn invocation sets $HOME to the cachedir, so we must expand ~ now + // else the path will be invalid when npm expands it. + packageName = expandTildeInLocalPath(packageName); readFile = fspromises - .readFile(path.join(packageName.substr("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); } else { const split = packageName.split("@"); @@ -106,4 +109,9 @@ program }); }); +function expandTildeInLocalPath(packageName: string): string { + const path = packageName.substring("file:".length); + return "file:" + Helper.expandHome(path); +} + export default program;