X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Fplugins%2Fyarn.ts;h=3f45681d3f90ca839d575616681a4680b164ca23;hb=39d117a47d313637cf3ded4c6fa915aa9fd469ee;hp=5fe1c50463d0f30aafd9d567f7a186a9896a6a1b;hpb=ad91e7006e41f8ee5b8dcefee30f99e8ca44133a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/plugins/yarn.ts b/server/lib/plugins/yarn.ts index 5fe1c5046..3f45681d3 100644 --- a/server/lib/plugins/yarn.ts +++ b/server/lib/plugins/yarn.ts @@ -1,19 +1,24 @@ +import { outputJSON, pathExists } from 'fs-extra' +import { join } from 'path' import { execShell } from '../../helpers/core-utils' -import { logger } from '../../helpers/logger' import { isNpmPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' +import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' -import { outputJSON, pathExists } from 'fs-extra' -import { join } from 'path' +import { getLatestPluginVersion } from './plugin-index' -async function installNpmPlugin (name: string, version?: string) { +async function installNpmPlugin (npmName: string, versionArg?: string) { // Security check - checkNpmPluginNameOrThrow(name) - if (version) checkPluginVersionOrThrow(version) + checkNpmPluginNameOrThrow(npmName) + if (versionArg) checkPluginVersionOrThrow(versionArg) - let toInstall = name + const version = versionArg || await getLatestPluginVersion(npmName) + + let toInstall = npmName if (version) toInstall += `@${version}` - await execYarn('add ' + toInstall) + const { stdout } = await execYarn('add ' + toInstall) + + logger.debug('Added a yarn package.', { yarnStdout: stdout }) } async function installNpmPluginFromDisk (path: string) { @@ -46,7 +51,7 @@ async function execYarn (command: string) { await outputJSON(pluginPackageJSON, {}) } - await execShell(`yarn ${command}`, { cwd: pluginDirectory }) + return execShell(`yarn ${command}`, { cwd: pluginDirectory }) } catch (result) { logger.error('Cannot exec yarn.', { command, err: result.err, stderr: result.stderr })