import { logger } from "@atomist/automation-client" ; import { execPromise } from "@atomist/sdm" ; import { ConcreteIdeal } from "@atomist/sdm-pack-fingerprint" ; import { createNpmDepFingerprint , deconstructNpmDepsFingerprintName , } from "@atomist/sdm-pack-fingerprint/lib/fingerprints/npmDeps" ; export async function idealsFromNpm ( name ) { const ideal = await idealFromNpm ( name ) ; return ideal ? [ ideal ] : [ ] ; } export async function idealFromNpm ( name ) { const libraryName = deconstructNpmDepsFingerprintName ( name ) ; try { const result = await execPromise ( "npm" , [ "view" , libraryName , "dist-tags.latest" ] ) ; logger . info ( `World Ideal Version is ${ result . stdout } for ${ libraryName }` ) ; return { ideal : createNpmDepFingerprint ( libraryName , result . stdout . trim ( ) ) , reason : "latest from NPM" , } ; } catch ( err ) { logger . error ( "Could not find version of " + libraryName + ": " + err . message ) ; } return undefined ; }