修复 node 依赖匹配判断

This commit is contained in:
whyour 2023-07-21 21:22:48 +08:00
parent 6131fe0110
commit 04edd97967
2 changed files with 16 additions and 10 deletions

View File

@ -13,7 +13,7 @@ const client = new HealthClient(
app.get('/api/health', (req, res) => {
client.check({ service: 'cron' }, (err, response) => {
if (err) {
return res.status(500).send({ code: 500, error: err });
return res.status(200).send({ code: 500, error: err });
}
return res.status(200).send({ code: 200, data: response });
});

View File

@ -168,7 +168,7 @@ export default class DependenceService {
const socketMessageType = isInstall
? 'installDependence'
: 'uninstallDependence';
const depName = dependency.name.trim();
let depName = dependency.name.trim();
const depRunCommand = (
isInstall
? InstallDependenceCommandTypes
@ -191,29 +191,35 @@ export default class DependenceService {
if (isInstall) {
const getCommandPrefix = GetDependenceCommandTypes[dependency.type];
const depVersionStr = versionDependenceCommandTypes[dependency.type];
const [_depName, _depVersion] = dependency.name
.trim()
.split(depVersionStr);
let depVersion = '';
if (depName.includes(depVersionStr)) {
const symbolRegx = new RegExp(`(.*)${depVersionStr}([0-9\\.\\-\\+a-zA-Z]*)`);
const [, _depName, _depVersion] = depName.match(symbolRegx) || [];
if (_depVersion && _depName) {
depName = _depName;
depVersion = _depVersion;
}
}
const isNodeDependence = dependency.type === DependenceTypes.nodejs;
const isLinuxDependence = dependency.type === DependenceTypes.linux;
const isPythonDependence = dependency.type === DependenceTypes.python3;
const depInfo = (
await promiseExecSuccess(
isNodeDependence
? `${getCommandPrefix} | grep "${_depName}" | head -1`
: `${getCommandPrefix} ${_depName}`,
? `${getCommandPrefix} | grep "${depName}" | head -1`
: `${getCommandPrefix} ${depName}`,
)
).replace(/\s{2,}/, ' ');
if (
depInfo &&
((isNodeDependence && depInfo.split(' ')?.[0] === _depName) ||
((isNodeDependence && depInfo.split(' ')?.[0] === depName) ||
(isLinuxDependence && depInfo.toLocaleLowerCase().includes('installed')) ||
isPythonDependence) &&
(!_depVersion || depInfo.includes(_depVersion))
(!depVersion || depInfo.includes(depVersion))
) {
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',
)} ${endTime.diff(startTime, 'second')} `;
this.sockService.sendMessage({