|
1 | 1 | // Copyright (c) Microsoft Corporation.
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -import { spawn } from "child_process"; |
5 |
| -import * as fs from "fs"; // TODO: Remove, but it's for a stream. |
6 | 4 | import fetch from "node-fetch";
|
7 |
| -import * as os from "os"; |
8 |
| -import * as path from "path"; |
9 | 5 | import { SemVer } from "semver";
|
10 |
| -import * as stream from "stream"; |
11 |
| -import * as util from "util"; |
12 | 6 | import vscode = require("vscode");
|
13 | 7 |
|
14 | 8 | import { ILogger } from "../logging";
|
15 |
| -import { IPowerShellVersionDetails, SessionManager } from "../session"; |
| 9 | +import { IPowerShellVersionDetails } from "../session"; |
16 | 10 | import { changeSetting, Settings } from "../settings";
|
17 |
| -import { isWindows } from "../utils"; |
18 |
| - |
19 |
| -const streamPipeline = util.promisify(stream.pipeline); |
20 | 11 |
|
21 | 12 | interface IUpdateMessageItem extends vscode.MessageItem {
|
22 | 13 | id: number;
|
@@ -29,7 +20,6 @@ export class UpdatePowerShell {
|
29 | 20 | private static LTSBuildInfoURL = "https://aka.ms/pwsh-buildinfo-lts";
|
30 | 21 | private static StableBuildInfoURL = "https://aka.ms/pwsh-buildinfo-stable";
|
31 | 22 | private static PreviewBuildInfoURL = "https://aka.ms/pwsh-buildinfo-preview";
|
32 |
| -private static APIReleaseURL = "https://api..com/repos/PowerShell/PowerShell/releases/tags/"; |
33 | 23 | private static WebReleaseURL = "https://.com/PowerShell/PowerShell/releases/tag/";
|
34 | 24 | private static promptOptions: IUpdateMessageItem[] = [
|
35 | 25 | {
|
@@ -46,10 +36,8 @@ export class UpdatePowerShell {
|
46 | 36 | },
|
47 | 37 | ];
|
48 | 38 | private localVersion: SemVer;
|
49 |
| -private architecture: string; |
50 | 39 |
|
51 | 40 | constructor(
|
52 |
| -private sessionManager: SessionManager, |
53 | 41 | private sessionSettings: Settings,
|
54 | 42 | private logger: ILogger,
|
55 | 43 | versionDetails: IPowerShellVersionDetails) {
|
@@ -58,7 +46,6 @@ export class UpdatePowerShell {
|
58 | 46 | // to SemVer. The version handler in PSES handles Windows PowerShell and
|
59 | 47 | // just returns the first three fields like '5.1.22621'.
|
60 | 48 | this.localVersion = new SemVer(versionDetails.commit);
|
61 |
| -this.architecture = versionDetails.architecture.toLowerCase(); |
62 | 49 | }
|
63 | 50 |
|
64 | 51 | private shouldCheckForUpdate(): boolean {
|
@@ -173,74 +160,13 @@ export class UpdatePowerShell {
|
173 | 160 | await vscode.env.openExternal(url);
|
174 | 161 | }
|
175 | 162 |
|
176 |
| -private async updateWindows(tag: string): Promise<void> { |
177 |
| -let msiMatcher: string; |
178 |
| -if (this.architecture === "x64") { |
179 |
| -msiMatcher = "win-x64.msi"; |
180 |
| -} else if (this.architecture === "x86") { |
181 |
| -msiMatcher = "win-x86.msi"; |
182 |
| -} else { |
183 |
| -// We shouldn't get here, but do something sane anyway. |
184 |
| -return this.openReleaseInBrowser(tag); |
185 |
| -} |
186 |
| - |
187 |
| -let response = await fetch(UpdatePowerShell.APIReleaseURL + tag); |
188 |
| -if (!response.ok) { |
189 |
| -throw new Error("Failed to fetch release info!"); |
190 |
| -} |
191 |
| -const release = await response.json(); |
192 |
| - |
193 |
| -// eslint-disable-next-line @typescript-eslint/no-explicit-any |
194 |
| -const asset = release.assets.filter((a: any) => a.name.indexOf(msiMatcher) >= 0)[0]; |
195 |
| -const msiDownloadPath = path.join(os.tmpdir(), asset.name); |
196 |
| - |
197 |
| -response = await fetch(asset.browser_download_url); |
198 |
| -if (!response.ok) { |
199 |
| -throw new Error("Failed to fetch MSI!"); |
200 |
| -} |
201 |
| - |
202 |
| -const progressOptions = { |
203 |
| -title: "Downloading PowerShell Installer...", |
204 |
| -location: vscode.ProgressLocation.Notification, |
205 |
| -cancellable: false, |
206 |
| -}; |
207 |
| -// Streams the body of the request to a file. |
208 |
| -await vscode.window.withProgress(progressOptions, |
209 |
| -async () => { await streamPipeline(response.body, fs.createWriteStream(msiDownloadPath)); }); |
210 |
| - |
211 |
| -// Stop the session because Windows likes to hold on to files. |
212 |
| -this.logger.writeDiagnostic("MSI downloaded, stopping session and closing terminals!"); |
213 |
| -await this.sessionManager.stop(); |
214 |
| - |
215 |
| -// Close all terminals with the name "pwsh" in the current VS Code session. |
216 |
| -// This will encourage folks to not close the instance of VS Code that spawned |
217 |
| -// the MSI process. |
218 |
| -for (const terminal of vscode.window.terminals) { |
219 |
| -if (terminal.name === "pwsh") { |
220 |
| -terminal.dispose(); |
221 |
| -} |
222 |
| -} |
223 |
| - |
224 |
| -// Invoke the MSI via cmd. |
225 |
| -this.logger.writeDiagnostic(`Running '${msiDownloadPath}' to update PowerShell...`); |
226 |
| -const msi = spawn("msiexec", ["/i", msiDownloadPath]); |
227 |
| - |
228 |
| -msi.on("close", () => { |
229 |
| -// Now that the MSI is finished, restart the session. |
230 |
| -this.logger.writeDiagnostic("MSI installation finished, restarting session."); |
231 |
| -void this.sessionManager.start(); |
232 |
| -fs.unlinkSync(msiDownloadPath); |
233 |
| -}); |
234 |
| -} |
235 |
| - |
236 | 163 | private async installUpdate(tag: string): Promise<void> {
|
237 | 164 | const releaseVersion = new SemVer(tag);
|
238 | 165 | const result = await vscode.window.showInformationMessage(
|
239 |
| -`You have an old version of PowerShell (${this.localVersion.version}). The current latest release is ${releaseVersion.version}. |
240 |
| -Would you like to update the version? ${isWindows |
241 |
| -? "This will close ALL pwsh terminals running in this VS Code session!" |
242 |
| -: "We can't update you automatically, but we can open the latest release in your browser!" |
243 |
| -}`, ...UpdatePowerShell.promptOptions); |
| 166 | +`You have an old version of PowerShell (${this.localVersion.version}). |
| 167 | +The current latest release is ${releaseVersion.version}. |
| 168 | +Would you like to open the release in your browser?`, |
| 169 | +...UpdatePowerShell.promptOptions); |
244 | 170 |
|
245 | 171 | // If the user cancels the notification.
|
246 | 172 | if (!result) {
|
@@ -253,11 +179,7 @@ export class UpdatePowerShell {
|
253 | 179 | switch (result.id) {
|
254 | 180 | // Yes
|
255 | 181 | case 0:
|
256 |
| -if (isWindows && (this.architecture === "x64" || this.architecture === "x86")) { |
257 |
| -await this.updateWindows(tag); |
258 |
| -} else { |
259 |
| -await this.openReleaseInBrowser(tag); |
260 |
| -} |
| 182 | +await this.openReleaseInBrowser(tag); |
261 | 183 | break;
|
262 | 184 | // Not Now
|
263 | 185 | case 1:
|
|
0 commit comments