import execa from 'execa' import semver from 'semver' import chalk from 'chalk' import log from './log' import { execBin } from './bin' export async function getPackageVersion(pkg: string): Promise { try { const { stdout } = await execa('tnpm', ['info', pkg, 'version']) const version = semver.valid(stdout.trim()) return version || '' } catch (err) { log.error('bin', chalk.red(err)) } return '' } export async function installPkgs({ cwd, pkgs, dev, save, global, exitWhenErr, }: { cwd: string pkgs?: string[] dev?: boolean save?: boolean global?: boolean exitWhenErr?: boolean }): Promise { const args = ['i'] if (pkgs && pkgs.length > 0) { if (global) { args.push('-g') } else if (save) { args.push(dev ? '-D' : '-S') } else { args.push('--no-save') } args.push(...pkgs) } await execBin({ global: true, binPath: 'tnpm', args, cwd, exitWhenErr, }) }