Skip to content

Commit ef03174

Browse files
committed
Return installation status for already installed dependencies
1 parent 6f63cf6 commit ef03174

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/installRuntimeDependencies.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { PackageInstallation, LogPlatformInfo, InstallationSuccess } from './sha
88
import { EventStream } from './eventStream';
99
import { getRuntimeDependenciesPackages } from './tools/runtimeDependencyPackageUtils';
1010
import { getAbsolutePathPackagesToInstall } from './packageManager/getAbsolutePathPackagesToInstall';
11-
import { DependencyInstallationResults, IInstallDependencies } from './packageManager/IInstallDependencies';
11+
import { DependencyInstallationStatus, IInstallDependencies } from './packageManager/IInstallDependencies';
1212
import { AbsolutePathPackage } from './packageManager/absolutePathPackage';
1313

1414
export async function installRuntimeDependencies(
@@ -19,31 +19,39 @@ export async function installRuntimeDependencies(
1919
platformInfo: PlatformInformation,
2020
useFramework: boolean,
2121
requiredPackageIds: string[]
22-
): Promise<DependencyInstallationResults> {
22+
): Promise<DependencyInstallationStatus> {
2323
const runTimeDependencies = getRuntimeDependenciesPackages(packageJSON);
2424
const packagesToInstall = await getAbsolutePathPackagesToInstall(runTimeDependencies, platformInfo, extensionPath);
25+
26+
// PackagesToInstall will only return packages that are not already installed. However,
27+
// we need to return the installation status of all required packages, so we need to
28+
// track which required packages are already installed, so that we can return true for them.
29+
const installedPackages = requiredPackageIds.filter(
30+
(id) => packagesToInstall.find((pkg) => pkg.id === id) === undefined
31+
);
32+
const installedPackagesResults = installedPackages.reduce((acc, id) => ({ ...acc, [id]: true }), {});
33+
2534
const filteredPackages = filterOmniSharpPackage(packagesToInstall, useFramework);
2635
const filteredRequiredPackages = filteredRequiredPackage(requiredPackageIds, filteredPackages);
2736

28-
if (filteredRequiredPackages.length > 0) {
29-
eventStream.post(new PackageInstallation('C# dependencies'));
30-
// Display platform information and RID
31-
eventStream.post(new LogPlatformInfo(platformInfo));
37+
if (filteredRequiredPackages.length === 0) {
38+
return installedPackagesResults;
39+
}
3240

33-
const installationResults = await installDependencies(filteredRequiredPackages);
41+
eventStream.post(new PackageInstallation('C# dependencies'));
42+
// Display platform information and RID
43+
eventStream.post(new LogPlatformInfo(platformInfo));
3444

35-
const failedPackages = Object.entries(installationResults)
36-
.filter(([, installed]) => !installed)
37-
.map(([name]) => name);
38-
if (failedPackages.length === 0) {
39-
eventStream.post(new InstallationSuccess());
40-
}
45+
const installationResults = await installDependencies(filteredRequiredPackages);
4146

42-
return installationResults;
47+
const failedPackages = Object.entries(installationResults)
48+
.filter(([, installed]) => !installed)
49+
.map(([name]) => name);
50+
if (failedPackages.length === 0) {
51+
eventStream.post(new InstallationSuccess());
4352
}
4453

45-
// There was nothing to install
46-
return {};
54+
return { ...installedPackagesResults, ...installationResults };
4755
}
4856

4957
function filterOmniSharpPackage(packages: AbsolutePathPackage[], useFramework: boolean) {

src/packageManager/IInstallDependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import { AbsolutePathPackage } from './absolutePathPackage';
77

8-
export type DependencyInstallationResults = { [name: string]: boolean };
8+
export type DependencyInstallationStatus = { [name: string]: boolean };
99

1010
export interface IInstallDependencies {
11-
(packages: AbsolutePathPackage[]): Promise<DependencyInstallationResults>;
11+
(packages: AbsolutePathPackage[]): Promise<DependencyInstallationStatus>;
1212
}

src/packageManager/downloadAndInstallPackages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { PackageInstallStart } from '../shared/loggingEvents';
1717
import { DownloadValidator } from './isValidDownload';
1818
import { CancellationToken } from 'vscode';
1919
import { ITelemetryReporter } from '../shared/telemetryReporter';
20-
import { DependencyInstallationResults } from './IInstallDependencies';
20+
import { DependencyInstallationStatus } from './IInstallDependencies';
2121

2222
export async function downloadAndInstallPackages(
2323
packages: AbsolutePathPackage[],
@@ -26,9 +26,9 @@ export async function downloadAndInstallPackages(
2626
downloadValidator: DownloadValidator,
2727
telemetryReporter?: ITelemetryReporter,
2828
token?: CancellationToken
29-
): Promise<DependencyInstallationResults> {
29+
): Promise<DependencyInstallationStatus> {
3030
eventStream.post(new PackageInstallStart());
31-
const results: DependencyInstallationResults = {};
31+
const results: DependencyInstallationStatus = {};
3232
for (const pkg of packages) {
3333
let installationStage = 'touchBeginFile';
3434
try {

0 commit comments

Comments
 (0)