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

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 {
'pnpm ls -g ',
'pip3 list --disable-pip-version-check',
'pip3 show --disable-pip-version-check',
'apk info',
}

View File

@ -23,7 +23,7 @@ export default class DependenceService {
constructor(
@Inject('logger') private logger: winston.Logger,
private sockService: SockService,
) {}
) { }
public async create(payloads: Dependence[]): Promise<Dependence[]> {
const tabs = payloads.map((x) => {
@ -191,16 +191,27 @@ export default class DependenceService {
if (isInstall) {
const getCommandPrefix = GetDependenceCommandTypes[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 = (
await promiseExecSuccess(
dependency.type === DependenceTypes.linux
? `${getCommandPrefix} ${_depName}`
: `${getCommandPrefix} | grep "${_depName}"`,
isNodeDependence
? `${getCommandPrefix} | grep "${_depName}" | head -1`
: `${getCommandPrefix} ${_depName}`,
)
).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 _message = `检测到已经安装 ${_depName}\n\n${depInfo}\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format(
'YYYY-MM-DD HH:mm:ss',