Skip to content

Commit

Permalink
install: expand ~ for local paths
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brunnre8 committed Jul 23, 2022
1 parent c8cd405 commit e221e70
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion server/command-line/install.ts
Expand Up @@ -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("@");
Expand Down Expand Up @@ -106,4 +109,9 @@ program
});
});

function expandTildeInLocalPath(packageName: string): string {
const path = packageName.substring("file:".length);
return "file:" + Helper.expandHome(path);
}

export default program;

0 comments on commit e221e70

Please sign in to comment.