license import * as fs from 'fs' ; /**
 * Represents a valid node module that has been successfully resolved.
 */ export interface NodeModule { name : string ; resolvedPath : string ; version : Version ; } export function resolve ( packageName , location , rootPackage ? ) { rootPackage = rootPackage || packageName ; try { const packageJsonPath = require . resolve ( `${ rootPackage }/package.json` , { paths : [ location ] , } ) ; const packageJson = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) ; const resolvedPath = require . resolve ( packageName , { paths : [ location ] , } ) ; return { name : packageName , resolvedPath , version : new Version ( packageJson . version ) , } ; } catch { } } export class Version { readonly major : number ; readonly minor : number ; readonly patch : number ; constructor ( private readonly versionStr ) { const [ major , minor , patch ] = Version . parseVersionStr ( versionStr ) ; this . major = major ; this . minor = minor ; this . patch = patch ; } greaterThanOrEqual ( other ) { if ( this . major < other . major ) { return false ; } if ( this . major > other . major ) { return true ; } if ( this . minor < other . minor ) { return false ; } if ( this . minor > other . minor ) { return true ; } return this . patch >= other . patch ; } toString ( ) { return this . versionStr ; } param versionStr static parseVersionStr ( versionStr ) { const [ major , minor , patch ] = versionStr . split ( '.' ) . map ( parseNonNegativeInt ) ; return [ major === undefined ? 0 : major , minor === undefined ? 0 : minor , patch === undefined ? 0 : patch , ] ; } } param a function parseNonNegativeInt ( a ) { const i = parseInt ( a , 10 ) ; return isNaN ( i ) ? - 1 : i ; }