Skip to content

Commit

Permalink
Simplify generating/removing links
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jul 12, 2024
1 parent 1cfa1f6 commit b0a9140
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
14 changes: 6 additions & 8 deletions sources/commands/Disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DisableCommand extends Command<Context> {
? SupportedPackageManagerSetWithoutNpm
: this.names;

const allBinNames: string[] = [];
const allBinNames: Array<string> = [];

for (const name of new Set(names)) {
if (!isSupportedPackageManager(name))
Expand All @@ -60,13 +60,11 @@ export class DisableCommand extends Command<Context> {
allBinNames.push(...binNames);
}

await Promise.all(allBinNames.map(binName => {
if (process.platform === `win32`) {
return this.removeWin32Link(installDirectory, binName);
} else {
return this.removePosixLink(installDirectory, binName);
}
}));
const removeLink = process.platform === `win32` ?
(binName: string) => this.removeWin32Link(installDirectory, binName) :
(binName: string) => this.removePosixLink(installDirectory, binName);

await Promise.all(allBinNames.map(removeLink));
}

async removePosixLink(installDirectory: string, binName: string) {
Expand Down
14 changes: 6 additions & 8 deletions sources/commands/Enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class EnableCommand extends Command<Context> {
? SupportedPackageManagerSetWithoutNpm
: this.names;

const allBinNames: string[] = [];
const allBinNames: Array<string> = [];

for (const name of new Set(names)) {
if (!isSupportedPackageManager(name))
Expand All @@ -70,13 +70,11 @@ export class EnableCommand extends Command<Context> {
allBinNames.push(...binNames);
}

await Promise.all(allBinNames.map(binName => {
if (process.platform === `win32`) {
return this.generateWin32Link(installDirectory, distFolder, binName);
} else {
return this.generatePosixLink(installDirectory, distFolder, binName);
}
}));
const generateLink = process.platform === `win32` ?
(binName: string) => this.generateWin32Link(installDirectory, distFolder, binName) :
(binName: string) => this.generatePosixLink(installDirectory, distFolder, binName);

await Promise.all(allBinNames.map(generateLink));
}

async generatePosixLink(installDirectory: string, distFolder: string, binName: string) {
Expand Down

0 comments on commit b0a9140

Please sign in to comment.