Skip to content

Commit b664e26

Browse files
committed
refactor: Simplify symlink update logic
1 parent 4c8e5da commit b664e26

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

sources/commands/Enable.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ export class EnableCommand extends Command<Context> {
8181
async generatePosixLink(installDirectory: string, distFolder: string, binName: string) {
8282
const file = path.join(installDirectory, binName);
8383
const symlink = path.relative(installDirectory, path.join(distFolder, `${binName}.js`));
84+
const stats = fs.lstatSync(file, {throwIfNoEntry: false});
8485

85-
if (fs.existsSync(file)) {
86-
const stats = await fs.promises.lstat(file);
87-
86+
if (stats) {
8887
if (stats.isSymbolicLink()) {
8988
const currentSymlink = await fs.promises.readlink(file);
9089

@@ -93,14 +92,11 @@ export class EnableCommand extends Command<Context> {
9392
return;
9493
}
9594

96-
if (currentSymlink !== symlink) {
97-
await fs.promises.unlink(file);
98-
} else {
95+
if (currentSymlink === symlink) {
9996
return;
10097
}
101-
} else {
102-
await fs.promises.unlink(file);
10398
}
99+
await fs.promises.unlink(file);
104100
}
105101

106102
await fs.promises.symlink(symlink, file);

0 commit comments

Comments
 (0)