修复依赖是否已经安装判断

This commit is contained in:
whyour 2023-07-20 22:54:11 +08:00
parent 373b8c97d7
commit 665c344ae4
2 changed files with 18 additions and 7 deletions

View File

@ -48,7 +48,7 @@ export enum InstallDependenceCommandTypes {
export enum GetDependenceCommandTypes { export enum GetDependenceCommandTypes {
'pnpm ls -g ', 'pnpm ls -g ',
'pip3 list --disable-pip-version-check', 'pip3 show --disable-pip-version-check',
'apk info', 'apk info',
} }

View File

@ -191,16 +191,27 @@ export default class DependenceService {
if (isInstall) { if (isInstall) {
const getCommandPrefix = GetDependenceCommandTypes[dependency.type]; const getCommandPrefix = GetDependenceCommandTypes[dependency.type];
const depVersionStr = versionDependenceCommandTypes[dependency.type]; const depVersionStr = versionDependenceCommandTypes[dependency.type];
const [_depName] = dependency.name.trim().split(depVersionStr); const [_depName, _depVersion] = dependency.name
.trim()
.split(depVersionStr);
const isNodeDependence = dependency.type === DependenceTypes.nodejs;
const isLinuxDependence = dependency.type === DependenceTypes.linux;
const isPythonDependence = dependency.type === DependenceTypes.python3;
const depInfo = ( const depInfo = (
await promiseExecSuccess( await promiseExecSuccess(
dependency.type === DependenceTypes.linux isNodeDependence
? `${getCommandPrefix} ${_depName}` ? `${getCommandPrefix} | grep "${_depName}" | head -1`
: `${getCommandPrefix} | grep "${_depName}"`, : `${getCommandPrefix} ${_depName}`,
) )
).replace(/\s{2,}/, ' '); ).replace(/\s{2,}/, ' ');
if (depInfo) { if (
depInfo &&
((isNodeDependence && depInfo.split(' ')?.[0] === _depName) ||
(isLinuxDependence && depInfo.toLocaleLowerCase().includes('installed')) ||
isPythonDependence) &&
(!_depVersion || depInfo.includes(_depVersion))
) {
const endTime = dayjs(); const endTime = dayjs();
const _message = `检测到已经安装 ${_depName}\n\n${depInfo}\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format( const _message = `检测到已经安装 ${_depName}\n\n${depInfo}\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format(
'YYYY-MM-DD HH:mm:ss', 'YYYY-MM-DD HH:mm:ss',