import { ProgrammingLanguage } from '../constants' ; import type { RangeStrategy } from '../types' ; import managers from './api' ; import type { ExtractConfig , GlobalManagerConfig , ManagerApi , PackageFile , RangeConfig , Result , } from './types' ; const managerList = Array . from ( managers . keys ( ) ) ; const languageList = Object . values ( ProgrammingLanguage ) ; export function get < T extends keyof ManagerApi > ( manager , name ) { return managers . get ( manager ) ?. [ name ] ; } export const getLanguageList = ( ) : string [ ] => languageList ; export const getManagerList = ( ) : string [ ] => managerList ; export const getManagers = ( ) : Map < string , ManagerApi > => managers ; export async function detectAllGlobalConfig ( ) { let config = { } ; for ( const managerName of managerList ) { const manager = managers . get ( managerName ) ; if ( manager . detectGlobalConfig ) { config = { ... config , ... ( await manager . detectGlobalConfig ( ) ) } ; } } return config ; } export async function extractAllPackageFiles ( manager , config , files ) { if ( ! managers . has ( manager ) ) { return null ; } const m = managers . get ( manager ) ; if ( m . extractAllPackageFiles ) { const res = await m . extractAllPackageFiles ( config , files ) ; if ( ! res ) { return null ; } return res ; } return null ; } export function extractPackageFile ( manager , content , fileName ? , config ? ) { if ( ! managers . has ( manager ) ) { return null ; } const m = managers . get ( manager ) ; return m . extractPackageFile ? m . extractPackageFile ( content , fileName , config ) : null ; } export function getRangeStrategy ( config ) { const { manager , rangeStrategy } = config ; if ( ! managers . has ( manager ) ) { return null ; } const m = managers . get ( manager ) ; if ( m . getRangeStrategy ) { return m . getRangeStrategy ( config ) ; } if ( rangeStrategy === 'auto' ) { return 'replace' ; } return config . rangeStrategy ; }