import * as fs from "fs" ; import * as ini from "ini" ; import * as tl from "azure-pipelines-task-lib/task" ; export function GetRegistries ( npmrc , saveNormalizedRegistries ) { let registries = [ ] ; let config = ini . parse ( fs . readFileSync ( npmrc ) . toString ( ) ) ; for ( let key in config ) { let colonIndex = key . indexOf ( ":" ) ; if ( key . substring ( colonIndex + 1 ) . toLowerCase ( ) === "registry" ) { config [ key ] = NormalizeRegistry ( config [ key ] ) ; registries . push ( config [ key ] ) ; } } if ( saveNormalizedRegistries ) { tl . writeFile ( npmrc , ini . stringify ( config ) ) ; } return registries ; } export function NormalizeRegistry ( registry ) { if ( registry && ! registry . endsWith ( "/" ) ) { registry += "/" ; } return registry ; }