Skip to content

Commit 1f32f6c

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

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

sources/commands/Enable.ts

Lines changed: 4 additions & 10 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,9 @@ export class EnableCommand extends Command<Context> {
9392
return;
9493
}
9594

96-
if (currentSymlink !== symlink) {
97-
await fs.promises.unlink(file);
98-
} else {
99-
return;
100-
}
101-
} else {
102-
await fs.promises.unlink(file);
95+
if (currentSymlink === symlink) return;
10396
}
97+
await fs.promises.unlink(file);
10498
}
10599

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

0 commit comments

Comments
 (0)