import execa from 'execa' ; import { detectPackageManager } from '.' ; export interface InstallPackageOptions { cwd ? : string ; dev ? : boolean ; silent ? : boolean ; packageManager ? : string ; preferOffline ? : boolean ; additionalArgs ? : string [ ] ; } export async function installPackage ( names , options = { } ) { const agent = options . packageManager || await detectPackageManager ( options . cwd ) || 'npm' ; if ( ! Array . isArray ( names ) ) names = [ names ] ; const args = options . additionalArgs || [ ] ; if ( options . preferOffline ) args . unshift ( '--prefer-offline' ) ; return execa ( agent , [ agent === 'yarn' ? 'add' : 'install' , options . dev ? '-D' : '' , ... args , ... names , ] . filter ( Boolean ) , { stdio : options . silent ? 'ignore' : 'inherit' , cwd : options . cwd , } ) ; }