"Fossies" - the Fresh Open Source Software Archive 
Member "cli-1.1259.0/packages/snyk-fix/src/plugins/python/handlers/pip-requirements/update-dependencies/calculate-relevant-fixes.ts" (30 Nov 2023, 1072 Bytes) of package /linux/misc/snyk-cli-1.1259.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 import { DependencyPins } from '../../../../../types';
2 import { isDefined } from './is-defined';
3 import { Requirement } from './requirements-file-parser';
4 import { standardizePackageName } from '../../../standardize-package-name';
5
6 export type FixesType = 'direct-upgrades' | 'transitive-pins';
7
8 export function calculateRelevantFixes(
9 requirements: Requirement[],
10 updates: DependencyPins,
11 type: FixesType,
12 ): DependencyPins {
13 const lowerCasedUpdates = {};
14 const topLevelDeps = requirements.map(({ name }) => name).filter(isDefined);
15
16 Object.keys(updates).forEach((update) => {
17 const { upgradeTo } = updates[update];
18 const [pkgName] = update.split('@');
19 const isTransitive =
20 topLevelDeps.indexOf(standardizePackageName(pkgName)) < 0;
21 if (type === 'transitive-pins' ? isTransitive : !isTransitive) {
22 const [name, newVersion] = upgradeTo.split('@');
23
24 lowerCasedUpdates[update] = {
25 ...updates[update],
26 upgradeTo: `${standardizePackageName(name)}@${newVersion}`,
27 };
28 }
29 });
30 return lowerCasedUpdates;
31 }