license import exec , { ExecResult } from './util/exec' ; import fs = require ( 'fs' ) ; import path = require ( 'path' ) ; import _util = require ( 'util' ) ; const { promisify } = _util ; export class NpmPackage { dir : string ; constructor ( dir ) { this . dir = dir ; } /**
     * Return the current user logged in to npm.
     */ async whoami ( ) { return ( await exec ( this . dir , 'npm' , [ 'whoami' ] ) ) . stdout ; } /**
     * Return the current package manifest. Throws if there are any issues
     * reading/parsing the file contents.
     */ async getPackageManifest ( ) { const packageManifestLoc = path . join ( this . dir , 'package.json' ) ; const packageManifest = await promisify ( fs . readFile ) ( packageManifestLoc , 'utf-8' ) ; return JSON . parse ( packageManifest ) ; } /**
     * Run `npm publish` in the package directory. A tag name is required
     * (use "latest" to mimic the npm default).
     */ async publishToNpm ( tagName ) { return exec ( this . dir , 'npm' , [ 'publish' , '--tag' , tagName ] ) ; } }