From 0a79b2d0c0bbc9571662b75e337f7107a4a055dc Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:09:48 +0100 Subject: [PATCH 1/3] feat: check icp-bindgen with globall fallback --- src/utils/build.bindgen.utils.ts | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts index 8e3d343..2a97913 100644 --- a/src/utils/build.bindgen.utils.ts +++ b/src/utils/build.bindgen.utils.ts @@ -5,15 +5,19 @@ 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(); +export const checkIcpBindgen = async ({ + globalFallback +}: { + globalFallback: boolean; +}): Promise<{valid: boolean}> => { + const {valid: localValid} = await checkLocalIcpBindgen(); - const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; + if (localValid === true) { + return {valid: true}; + } - const {valid} = await checkToolInstalled({ - command, - args: ['icp-bindgen', '--version', ...(command === 'npx' ? ['--no'] : [])] - }); + if (globalFallback) { + } if (valid === false) { return {valid}; @@ -34,3 +38,21 @@ export const checkIcpBindgen = async (): Promise<{valid: boolean}> => { return {valid: true}; }; + +const checkLocalIcpBindgen = async (): Promise<{valid: boolean | 'error'}> => { + const pm = detectPackageManager(); + + const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; + + return await checkToolInstalled({ + command, + args: ['icp-bindgen', '--version', ...(command === 'npx' ? ['--no'] : [])] + }); +}; + +const checkGlobalIcpBindgen = async (): Promise<{valid: boolean | 'error'}> => { + return await checkToolInstalled({ + command: 'icp-bindgen', + args: ['--version'] + }); +}; From 66d9a6e20c11c4403af260b2c4e3b6372cc16e56 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:33:03 +0100 Subject: [PATCH 2/3] feat: fallback to global bindgen --- .../functions/build/build.rust.services.ts | 3 +- src/utils/build.bindgen.utils.ts | 56 ++++++++++++------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/services/functions/build/build.rust.services.ts b/src/services/functions/build/build.rust.services.ts index 6bd5f31..8defbbf 100644 --- a/src/services/functions/build/build.rust.services.ts +++ b/src/services/functions/build/build.rust.services.ts @@ -26,6 +26,7 @@ import {checkRustVersion} from '../../../utils/env.utils'; import {formatTime} from '../../../utils/format.utils'; import {readPackageJson} from '../../../utils/pkg.utils'; import {detectPackageManager} from '../../../utils/pm.utils'; +import {isHeadless} from '../../../utils/process.utils'; import {readEmulatorConfigAndCreateDeployTargetDir} from '../../emulator/_fs.services'; import {prepareJunoPkgForSatellite, prepareJunoPkgForSputnik} from './build.metadata.services'; import {dispatchEmulatorTouchSatellite} from './touch.services'; @@ -52,7 +53,7 @@ export const buildRust = async ({ return; } - const {valid: validBindgen} = await checkIcpBindgen(); + const {valid: validBindgen} = await checkIcpBindgen({withGlobalFallback: isHeadless()}); if (!validBindgen) { return; diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts index 2a97913..2771015 100644 --- a/src/utils/build.bindgen.utils.ts +++ b/src/utils/build.bindgen.utils.ts @@ -1,47 +1,61 @@ import {isNullish} from '@dfinity/utils'; import {execute} from '@junobuild/cli-tools'; import {magenta} from 'kleur'; +import {PackageManager} from '../types/pm'; import {checkToolInstalled} from './env.utils'; import {detectPackageManager} from './pm.utils'; import {confirmAndExit} from './prompt.utils'; export const checkIcpBindgen = async ({ - globalFallback + withGlobalFallback }: { - globalFallback: boolean; + withGlobalFallback: boolean; }): Promise<{valid: boolean}> => { - const {valid: localValid} = await checkLocalIcpBindgen(); + const pm = detectPackageManager(); + + const {valid: localValid} = await checkLocalIcpBindgen({pm}); if (localValid === true) { return {valid: true}; } - if (globalFallback) { - } + if (withGlobalFallback) { + const {valid: globalValid} = await checkGlobalIcpBindgen(); - if (valid === false) { - return {valid}; + if (globalValid === true) { + return {valid: true}; + } + + // Useful the day we require a specific version of the tool. + if (globalValid === false) { + return {valid: globalValid}; + } } - 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'] - }); + // Useful the day we require a specific version of the tool. + if (localValid === false) { + return {valid: localValid}; } + 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}; }; -const checkLocalIcpBindgen = async (): Promise<{valid: boolean | 'error'}> => { - const pm = detectPackageManager(); - +const checkLocalIcpBindgen = async ({ + pm +}: { + pm: PackageManager | undefined; +}): Promise<{valid: boolean | 'error'}> => { const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; return await checkToolInstalled({ From b383102d9f8be8290fde0ab73c77a63200cb9c0b Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:34:36 +0100 Subject: [PATCH 3/3] chore: lint --- src/utils/build.bindgen.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts index 2771015..f95cd48 100644 --- a/src/utils/build.bindgen.utils.ts +++ b/src/utils/build.bindgen.utils.ts @@ -1,7 +1,7 @@ import {isNullish} from '@dfinity/utils'; import {execute} from '@junobuild/cli-tools'; import {magenta} from 'kleur'; -import {PackageManager} from '../types/pm'; +import {type PackageManager} from '../types/pm'; import {checkToolInstalled} from './env.utils'; import {detectPackageManager} from './pm.utils'; import {confirmAndExit} from './prompt.utils';