Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parallelize linking, unlinking and installing #524

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions sources/commands/Disable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,25 @@ export class DisableCommand extends Command<Context> {
? SupportedPackageManagerSetWithoutNpm
: this.names;

const binNamesMap = new Map<string, Set<string>>();
wojtekmaj marked this conversation as resolved.
Show resolved Hide resolved

for (const name of new Set(names)) {
if (!isSupportedPackageManager(name))
throw new UsageError(`Invalid package manager name '${name}'`);

for (const binName of this.context.engine.getBinariesFor(name)) {
if (process.platform === `win32`) {
await this.removeWin32Link(installDirectory, binName);
} else {
await this.removePosixLink(installDirectory, binName);
}
}
const binNames = this.context.engine.getBinariesFor(name);
binNamesMap.set(name, binNames);
wojtekmaj marked this conversation as resolved.
Show resolved Hide resolved
}

const allBinNames = Array.from(binNamesMap.values()).flatMap(binNames => Array.from(binNames));

await Promise.all(allBinNames.map(binName => {
if (process.platform === `win32`) {
return this.removeWin32Link(installDirectory, binName);
} else {
return this.removePosixLink(installDirectory, binName);
}
}));
wojtekmaj marked this conversation as resolved.
Show resolved Hide resolved
}

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

const binNamesMap = new Map<string, Set<string>>();

for (const name of new Set(names)) {
if (!isSupportedPackageManager(name))
throw new UsageError(`Invalid package manager name '${name}'`);

for (const binName of this.context.engine.getBinariesFor(name)) {
if (process.platform === `win32`) {
await this.generateWin32Link(installDirectory, distFolder, binName);
} else {
await this.generatePosixLink(installDirectory, distFolder, binName);
}
}
const binNames = this.context.engine.getBinariesFor(name);
binNamesMap.set(name, binNames);
}

const allBinNames = Array.from(binNamesMap.values()).flatMap(binNames => Array.from(binNames));

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

async generatePosixLink(installDirectory: string, distFolder: string, binName: string) {
Expand Down
9 changes: 4 additions & 5 deletions sources/commands/InstallGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export class InstallGlobalCommand extends BaseCommand {
if (this.args.length === 0)
throw new UsageError(`No package managers specified`);

for (const arg of this.args) {
await Promise.all(this.args.map(arg => {
if (arg.endsWith(`.tgz`)) {
await this.installFromTarball(path.resolve(this.context.cwd, arg));
return this.installFromTarball(path.resolve(this.context.cwd, arg));
} else {
await this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
return this.installFromDescriptor(specUtils.parseSpec(arg, `CLI arguments`, {enforceExactVersion: false}));
}
}
}));
}

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


if (segments.length < 3) {
hasShortEntries = true;
} else {
Expand Down