Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/services/functions/build/build.did.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/build.bindgen.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const checkIcpBindgen = async ({
return {valid: true};
};

const checkLocalIcpBindgen = async ({
export const checkLocalIcpBindgen = async ({
pm
}: {
pm: PackageManager | undefined;
Expand Down