diff --git a/src/commands/installSwiftlyToolchain.ts b/src/commands/installSwiftlyToolchain.ts index 1dcc335c0..99545811b 100644 --- a/src/commands/installSwiftlyToolchain.ts +++ b/src/commands/installSwiftlyToolchain.ts @@ -49,31 +49,36 @@ export async function installSwiftlyToolchainWithProgress( await Swiftly.installToolchain( version, (progressData: SwiftlyProgressData) => { - if ( - progressData.step?.percent !== undefined && - progressData.step.percent > lastProgress - ) { - const increment = progressData.step.percent - lastProgress; + if (progressData.complete) { + // Swiftly will also verify the signature and extract the toolchain after the + // "complete" message has been sent, but does not report progress for this. + // Provide a suitable message in this case and reset the progress back to an + // indeterminate state (0) since we don't know how long it will take. progress.report({ - increment, - message: - progressData.step.text ?? - `${progressData.step.percent}% complete`, + message: "Verifying signature and extracting...", + increment: -lastProgress, }); - lastProgress = progressData.step.percent; + return; } + if (!progressData.step) { + return; + } + const increment = progressData.step.percent - lastProgress; + progress.report({ + increment, + message: + progressData.step.text ?? `${progressData.step.percent}% complete`, + }); + lastProgress = progressData.step.percent; }, logger, token ); - - progress.report({ - increment: 100 - lastProgress, - message: "Installation complete", - }); } ); + void vscode.window.showInformationMessage(`Successfully installed Swift ${version}`); + return true; } catch (error) { const errorMessage = (error as Error).message; @@ -83,7 +88,7 @@ export async function installSwiftlyToolchainWithProgress( return false; } - logger?.error(`Failed to install Swift ${version}: ${error}`); + logger?.error(new Error(`Failed to install Swift ${version}`, { cause: error })); void vscode.window.showErrorMessage(`Failed to install Swift ${version}: ${error}`); return false; } diff --git a/src/toolchain/swiftly.ts b/src/toolchain/swiftly.ts index 771a0cceb..7e58c1a31 100644 --- a/src/toolchain/swiftly.ts +++ b/src/toolchain/swiftly.ts @@ -104,13 +104,21 @@ const InUseVersionResult = z.object({ version: z.string(), }); -export interface SwiftlyProgressData { - step?: { - text?: string; - timestamp?: number; - percent?: number; - }; -} +const SwiftlyProgressData = z.object({ + complete: z.optional( + z.object({ + success: z.boolean(), + }) + ), + step: z.optional( + z.object({ + text: z.string(), + percent: z.number(), + }) + ), +}); + +export type SwiftlyProgressData = z.infer; export interface PostInstallValidationResult { isValid: boolean; @@ -510,10 +518,12 @@ export class Swiftly { } try { - const progressData = JSON.parse(line.trim()) as SwiftlyProgressData; + const progressData = SwiftlyProgressData.parse(JSON.parse(line)); progressCallback(progressData); - } catch (err) { - logger?.error(`Failed to parse progress line: ${err}`); + } catch (error) { + logger?.error( + new Error(`Failed to parse Swiftly progress: ${line}`, { cause: error }) + ); } }); diff --git a/tsconfig-base.json b/tsconfig-base.json index b2cabb90b..0a88c91b3 100644 --- a/tsconfig-base.json +++ b/tsconfig-base.json @@ -5,8 +5,8 @@ "rootDir": ".", "outDir": "dist", - "lib": ["ES2021"], - "target": "ES2020", + "lib": ["ES2022"], + "target": "ES2022", "module": "commonjs", "strict": true,