diff --git a/cli/src/commands/dep/versions.ts b/cli/src/commands/dep/versions.ts index b6536717a..a3bcb390d 100644 --- a/cli/src/commands/dep/versions.ts +++ b/cli/src/commands/dep/versions.ts @@ -26,7 +26,7 @@ import { initCli } from "../../lib/lifeCycle.js"; import { ensureMarinePath, ensureMreplPath } from "../../lib/marineCli.js"; import { getRustToolchainToUse, - resolveMarineAndMreplDependencies, + getMarineOrMreplVersion, } from "../../lib/rust.js"; import CLIPackageJSON from "../../versions/cli.package.json" assert { type: "json" }; import JSClientPackageJSON from "../../versions/js-client.package.json" assert { type: "json" }; @@ -85,24 +85,16 @@ export default class Versions extends BaseCommand { maybeFluenceConfig === null ? versions.npm : maybeFluenceConfig.aquaDependencies, - tools: Object.fromEntries( - await Promise.all( - (await resolveMarineAndMreplDependencies()).map( - async ([tool, version]) => { - return [ - tool, - { - version, - path: - tool === "marine" - ? await ensureMarinePath() - : await ensureMreplPath(), - }, - ] as const; - }, - ), - ), - ), + tools: { + marine: { + version: await getMarineOrMreplVersion("marine"), + path: await ensureMarinePath(), + }, + mrepl: { + version: await getMarineOrMreplVersion("mrepl"), + path: await ensureMreplPath(), + }, + }, "internal dependencies": filterOutNonFluenceDependencies( CLIPackageJSON.dependencies, ), diff --git a/cli/src/lib/marineCli.ts b/cli/src/lib/marineCli.ts index 10013531b..b722cf6fb 100644 --- a/cli/src/lib/marineCli.ts +++ b/cli/src/lib/marineCli.ts @@ -18,9 +18,9 @@ import { join } from "node:path"; import { commandObj } from "./commandObj.js"; -import { BIN_DIR_NAME, MARINE_CARGO_DEPENDENCY } from "./const.js"; +import { BIN_DIR_NAME } from "./const.js"; import { execPromise } from "./execPromise.js"; -import { ensureMarineOrMreplDependency } from "./rust.js"; +import { ensureMarineOrMreplDependency, ensureRust } from "./rust.js"; import { type Flags } from "./typeHelpers.js"; type MarineCliInput = @@ -44,19 +44,17 @@ export type MarineCLI = { }; export async function ensureMarinePath() { - const marineCLIDirPath = await ensureMarineOrMreplDependency({ - name: MARINE_CARGO_DEPENDENCY, - }); - + const marineCLIDirPath = await ensureMarineOrMreplDependency("marine"); return join(marineCLIDirPath, BIN_DIR_NAME, "marine"); } export async function ensureMreplPath() { - const mreplDirPath = await ensureMarineOrMreplDependency({ name: "mrepl" }); + const mreplDirPath = await ensureMarineOrMreplDependency("mrepl"); return join(mreplDirPath, BIN_DIR_NAME, "mrepl"); } export async function initMarineCli(): Promise { + await ensureRust(); const marineCLIPath = await ensureMarinePath(); return async ({ diff --git a/cli/src/lib/rust.ts b/cli/src/lib/rust.ts index e7ccb5c37..fdb08afcb 100644 --- a/cli/src/lib/rust.ts +++ b/cli/src/lib/rust.ts @@ -48,7 +48,7 @@ import { const CARGO = "cargo"; const RUSTUP = "rustup"; -async function ensureRust(): Promise { +export async function ensureRust(): Promise { if (!(await isRustInstalled())) { if (commandObj.config.windows) { commandObj.error( @@ -333,17 +333,11 @@ async function tryDownloadingBinary({ return true; } -type CargoDependencyArg = { - name: MarineOrMrepl; - version?: string | undefined; -}; - -export async function ensureMarineOrMreplDependency({ - name, -}: CargoDependencyArg): Promise { - await ensureRust(); +export async function ensureMarineOrMreplDependency( + name: MarineOrMrepl, +): Promise { const fluenceConfig = await initFluenceConfig(); - const version = fluenceConfig?.[`${name}Version`] ?? versions.cargo[name]; + const version = await getMarineOrMreplVersion(name); const { dependencyDirPath, dependencyTmpDirPath } = await resolveDependencyDirPathAndTmpPath({ name, version }); @@ -385,20 +379,16 @@ export async function ensureMarineOrMreplDependency({ } export async function ensureMarineAndMreplDependencies(): Promise { - for (const [name, version] of await resolveMarineAndMreplDependencies()) { - // Not installing dependencies in parallel - // for cargo logs to be clearly readable - await ensureMarineOrMreplDependency({ name, version }); - } + await ensureRust(); + await ensureMarineOrMreplDependency("marine"); + await ensureMarineOrMreplDependency("mrepl"); } -export async function resolveMarineAndMreplDependencies() { - const fluenceConfig = await initFluenceConfig(); - - return [ - ["marine", fluenceConfig?.marineVersion ?? versions.cargo.marine], - ["mrepl", fluenceConfig?.mreplVersion ?? versions.cargo.mrepl], - ] as const; +export async function getMarineOrMreplVersion(marineOrMrepl: MarineOrMrepl) { + return ( + (await initFluenceConfig())?.[`${marineOrMrepl}Version`] ?? + versions.cargo[marineOrMrepl] + ); } type ResolveDependencyDirPathAndTmpPath = {