import * as debugLib from 'debug' ; import { DependencyPins , FixChangesSummary } from '../../../../../types' ; import { generatePins } from './generate-pins' ; import { applyUpgrades } from './apply-upgrades' ; import { ParsedRequirements } from './requirements-file-parser' ; import { generateUpgrades } from './generate-upgrades' ; import { FailedToParseManifest } from '../../../../../lib/errors/failed-to-parse-manifest' ; const debug = debugLib ( 'snyk-fix:python:update-dependencies' ) ; export function updateDependencies ( parsedRequirementsData , updates , directUpgradesOnly = false , referenceFileInChanges ? ) { const { requirements , endsWithNewLine : shouldEndWithNewLine , } = parsedRequirementsData ; if ( ! requirements . length ) { debug ( 'Error: Expected to receive parsed manifest data. Is manifest empty?' ) ; throw new FailedToParseManifest ( ) ; } debug ( 'Finished parsing manifest' ) ; const { updatedRequirements , changes : upgradedChanges } = generateUpgrades ( requirements , updates , referenceFileInChanges ) ; debug ( 'Finished generating upgrades to apply' ) ; let pinnedRequirements = [ ] ; let pinChanges = [ ] ; if ( ! directUpgradesOnly ) { ( { pinnedRequirements , changes : pinChanges } = generatePins ( requirements , updates , referenceFileInChanges ) ) ; debug ( 'Finished generating pins to apply' ) ; } let updatedManifest = [ ... applyUpgrades ( requirements , updatedRequirements ) , ... pinnedRequirements , ] . join ( '\n' ) ; if ( shouldEndWithNewLine ) { updatedManifest += '\n' ; } debug ( 'Finished applying changes to manifest' ) ; return { updatedManifest , changes : [ ... pinChanges , ... upgradedChanges ] , } ; }