mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 20:13:32 +01:00
add suggest setting WindowsExecutableExtensions, default values (#238155)
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
import { osIsWindows } from './os';
|
||||
import * as fs from 'fs/promises';
|
||||
|
||||
export async function isExecutable(filePath: string): Promise<boolean> {
|
||||
export async function isExecutable(filePath: string, configuredWindowsExecutableExtensions?: Object): Promise<boolean> {
|
||||
if (osIsWindows()) {
|
||||
return windowsExecutableExtensions.find(ext => filePath.endsWith(ext)) !== undefined;
|
||||
const resolvedWindowsExecutableExtensions = resolveWindowsExecutableExtensions(configuredWindowsExecutableExtensions);
|
||||
return resolvedWindowsExecutableExtensions.find(ext => filePath.endsWith(ext)) !== undefined;
|
||||
}
|
||||
try {
|
||||
const stats = await fs.stat(filePath);
|
||||
@@ -19,7 +20,23 @@ export async function isExecutable(filePath: string): Promise<boolean> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const windowsExecutableExtensions: string[] = [
|
||||
|
||||
function resolveWindowsExecutableExtensions(configuredWindowsExecutableExtensions?: Object): string[] {
|
||||
const resolvedWindowsExecutableExtensions: string[] = windowsDefaultExecutableExtensions;
|
||||
const excluded = new Set<string>();
|
||||
if (configuredWindowsExecutableExtensions) {
|
||||
for (const [key, value] of Object.entries(configuredWindowsExecutableExtensions)) {
|
||||
if (value === true) {
|
||||
resolvedWindowsExecutableExtensions.push(key);
|
||||
} else {
|
||||
excluded.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(new Set(resolvedWindowsExecutableExtensions)).filter(ext => !excluded.has(ext));
|
||||
}
|
||||
|
||||
export const windowsDefaultExecutableExtensions: string[] = [
|
||||
'.exe', // Executable file
|
||||
'.bat', // Batch file
|
||||
'.cmd', // Command script
|
||||
|
||||
Reference in New Issue
Block a user