Optimize getCommandsInPath, restore cache

Changes:

- Fix cache mechanism as pathValue never got stored
- Cache labels instead of returning empty set
- Walking each directory in separate promise and await via Promise.all
- Don't create a promise on Windows when checking exe

Fixes #239396
This commit is contained in:
Daniel Imms
2025-02-01 05:17:57 -08:00
parent d487556d4d
commit fafd6b594a
2 changed files with 47 additions and 20 deletions

View File

@@ -6,11 +6,15 @@
import { osIsWindows } from './os';
import * as fs from 'fs/promises';
export async function isExecutable(filePath: string, configuredWindowsExecutableExtensions?: { [key: string]: boolean | undefined } | undefined): Promise<boolean> {
export function isExecutable(filePath: string, configuredWindowsExecutableExtensions?: { [key: string]: boolean | undefined } | undefined): Promise<boolean> | boolean {
if (osIsWindows()) {
const resolvedWindowsExecutableExtensions = resolveWindowsExecutableExtensions(configuredWindowsExecutableExtensions);
return resolvedWindowsExecutableExtensions.find(ext => filePath.endsWith(ext)) !== undefined;
}
return isExecutableUnix(filePath);
}
export async function isExecutableUnix(filePath: string): Promise<boolean> {
try {
const stats = await fs.stat(filePath);
// On macOS/Linux, check if the executable bit is set