import type { CustomExtractConfig , PackageDependency , PackageFile , Result , } from '../types' ; import { handleAny , handleCombination , handleRecursive } from './strategies' ; import { validMatchFields } from './utils' ; export const defaultConfig = { pinDigests : false , } ; export function extractPackageFile ( content , packageFile , config ) { let deps ; switch ( config . matchStringsStrategy ) { default : case 'any' : deps = handleAny ( content , packageFile , config ) ; break ; case 'combination' : deps = handleCombination ( content , packageFile , config ) ; break ; case 'recursive' : deps = handleRecursive ( content , packageFile , config ) ; break ; } deps = deps . filter ( Boolean ) ; if ( deps . length ) { const res = { deps , matchStrings : config . matchStrings } ; if ( config . matchStringsStrategy ) { res . matchStringsStrategy = config . matchStringsStrategy ; } for ( const field of validMatchFields . map ( ( f ) => `${ f }Template` ) ) { if ( config [ field ] ) { res [ field ] = config [ field ] ; } } if ( config . autoReplaceStringTemplate ) { res . autoReplaceStringTemplate = config . autoReplaceStringTemplate ; } return res ; } return null ; }