Skip to content

Commit 0a66c89

Browse files
committed
Use GitCommitId to avoid pointless update checks
And remove an unused `IRunspaceDetails` interface.
1 parent 2698ac1 commit 0a66c89

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

src/features/UpdatePowerShell.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class UpdatePowerShell {
5353
private sessionSettings: Settings,
5454
private logger: ILogger,
5555
versionDetails: IPowerShellVersionDetails) {
56-
this.localVersion = new SemVer(versionDetails.version);
56+
// We use the commit field as it's like
57+
// '7.3.0-preview.3-508-g07175ae0ff8eb7306fe0b0fc7d...' which translates
58+
// to SemVer. The version handler in PSES handles Windows PowerShell and
59+
// just returns the first three fields like '5.1.22621'.
60+
this.localVersion = new SemVer(versionDetails.commit);
5761
this.architecture = versionDetails.architecture.toLowerCase();
5862
}
5963

@@ -77,8 +81,22 @@ export class UpdatePowerShell {
7781
return false;
7882
}
7983

80-
// TODO: Check if PowerShell is self-built, i.e. PSVersionInfo.GitCommitId.Length > 40.
81-
// TODO: Check if preview is a daily build.
84+
if (this.localVersion.prerelease.length > 1) {
85+
const prerelease = this.localVersion.prerelease[1].toString();
86+
87+
// Skip if PowerShell is self-built, that is, this contains a commit hash.
88+
if (prerelease.length >= 40) {
89+
this.logger.writeDiagnostic("Not offering to update development build.");
90+
return false;
91+
}
92+
93+
// Skip if preview is a daily build.
94+
if (prerelease.toLowerCase().match("daily")) {
95+
this.logger.writeDiagnostic("Not offering to update daily build.");
96+
return false;
97+
}
98+
}
99+
82100
// TODO: Check if network is available?
83101
// TODO: Only check once a week.
84102
this.logger.writeDiagnostic("Should check for PowerShell update.");

src/session.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
OperatingSystem, PowerShellExeFinder
2525
} from "./platform";
2626
import { LanguageClientConsumer } from "./languageClientConsumer";
27+
import { SemVer } from "semver";
2728

