From 723a9c54aab5fbbb9307feeeaf146138a7faa264 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:52:53 +0100 Subject: [PATCH 1/2] feat: fallback on global icp-sdk/bindgen for generating did files Signed-off-by: David Dal Busco --- .../functions/build/build.did.services.ts | 37 ++++++++++++------- src/utils/build.bindgen.utils.ts | 2 +- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/services/functions/build/build.did.services.ts b/src/services/functions/build/build.did.services.ts index 3882b9f9..f06924c7 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'; @@ -30,17 +31,37 @@ export const generateDid = async () => { return; } + await executeIcpBindgen(); + + // icp-bindgen generates the files in a `declarations` subfolder + // using a different suffix for JavaScript as the one we used to use. + // That's why we have to post-process the results. + const generatedFolder = join(DEVELOPER_PROJECT_SATELLITE_DECLARATIONS_PATH, 'declarations'); + + await rename(join(generatedFolder, `${EXTENSION_DID_FILE_NAME}.d.ts`), satellitedIdl('ts')); + await rename(join(generatedFolder, `${EXTENSION_DID_FILE_NAME}.js`), satellitedIdl('js')); + + await rm(generatedFolder, {recursive: true, force: true}); +}; + +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', @@ -50,16 +71,6 @@ export const generateDid = async () => { ], silentOut: true }); - - // icp-bindgen generates the files in a `declarations` subfolder - // using a different suffix for JavaScript as the one we used to use. - // That's why we have to post-process the results. - const generatedFolder = join(DEVELOPER_PROJECT_SATELLITE_DECLARATIONS_PATH, 'declarations'); - - await rename(join(generatedFolder, `${EXTENSION_DID_FILE_NAME}.d.ts`), satellitedIdl('ts')); - await rename(join(generatedFolder, `${EXTENSION_DID_FILE_NAME}.js`), satellitedIdl('js')); - - await rm(generatedFolder, {recursive: true, force: true}); }; export const generateApi = async () => { diff --git a/src/utils/build.bindgen.utils.ts b/src/utils/build.bindgen.utils.ts index f95cd48d..1c07b06b 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; From a7ed368f5a14d67845dcbfc9d73ad26918e887b3 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 25 Nov 2025 09:58:39 +0100 Subject: [PATCH 2/2] chore: merge main Signed-off-by: David Dal Busco --- src/services/functions/build/build.did.services.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/functions/build/build.did.services.ts b/src/services/functions/build/build.did.services.ts index 9beac94c..f06924c7 100644 --- a/src/services/functions/build/build.did.services.ts +++ b/src/services/functions/build/build.did.services.ts @@ -33,7 +33,6 @@ export const generateDid = async () => { await executeIcpBindgen(); - // icp-bindgen generates the files in a `declarations` subfolder // using a different suffix for JavaScript as the one we used to use. // That's why we have to post-process the results.