Skip to content

Commit 48bc0f3

Browse files
author
xwj02155382
committed
perf: add cache for commandExists to fix CI timeout
- Add commandExistsCache Map to avoid repeated execSync calls - Cache command existence check results to improve test performance - Fix CI test timeout issue (was timing out after 7m) The commandExists() function was being called frequently during tests, causing slow test execution due to repeated system command calls. By caching the results, we significantly improve performance in test environments while maintaining the same functionality.
1 parent e30c2db commit 48bc0f3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/cli/src/ui/hooks/useLaunchEditor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,29 @@ const editorCommands: Record<
2929
trae: { win32: ['trae'], default: ['trae'] },
3030
};
3131

32+
/**
33+
* Cache for command existence checks to avoid repeated execSync calls.
34+
*/
35+
const commandExistsCache = new Map<string, boolean>();
36+
3237
/**
3338
* Check if a command exists in the system.
39+
* Results are cached to improve performance in test environments.
3440
*/
3541
function commandExists(cmd: string): boolean {
42+
if (commandExistsCache.has(cmd)) {
43+
return commandExistsCache.get(cmd)!;
44+
}
45+
3646
try {
3747
execSync(
3848
process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`,
3949
{ stdio: 'ignore' },
4050
);
51+
commandExistsCache.set(cmd, true);
4152
return true;
4253
} catch {
54+
commandExistsCache.set(cmd, false);
4355
return false;
4456
}
4557
}

0 commit comments

Comments
 (0)