Skip to content

Commit

Permalink
fix: add graphlib types
Browse files Browse the repository at this point in the history
It was previously typed as any by mistake
  • Loading branch information
JackuB committed Sep 10, 2020
1 parent 0e9ac00 commit d2ea109
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/lib/plugins/convert-single-splugin-res-to-multi-custom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { legacyPlugin as pluginApi } from '@snyk/cli-interface';
import { MultiProjectResultCustom } from './get-multi-plugin-result';
import { SupportedPackageManagers } from '../package-managers';
import { CallGraph } from '@snyk/cli-interface/legacy/common';

export function convertSingleResultToMultiCustom(
inspectRes: pluginApi.SinglePackageResult,
Expand Down Expand Up @@ -28,7 +29,7 @@ function convertDepGraphResult(
{
plugin: plugin as any,
depGraph,
callGraph,
callGraph: callGraph as CallGraph,
meta,
targetFile: plugin.targetFile,
packageManager,
Expand Down Expand Up @@ -63,7 +64,7 @@ function convertDepTreeResult(
{
plugin: plugin as any,
depTree,
callGraph,
callGraph: callGraph as CallGraph,
meta,
targetFile: plugin.targetFile,
packageManager,
Expand Down
11 changes: 8 additions & 3 deletions src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { validateOptions } from '../options-validator';
import { findAndLoadPolicy } from '../policy';
import { assembleIacLocalPayloads, parseIacTestResult } from './run-iac-test';
import { Payload, PayloadBody, DepTreeFromResolveDeps } from './types';
import { CallGraphError } from '@snyk/cli-interface/legacy/common';
import { CallGraphError, CallGraph } from '@snyk/cli-interface/legacy/common';
import * as alerts from '../alerts';
import { abridgeErrorMessage } from '../error-format';
import { getDockerToken } from '../api-token';
Expand Down Expand Up @@ -533,7 +533,10 @@ async function assembleLocalPayloads(
body.depGraph = depGraph;
}

if (options.reachableVulns && scannedProject.callGraph?.message) {
if (
options.reachableVulns &&
(scannedProject.callGraph as CallGraphError)?.message
) {
const err = scannedProject.callGraph as CallGraphError;
const analyticsError = err.innerError || err;
analytics.add('callGraphError', {
Expand All @@ -555,7 +558,9 @@ async function assembleLocalPayloads(
callGraph,
nodeCount,
edgeCount,
} = serializeCallGraphWithMetrics(scannedProject.callGraph);
} = serializeCallGraphWithMetrics(
scannedProject.callGraph as CallGraph,
);
debug(
`Adding call graph to payload, node count: ${nodeCount}, edge count: ${edgeCount}`,
);
Expand Down
5 changes: 3 additions & 2 deletions test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { tmpdir } from 'os';
import { join } from 'path';
import { mkdir, readFileSync } from 'fs';
import * as graphlib from '@snyk/graphlib';
import * as graphlib from 'graphlib';
import { CallGraph } from '@snyk/cli-interface/legacy/common';

export function silenceLog() {
const old = console.log;
Expand Down Expand Up @@ -52,6 +53,6 @@ export function loadJson(filename: string) {
return JSON.parse(readFileSync(filename, 'utf-8'));
}

export function createCallGraph(callGraphPayload: any): string | Buffer {
export function createCallGraph(callGraphPayload: any): CallGraph {
return graphlib.json.read(callGraphPayload);
}

0 comments on commit d2ea109

Please sign in to comment.