1
1
import * as debugLib from 'debug' ;
2
+ import * as pathLib from 'path' ;
2
3
3
4
import {
4
5
EntityToFix ,
@@ -11,7 +12,7 @@ import { MissingRemediationDataError } from '../../../../lib/errors/missing-reme
11
12
import { MissingFileNameError } from '../../../../lib/errors/missing-file-name' ;
12
13
import { partitionByFixable } from './is-supported' ;
13
14
import { NoFixesCouldBeAppliedError } from '../../../../lib/errors/no-fixes-applied' ;
14
- import { parseRequirementsFile } from './update-dependencies/requirements-file-parser ' ;
15
+ import { extractProvenance } from './extract-version-provenance ' ;
15
16
16
17
const debug = debugLib ( 'snyk-fix:python:requirements.txt' ) ;
17
18
@@ -53,17 +54,19 @@ export async function fixIndividualRequirementsTxt(
53
54
if ( ! fileName ) {
54
55
throw new MissingFileNameError ( ) ;
55
56
}
56
- const requirementsTxt = await entity . workspace . readFile ( fileName ) ;
57
- const requirementsData = parseRequirementsFile ( requirementsTxt ) ;
58
-
57
+ const { dir, base } = pathLib . parse ( fileName ) ;
58
+ const versionProvenance = await extractProvenance (
59
+ entity . workspace ,
60
+ dir ,
61
+ base ,
62
+ ) ;
59
63
// TODO: allow handlers per fix type (later also strategies or combine with strategies)
60
64
const { updatedManifest, changes } = updateDependencies (
61
- requirementsData ,
65
+ versionProvenance [ base ] ,
62
66
remediationData . pin ,
63
67
) ;
64
68
65
- // TODO: do this with the changes now that we only return new
66
- if ( updatedManifest === requirementsTxt ) {
69
+ if ( ! changes . length ) {
67
70
debug ( 'Manifest has not changed!' ) ;
68
71
throw new NoFixesCouldBeAppliedError ( ) ;
69
72
}
0 commit comments