"Fossies" - the Fresh Open Source Software Archive 
Member "cli-1.1260.0/src/lib/plugins/convert-single-splugin-res-to-multi-custom.ts" (4 Dec 2023, 2010 Bytes) of package /linux/misc/snyk-cli-1.1260.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 { legacyPlugin as pluginApi } from '@snyk/cli-interface';
2 import { MultiProjectResultCustom } from './get-multi-plugin-result';
3 import { SupportedPackageManagers } from '../package-managers';
4 import { CallGraph } from '@snyk/cli-interface/legacy/common';
5
6 export function convertSingleResultToMultiCustom(
7 inspectRes: pluginApi.SinglePackageResult,
8 packageManager?: SupportedPackageManagers,
9 ): MultiProjectResultCustom {
10 if (!packageManager) {
11 packageManager = inspectRes.plugin
12 .packageManager as SupportedPackageManagers;
13 }
14 if (inspectRes.dependencyGraph) {
15 return convertDepGraphResult(inspectRes, packageManager);
16 } else {
17 return convertDepTreeResult(inspectRes, packageManager);
18 }
19 }
20
21 function convertDepGraphResult(
22 inspectRes: pluginApi.SinglePackageResult,
23 packageManager: SupportedPackageManagers,
24 ): MultiProjectResultCustom {
25 const { plugin, meta, dependencyGraph: depGraph, callGraph } = inspectRes;
26 return {
27 plugin,
28 scannedProjects: [
29 {
30 plugin: plugin as any,
31 depGraph,
32 callGraph: callGraph as CallGraph,
33 meta,
34 targetFile: plugin.targetFile,
35 packageManager,
36 },
37 ],
38 };
39 }
40
41 /**
42 * @deprecated @boost: delete me when all languages uses depGraph
43 */
44 function convertDepTreeResult(
45 inspectRes: pluginApi.SinglePackageResult,
46 packageManager: SupportedPackageManagers,
47 ): MultiProjectResultCustom {
48 if (
49 inspectRes.package &&
50 !inspectRes.package.targetFile &&
51 inspectRes.plugin
52 ) {
53 inspectRes.package.targetFile = inspectRes.plugin.targetFile;
54 }
55 const { plugin, meta, package: depTree, callGraph } = inspectRes;
56
57 if (depTree && !depTree.targetFile && plugin) {
58 depTree.targetFile = plugin.targetFile;
59 }
60
61 return {
62 plugin,
63 scannedProjects: [
64 {
65 plugin: plugin as any,
66 depTree,
67 callGraph: callGraph as CallGraph,
68 meta,
69 targetFile: plugin.targetFile,
70 packageManager,
71 },
72 ],
73 };
74 }