2829
export enum SessionStatus {
2930
NeverStarted,
@@ -54,17 +55,11 @@ export interface IEditorServicesSessionDetails {
5455

5556
export interface IPowerShellVersionDetails {
5657
version: string;
57-
displayVersion: string;
5858
edition: string;
59+
commit: string;
5960
architecture: string;
6061
}
6162

62-
export interface IRunspaceDetails {
63-
powerShellVersion: IPowerShellVersionDetails;
64-
runspaceType: RunspaceType;
65-
connectionString: string;
66-
}
67-
6863
export type IReadSessionFileCallback = (details: IEditorServicesSessionDetails) => void;
6964

7065
export const SendKeyPressNotificationType =
@@ -734,12 +729,9 @@ Type 'help' to get help.
734729
this.languageStatusItem.detail = "PowerShell";
735730

736731
if (this.versionDetails !== undefined) {
737-
const version = this.versionDetails.architecture.toLowerCase() !== "x64"
738-
? `${this.versionDetails.displayVersion} (${this.versionDetails.architecture.toLowerCase()})`
739-
: this.versionDetails.displayVersion;
740-
741-
this.languageStatusItem.text = "$(terminal-powershell) " + version;
742-
this.languageStatusItem.detail += " " + version;
732+
const semver = new SemVer(this.versionDetails.version);
733+
this.languageStatusItem.text = `$(terminal-powershell) ${semver.major}.${semver.minor}`;
734+
this.languageStatusItem.detail += ` ${this.versionDetails.commit} (${this.versionDetails.architecture.toLowerCase()})`;
743735
}
744736

745737
if (statusText) {
@@ -835,7 +827,7 @@ Type 'help' to get help.
835827
const powerShellSessionName =
836828
currentPowerShellExe ?
837829
currentPowerShellExe.displayName :
838-
`PowerShell ${this.versionDetails.displayVersion} ` +
830+
`PowerShell ${this.versionDetails.version} ` +
839831
`(${this.versionDetails.architecture.toLowerCase()}) ${this.versionDetails.edition} Edition ` +
840832
`[${this.versionDetails.version}]`;
841833

test/features/UpdatePowerShell.test.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ describe("UpdatePowerShell feature", function () {
2727
process.env.POWERSHELL_UPDATECHECK = "Default";
2828
const version: IPowerShellVersionDetails = {
2929
"version": "7.3.0",
30-
"displayVersion": "7.3",
3130
"edition": "Core",
31+
"commit": "7.3.0",
3232
"architecture": "X64"
3333
};
3434
// @ts-expect-error testing doesn't require all arguments.
@@ -39,10 +39,9 @@ describe("UpdatePowerShell feature", function () {
3939

4040
it("Won't check for Windows PowerShell", function () {
4141
const version: IPowerShellVersionDetails = {
42-
// TODO: This should handle e.g. 5.1.22621.436
43-
"version": "5.1.0",
44-
"displayVersion": "5.1",
42+
"version": "5.1.22621",
4543
"edition": "Desktop",
44+
"commit": "5.1.22621",
4645
"architecture": "X64"
4746
};
4847
// @ts-expect-error testing doesn't require all arguments.
@@ -51,12 +50,25 @@ describe("UpdatePowerShell feature", function () {
5150
assert(!updater.shouldCheckForUpdate());
5251
});
5352

53+
it("Won't check for a development build of PowerShell", function () {
54+
const version: IPowerShellVersionDetails = {
55+
"version": "7.3.0-preview.3",
56+
"edition": "Core",
57+
"commit": "7.3.0-preview.3-508-g07175ae0ff8eb7306fe0b0fc7d19bdef4fbf2d67",
58+
"architecture": "Arm64"
59+
};
60+
// @ts-expect-error testing doesn't require all arguments.
61+
const updater = new UpdatePowerShell(undefined, settings, testLogger, version);
62+
// @ts-expect-error method is private.
63+
assert(!updater.shouldCheckForUpdate());
64+
});
65+
5466
it("Won't check if POWERSHELL_UPDATECHECK is 'Off'", function () {
5567
process.env.POWERSHELL_UPDATECHECK = "Off";
5668
const version: IPowerShellVersionDetails = {
5769
"version": "7.3.0",
58-
"displayVersion": "7.3",
5970
"edition": "Core",
71+
"commit": "7.3.0",
6072
"architecture": "X64"
6173
};
6274
// @ts-expect-error testing doesn't require all arguments.
@@ -69,8 +81,8 @@ describe("UpdatePowerShell feature", function () {
6981
process.env.POWERSHELL_UPDATECHECK = "Default";
7082
const version: IPowerShellVersionDetails = {
7183
"version": "7.3.0",
72-
"displayVersion": "7.3",
7384
"edition": "Core",
85+
"commit": "7.3.0",
7486
"architecture": "X64"
7587
};
7688
// @ts-expect-error testing doesn't require all arguments.
@@ -85,8 +97,8 @@ describe("UpdatePowerShell feature", function () {
8597
process.env.POWERSHELL_UPDATECHECK = "LTS";
8698
const version: IPowerShellVersionDetails = {
8799
"version": "7.0.0",
88-
"displayVersion": "7.0",
89100
"edition": "Core",
101+
"commit": "7.0.0",
90102
"architecture": "X64"
91103
};
92104
// @ts-expect-error testing doesn't require all arguments.
@@ -100,8 +112,8 @@ describe("UpdatePowerShell feature", function () {
100112
it("Would update to stable", async function() {
101113
const version: IPowerShellVersionDetails = {
102114
"version": "7.0.0",
103-
"displayVersion": "7.0",
104115
"edition": "Core",
116+
"commit": "7.0.0",
105117
"architecture": "X64"
106118
};
107119
// @ts-expect-error testing doesn't require all arguments.

0 commit comments

Comments
 (0)