修复依赖是否安装检查逻辑

This commit is contained in:
whyour 2025-05-23 23:45:43 +08:00
parent 1c18668bad
commit 224000b63b

View File

@ -517,15 +517,22 @@ export async function setSystemTimezone(timezone: string): Promise<boolean> {
export function getGetCommand(type: DependenceTypes, name: string): string { export function getGetCommand(type: DependenceTypes, name: string): string {
const baseCommands = { const baseCommands = {
[DependenceTypes.nodejs]: `pnpm ls -g | grep "${name}" | head -1`, [DependenceTypes.nodejs]: `pnpm ls -g | grep "${name}" | head -1`,
[DependenceTypes.python3]: `python3 -c "import importlib;pkg=importlib.import_module('${name}');print(getattr(pkg, '__version__', 'inner package'))"`, [DependenceTypes.python3]: `
python3 -c "exec('''
name='${name}'
try:
from importlib.metadata import version
print(version(name))
except:
import importlib.util as u
import importlib.metadata as m
spec=u.find_spec(name)
print(name if spec else '')
''')"`,
[DependenceTypes.linux]: `apk info -es ${name}`, [DependenceTypes.linux]: `apk info -es ${name}`,
}; };
let command = baseCommands[type]; return baseCommands[type];
return type === DependenceTypes.python3
? command
: `${command} ${name.trim()}`;
} }
export function getInstallCommand(type: DependenceTypes, name: string): string { export function getInstallCommand(type: DependenceTypes, name: string): string {