Skip to content

Commit 1792ad5

Browse files
authored
Merge pull request #5255 from 50Wliu/users/winstonliu/misc-nullability
Package manager nullability fixes
2 parents a9d0b56 + 5b8983c commit 1792ad5

30 files changed

+214
-274
lines changed

package-lock.json

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@
9191
"@types/gulp": "4.0.5",
9292
"@types/minimist": "1.2.1",
9393
"@types/mocha": "5.2.5",
94-
"@types/node": "10.12.24",
94+
"@types/node": "16.11.38",
9595
"@types/semver": "5.5.0",
9696
"@types/tmp": "0.0.33",
9797
"@types/unzipper": "^0.9.1",
9898
"@types/vscode": "1.66.0",
99-
"@types/yauzl": "2.9.1",
99+
"@types/yauzl": "2.10.0",
100100
"@vscode/test-electron": "2.1.3",
101101
"archiver": "5.3.0",
102102
"chai": "4.3.4",
@@ -230,6 +230,9 @@
230230
"platforms": [
231231
"darwin"
232232
],
233+
"architectures": [
234+
"x86_64"
235+
],
233236
"binaries": [
234237
"./mono.osx",
235238
"./run"

src/common.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ export function getUnixTempDirectory(){
3333
return envTmp;
3434
}
3535

36-
export function isBoolean(obj: any): obj is boolean {
37-
return obj === true || obj === false;
38-
}
39-
4036
export function sum<T>(arr: T[], selector: (item: T) => number): number {
4137
return arr.reduce((prev, curr) => prev + selector(curr), 0);
4238
}

src/coreclr-debug/activate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function checkIsValidArchitecture(platformInformation: PlatformInformation
4848
}
4949

5050
// Validate we are on compatiable macOS version if we are x86_64
51-
if ((platformInformation.architecture !== "x86_64") ||
51+
if ((platformInformation.architecture !== "x86_64") ||
5252
(platformInformation.architecture === "x86_64" && !CoreClrDebugUtil.isMacOSSupported())) {
5353
eventStream.post(new DebuggerPrerequisiteFailure("[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer."));
5454
return false;
@@ -149,8 +149,8 @@ export class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescrip
149149

150150
// install.Lock does not exist, need to wait for packages to finish downloading.
151151
let installLock = false;
152-
let debuggerPackage = getRuntimeDependencyPackageWithId("Debugger", this.packageJSON, this.platformInfo, this.extensionPath);
153-
if (debuggerPackage && debuggerPackage.installPath) {
152+
const debuggerPackage = getRuntimeDependencyPackageWithId("Debugger", this.packageJSON, this.platformInfo, this.extensionPath);
153+
if (debuggerPackage?.installPath) {
154154
installLock = await common.installFileExists(debuggerPackage.installPath, common.InstallFileType.Lock);
155155
}
156156

src/observers/TelemetryObserver.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ export class TelemetryObserver {
8282
if (event.error instanceof PackageError) {
8383
// we can log the message in a PackageError to telemetry as we do not put PII in PackageError messages
8484
telemetryProps['error.message'] = event.error.message;
85-
86-
if (event.error.pkg) {
87-
telemetryProps['error.packageUrl'] = event.error.pkg.url;
88-
}
85+
telemetryProps['error.packageUrl'] = event.error.pkg.url;
8986
}
9087

9188
this.reporter.sendTelemetryEvent('AcquisitionFailed', telemetryProps);

src/omnisharp/OmnisharpDownloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class OmnisharpDownloader {
2828
let runtimeDependencies = getRuntimeDependenciesPackages(this.packageJSON);
2929
let omniSharpPackages = GetPackagesFromVersion(version, useFramework, runtimeDependencies, serverUrl, installPath);
3030
let packagesToInstall = await getAbsolutePathPackagesToInstall(omniSharpPackages, this.platformInfo, this.extensionPath);
31-
if (packagesToInstall && packagesToInstall.length > 0) {
31+
if (packagesToInstall.length > 0) {
3232
this.eventStream.post(new PackageInstallation(`OmniSharp Version = ${version}`));
3333
this.eventStream.post(new LogPlatformInfo(this.platformInfo));
3434
if (await downloadAndInstallPackages(packagesToInstall, this.networkSettingsProvider, this.eventStream, isValidDownload, useFramework)) {

src/omnisharp/OmnisharpPackageCreator.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ import { Package } from "../packageManager/Package";
88
export const modernNetVersion = "6.0";
99

1010
export function GetPackagesFromVersion(version: string, useFramework: boolean, runTimeDependencies: Package[], serverUrl: string, installPath: string): Package[] {
11-
if (!version) {
12-
throw new Error('Invalid version');
13-
}
14-
15-
let versionPackages = new Array<Package>();
16-
for (let inputPackage of runTimeDependencies) {
17-
if (inputPackage.platformId && inputPackage.isFramework === useFramework) {
18-
versionPackages.push(SetBinaryAndGetPackage(inputPackage, useFramework, serverUrl, version, installPath));
19-
}
20-
}
21-
22-
return versionPackages;
11+
return runTimeDependencies
12+
.filter(inputPackage =>
13+
inputPackage.platformId !== undefined && inputPackage.isFramework === useFramework)
14+
.map(inputPackage =>
15+
SetBinaryAndGetPackage(inputPackage, useFramework, serverUrl, version, installPath));
2316
}
2417

2518
export function SetBinaryAndGetPackage(inputPackage: Package, useFramework: boolean, serverUrl: string, version: string, installPath: string): Package {
@@ -28,7 +21,7 @@ export function SetBinaryAndGetPackage(inputPackage: Package, useFramework: bool
2821
// .NET 6 packages use system `dotnet OmniSharp.dll`
2922
installBinary = 'OmniSharp.dll';
3023
}
31-
else if (inputPackage.platformId === 'win-x86' || inputPackage.platformId === 'win-x64' || inputPackage.platformId === 'win-arm64') {
24+
else if (inputPackage.platforms.includes('win32')) {
3225
installBinary = 'OmniSharp.exe';
3326
}
3427
else {
@@ -39,25 +32,13 @@ export function SetBinaryAndGetPackage(inputPackage: Package, useFramework: bool
3932
}
4033

4134
function GetPackage(inputPackage: Package, useFramework: boolean, serverUrl: string, version: string, installPath: string, installBinary: string): Package {
42-
if (!version) {
43-
throw new Error('Invalid version');
44-
}
45-
4635
const packageSuffix = useFramework ? '' : `-net${modernNetVersion}`;
4736

48-
let versionPackage: Package = {
49-
id: inputPackage.id,
37+
return {
38+
...inputPackage,
5039
description: `${inputPackage.description}, Version = ${version}`,
5140
url: `${serverUrl}/releases/${version}/omnisharp-${inputPackage.platformId}${packageSuffix}.zip`,
5241
installPath: `${installPath}/${version}${packageSuffix}`,
5342
installTestPath: `./${installPath}/${version}${packageSuffix}/${installBinary}`,
54-
platforms: inputPackage.platforms,
55-
architectures: inputPackage.architectures,
56-
binaries: inputPackage.binaries,
57-
platformId: inputPackage.platformId,
58-
isFramework: useFramework
5943
};
60-
61-
return versionPackage;
6244
}
63-

src/packageManager/AbsolutePath.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { isAbsolute, resolve } from "path";
6+
import * as path from "path";
77

88
export class AbsolutePath {
99
constructor(public value: string) {
10-
if (!isAbsolute(value)) {
10+
if (!path.isAbsolute(value)) {
1111
throw new Error("The path must be absolute");
1212
}
1313
}
1414

1515
public static getAbsolutePath(...pathSegments: string[]): AbsolutePath {
16-
return new AbsolutePath(resolve(...pathSegments));
16+
return new AbsolutePath(path.resolve(...pathSegments));
1717
}
18-
}
18+
}

src/packageManager/AbsolutePathPackage.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class AbsolutePathPackage implements IPackage {
1313
public url: string,
1414
public platforms: string[],
1515
public architectures: string[],
16-
public binaries: AbsolutePath[],
17-
public installPath?: AbsolutePath,
16+
public installPath: AbsolutePath,
17+
public binaries?: AbsolutePath[],
1818
public installTestPath?: AbsolutePath,
1919
public fallbackUrl?: string,
2020
public platformId?: string,
@@ -29,8 +29,8 @@ export class AbsolutePathPackage implements IPackage {
2929
pkg.url,
3030
pkg.platforms,
3131
pkg.architectures,
32-
getAbsoluteBinaries(pkg, extensionPath),
3332
getAbsoluteInstallPath(pkg, extensionPath),
33+
getAbsoluteBinaries(pkg, extensionPath),
3434
getAbsoluteInstallTestPath(pkg, extensionPath),
3535
pkg.fallbackUrl,
3636
pkg.platformId,
@@ -40,27 +40,23 @@ export class AbsolutePathPackage implements IPackage {
4040
}
4141
}
4242

43-
function getAbsoluteInstallTestPath(pkg: Package, extensionPath: string): AbsolutePath {
44-
if (pkg.installTestPath) {
43+
function getAbsoluteInstallTestPath(pkg: Package, extensionPath: string): AbsolutePath | undefined {
44+
if (pkg.installTestPath !== undefined) {
4545
return AbsolutePath.getAbsolutePath(extensionPath, pkg.installTestPath);
4646
}
4747

48-
return null;
48+
return undefined;
4949
}
5050

51-
function getAbsoluteBinaries(pkg: Package, extensionPath: string): AbsolutePath[] {
52-
let basePath = getAbsoluteInstallPath(pkg, extensionPath).value;
53-
if (pkg.binaries) {
54-
return pkg.binaries.map(value => AbsolutePath.getAbsolutePath(basePath, value));
55-
}
56-
57-
return null;
51+
function getAbsoluteBinaries(pkg: Package, extensionPath: string): AbsolutePath[] | undefined {
52+
const basePath = getAbsoluteInstallPath(pkg, extensionPath).value;
53+
return pkg.binaries?.map(value => AbsolutePath.getAbsolutePath(basePath, value));
5854
}
5955

6056
function getAbsoluteInstallPath(pkg: Package, extensionPath: string): AbsolutePath {
61-
if (pkg.installPath) {
57+
if (pkg.installPath !== undefined) {
6258
return AbsolutePath.getAbsolutePath(extensionPath, pkg.installPath);
6359
}
6460

6561
return new AbsolutePath(extensionPath);
66-
}
62+
}

src/packageManager/FileDownloader.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as https from 'https';
7-
import * as util from '../common';
87
import { EventStream } from "../EventStream";
98
import { DownloadSuccess, DownloadStart, DownloadFallBack, DownloadFailure, DownloadProgress, DownloadSizeObtained } from "../omnisharp/loggingEvents";
109
import { NestedError } from "../NestedError";
@@ -24,7 +23,7 @@ export async function DownloadFile(description: string, eventStream: EventStream
2423
// If the package has a fallback Url, and downloading from the primary Url failed, try again from
2524
// the fallback. This is used for debugger packages as some users have had issues downloading from
2625
// the CDN link
27-
if (fallbackUrl) {
26+
if (fallbackUrl !== undefined) {
2827
eventStream.post(new DownloadFallBack(fallbackUrl));
2928
try {
3029
let buffer = await downloadFile(description, fallbackUrl, eventStream, networkSettingsProvider);
@@ -51,7 +50,7 @@ async function downloadFile(description: string, urlString: string, eventStream:
5150
path: url.path,
5251
agent: getProxyAgent(url, proxy, strictSSL),
5352
port: url.port,
54-
rejectUnauthorized: util.isBoolean(strictSSL) ? strictSSL : true
53+
rejectUnauthorized: strictSSL,
5554
};
5655

5756
let buffers: any[] = [];
@@ -60,13 +59,21 @@ async function downloadFile(description: string, urlString: string, eventStream:
6059
let request = https.request(options, response => {
6160
if (response.statusCode === 301 || response.statusCode === 302) {
6261
// Redirect - download from new location
62+
if (response.headers.location === undefined) {
63+
eventStream.post(new DownloadFailure(`Failed to download from ${urlString}. Redirected without location header`));
64+
return reject(new NestedError('Missing location'));
65+
}
6366
return resolve(downloadFile(description, response.headers.location, eventStream, networkSettingsProvider));
6467
}
65-
66-
else if (response.statusCode != 200) {
68+
else if (response.statusCode !== 200) {
6769
// Download failed - print error message
6870
eventStream.post(new DownloadFailure(`Failed to download from ${urlString}. Error code '${response.statusCode}')`));
69-
return reject(new NestedError(response.statusCode.toString()));
71+
return reject(new NestedError(response.statusCode!.toString())); // Known to exist because this is from a ClientRequest
72+
}
73+
74+
if (response.headers['content-length'] === undefined) {
75+
eventStream.post(new DownloadFailure(`Failed to download from ${urlString}. No content-length header`));
76+
return reject(new NestedError('Missing content-length'));
7077
}
7178

7279
// Downloading - hook up events
@@ -104,4 +111,4 @@ async function downloadFile(description: string, urlString: string, eventStream:
104111
// Execute the request
105112
request.end();
106113
});
107-
}
114+
}

0 commit comments

Comments
 (0)