From 99e6a86f9fafde90875e6e618ce9c2ea148a4ad6 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:00:14 +0100 Subject: [PATCH] refactor: rename and split rust build utils --- .../functions/build/build.rust.services.ts | 10 ++---- src/utils/build.bindgen.utils.ts | 36 +++++++++++++++++++ ...ild.rust.utils.ts => build.cargo.utils.ts} | 32 ----------------- 3 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 src/utils/build.bindgen.utils.ts rename src/utils/{build.rust.utils.ts => build.cargo.utils.ts} (70%) diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index b9b9612..6bd5f31 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -19,12 +19,8 @@ import { TARGET_PATH } from '../../../constants/dev.constants'; import type {BuildArgs, BuildType} from '../../../types/build'; -import { - checkBindgen, - checkCandidExtractor, - checkIcWasm, - checkWasi2ic -} from '../../../utils/build.rust.utils'; +import {checkIcpBindgen} from '../../../utils/build.bindgen.utils'; +import {checkCandidExtractor, checkIcWasm, checkWasi2ic} from '../../../utils/build.cargo.utils'; import {readSatelliteDid} from '../../../utils/did.utils'; import {checkRustVersion} from '../../../utils/env.utils'; import {formatTime} from '../../../utils/format.utils'; @@ -56,7 +52,7 @@ export const buildRust = async ({ return; } - const {valid: validBindgen} = await checkBindgen(); + const {valid: validBindgen} = await checkIcpBindgen(); if (!validBindgen) { return; diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts new file mode 100644 index 0000000..8e3d343 --- /dev/null +++ b/src/utils/build.bindgen.utils.ts @@ -0,0 +1,36 @@ +import {isNullish} from '@dfinity/utils'; +import {execute} from '@junobuild/cli-tools'; +import {magenta} from 'kleur'; +import {checkToolInstalled} from './env.utils'; +import {detectPackageManager} from './pm.utils'; +import {confirmAndExit} from './prompt.utils'; + +export const checkIcpBindgen = async (): Promise<{valid: boolean}> => { + const pm = detectPackageManager(); + + const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; + + const {valid} = await checkToolInstalled({ + command, + args: ['icp-bindgen', '--version', ...(command === 'npx' ? ['--no'] : [])] + }); + + if (valid === false) { + return {valid}; + } + + if (valid === 'error') { + await confirmAndExit( + `${magenta( + '@icp-sdk/bindgen' + )} is not available. This tool is required to generate API bindings. Would you like to install it now?` + ); + + await execute({ + command: pm ?? 'npm', + args: [pm === 'npm' ? 'i' : 'add', '@icp-sdk/bindgen', '-D'] + }); + } + + return {valid: true}; +}; diff --git a/src/utils/build.rust.utils.ts b/src/utils/build.cargo.utils.ts similarity index 70% rename from src/utils/build.rust.utils.ts rename to src/utils/build.cargo.utils.ts index 599b13d..b8148c7 100644 --- a/src/utils/build.rust.utils.ts +++ b/src/utils/build.cargo.utils.ts @@ -1,9 +1,7 @@ -import {isNullish} from '@dfinity/utils'; import {execute} from '@junobuild/cli-tools'; import {magenta, yellow} from 'kleur'; import {IC_WASM_MIN_VERSION} from '../constants/dev.constants'; import {checkIcWasmVersion, checkToolInstalled} from './env.utils'; -import {detectPackageManager} from './pm.utils'; import {confirmAndExit} from './prompt.utils'; export const checkIcWasm = async (): Promise<{valid: boolean}> => { @@ -55,36 +53,6 @@ export const checkCandidExtractor = async (): Promise<{valid: boolean}> => { return {valid: true}; }; -export const checkBindgen = async (): Promise<{valid: boolean}> => { - const pm = detectPackageManager(); - - const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; - - const {valid} = await checkToolInstalled({ - command, - args: ['icp-bindgen', '--version', ...(command === 'npx' ? ['--no'] : [])] - }); - - if (valid === false) { - return {valid}; - } - - if (valid === 'error') { - await confirmAndExit( - `${magenta( - '@icp-sdk/bindgen' - )} is not available. This tool is required to generate API bindings. Would you like to install it now?` - ); - - await execute({ - command: pm ?? 'npm', - args: [pm === 'npm' ? 'i' : 'add', '@icp-sdk/bindgen', '-D'] - }); - } - - return {valid: true}; -}; - export const checkWasi2ic = async (): Promise<{valid: boolean}> => { const {valid} = await checkToolInstalled({ command: 'wasi2ic',