import { promises } from "fs" ; import { join } from "path" ; const { writeFile , access } = promises ; export type PackageManagerType = "yarn" | "npm" ; export interface InstallOptions { force ? : boolean ; } export interface PackageManagerProgress { /**
     * Current step.
     */ current : number ; /**
     * Total number of steps.
     */ total : number ; /**
     * In the case there is multiple progress
     */ id ? : number ; } export type PackageInstallationResult = { success : false ; error : InstallationError ; } | { success : true ; } ; export interface InstallationError { /**
     * Main error message.
     */ message : string ; /**
     * Log entries for the package manager.
     */ logs : PackageManagerLogEntry [ ] ; } export interface PackageManagerLogEntry { severity : "info" | "warning" | "error" ; message : string ; } export interface PackageManager { install ( directory , packages , options ? , reportProgress ? ) : Promise < PackageInstallationResult > ; clean ( directory ) : Promise < void > ; getPackageVersions ( directory , packageName ) : Promise < any [ ] > ; } param directory export async function ensurePackageJsonExists ( directory ) { const filename = join ( directory , "package.json" ) ; if ( await exists ( filename ) ) { return ; } await writeFile ( filename , "{}" ) ; } async function exists ( filename ) { try { await access ( filename ) ; return true ; } catch { return false ; } }