Skip to content

Commit f0734e6

Browse files
authored
feat: parallelize linking, unlinking and installing (#524)
1 parent c01af88 commit f0734e6

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

sources/commands/Disable.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,21 @@ export class DisableCommand extends Command<Context> {
5050
? SupportedPackageManagerSetWithoutNpm
5151
: this.names;
5252

53+
const allBinNames: Array<string> = [];
54+
5355
for (const name of new Set(names)) {
5456
if (!isSupportedPackageManager(name))
5557
throw new UsageError(`Invalid package manager name '${name}'`);
5658

57-
for (const binName of this.context.engine.getBinariesFor(name)) {
58-
if (process.platform === `win32`) {
59-
await this.removeWin32Link(installDirectory, binName);
60-
} else {
61-
await this.removePosixLink(installDirectory, binName);
62-
}
63-
}
59+
const binNames = this.context.engine.getBinariesFor(name);
60+
allBinNames.push(...binNames);
6461
}
62+
63+
const removeLink = process.platform === `win32` ?
64+
(binName: string) => this.removeWin32Link(installDirectory, binName) :
65+
(binName: string) => this.removePosixLink(installDirectory, binName);
66+
67+
await Promise.all(allBinNames.map(removeLink));
6568
}
6669

6770
async removePosixLink(installDirectory: string, binName: string) {

sources/commands/Enable.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,21 @@ export class EnableCommand extends Command<Context> {
6060
? SupportedPackageManagerSetWithoutNpm
6161
: this.names;
6262

63+
const allBinNames: Array<string> = [];
64+
6365
for (const name of new Set(names)) {
6466
if (!isSupportedPackageManager(name))
6567
throw new UsageError(`Invalid package manager name '${name}'`);
6668

67-
for (const binName of this.context.engine.getBinariesFor(name)) {
68-
if (process.platform === `win32`) {
69-
await this.generateWin32Link(installDirectory, distFolder, binName);
70-
} else {
71-
await this.generatePosixLink(installDirectory, distFolder, binName);
72-
}
73-
}
69+
const binNames = this.context.engine.getBinariesFor(name);
70+
allBinNames.push(...binNames);
7471
}
72+
73+
const generateLink = process.platform === `win32` ?
74+
(binName: string) => this.generateWin32Link(installDirectory, distFolder, binName) :
75+
(binName: string) => this.generatePosixLink(installDirectory, distFolder, binName);
76+
77+
await Promise.all(allBinNames.map(generateLink));
7578
}
7679

7780
async generatePosixLink(installDirectory: string, distFolder: string, binName: string) {

sources/commands/InstallGlobal.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ export class InstallGlobalCommand extends BaseCommand {
4343
if (this.args.length === 0)
4444
throw new UsageError(`No package managers specified`);
4545

46-
for (const arg of this.args) {
46+
await Promise.all(this.args.map(arg => {
4747
if (arg.endsWith(`.tgz`)) {
48-
await this.installFromTarball(path.resolve(this.context.cwd, arg));
48+
return this.installFromTarball(path.resolve(this.context.cwd, arg));
4949
} else {
50-
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
50+
return this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
5151
}
52-
}
52+
}));
5353
}
5454

5555
log(locator: Locator) {
@@ -86,7 +86,6 @@ export class InstallGlobalCommand extends BaseCommand {
8686
if (segments.length > 0 && segments[segments.length - 1] !== `.corepack`)
8787
return;
8888

89-
9089
if (segments.length < 3) {
9190
hasShortEntries = true;
9291
} else {

0 commit comments

Comments
 (0)