diff --git a/src/services/functions/build/build.did.services.ts b/src/services/functions/build/build.did.services.ts index 0cd5582..f06924c 100644 --- a/src/services/functions/build/build.did.services.ts +++ b/src/services/functions/build/build.did.services.ts @@ -10,6 +10,7 @@ import { SATELLITE_CUSTOM_DID_FILE } from '../../../constants/build.constants'; import {DEVELOPER_PROJECT_SATELLITE_DECLARATIONS_PATH} from '../../../constants/dev.constants'; +import {checkLocalIcpBindgen} from '../../../utils/build.bindgen.utils'; import {readPackageJson} from '../../../utils/pkg.utils'; import {detectPackageManager} from '../../../utils/pm.utils'; @@ -46,15 +47,21 @@ export const generateDid = async () => { const executeIcpBindgen = async () => { const pm = detectPackageManager(); - const command = pm === 'npm' || isNullish(pm) ? 'npx' : pm; + // The assertion on checkIcpBindgen() which requires the installation of icp-bindgen + // is performed earlier to reaching this point. Therefore, we can optimistically + // assume that if no tool is available locally, it should be available globally. + const {valid: localValid} = await checkLocalIcpBindgen({pm}); + const withGlobalCmd = localValid !== true; + + const localCommand = pm === 'npm' || isNullish(pm) ? 'npx' : pm; // --actor-disabled: skip generating actor files, since we handle those ourselves // --force: overwrite files. Required; otherwise, icp-bindgen would delete files at preprocess, // which causes issues when multiple .did files are located in the same folder. await spawn({ - command, + command: withGlobalCmd ? 'icp-bindgen' : localCommand, args: [ - 'icp-bindgen', + ...(withGlobalCmd ? [] : ['icp-bindgen']), '--did-file', SATELLITE_CUSTOM_DID_FILE, '--out-dir', diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts index f95cd48..1c07b06 100644 --- a/src/utils/build.bindgen.utils.ts +++ b/src/utils/build.bindgen.utils.ts @@ -51,7 +51,7 @@ export const checkIcpBindgen = async ({ return {valid: true}; }; -const checkLocalIcpBindgen = async ({ +export const checkLocalIcpBindgen = async ({ pm }: { pm: PackageManager | undefined;