|
11 | 11 | // SPDX-License-Identifier: Apache-2.0 |
12 | 12 | // |
13 | 13 | //===----------------------------------------------------------------------===// |
| 14 | +import { ExecFileOptions } from "child_process"; |
14 | 15 | import * as fsSync from "fs"; |
15 | 16 | import * as fs from "fs/promises"; |
16 | 17 | import * as os from "os"; |
@@ -273,9 +274,9 @@ export class Swiftly { |
273 | 274 | if (!Array.isArray(installedToolchains)) { |
274 | 275 | return []; |
275 | 276 | } |
276 | | - return installedToolchains |
277 | | - .filter((toolchain): toolchain is string => typeof toolchain === "string") |
278 | | - .map(toolchain => path.join(swiftlyHomeDir, "toolchains", toolchain)); |
| 277 | + return installedToolchains.filter( |
| 278 | + (toolchain): toolchain is string => typeof toolchain === "string" |
| 279 | + ); |
279 | 280 | } catch (error) { |
280 | 281 | logger?.error(`Failed to retrieve Swiftly installations: ${error}`); |
281 | 282 | throw new Error( |
@@ -333,12 +334,21 @@ export class Swiftly { |
333 | 334 | * Instructs Swiftly to use a specific version of the Swift toolchain. |
334 | 335 | * |
335 | 336 | * @param version The version name to use. Obtainable via {@link Swiftly.list}. |
| 337 | + * @param [cwd] Optional working directory to set the toolchain within. |
336 | 338 | */ |
337 | | - public static async use(version: string): Promise<void> { |
| 339 | + public static async use(version: string, cwd?: string): Promise<void> { |
338 | 340 | if (!this.isSupported()) { |
339 | 341 | throw new Error("Swiftly is not supported on this platform"); |
340 | 342 | } |
341 | | - await execFile("swiftly", ["use", version]); |
| 343 | + const useArgs = ["use", "-y"]; |
| 344 | + const options: ExecFileOptions = {}; |
| 345 | + if (cwd) { |
| 346 | + options.cwd = cwd; |
| 347 | + } else { |
| 348 | + useArgs.push("--global-default"); |
| 349 | + } |
| 350 | + useArgs.push(version); |
| 351 | + await execFile("swiftly", useArgs, options); |
342 | 352 | } |
343 | 353 |
|
344 | 354 | /** |
|
0 commit comments