Skip to content

Commit

Permalink
Merge pull request #1165 from snyk/feat/support-depgraph-deptree-coex…
Browse files Browse the repository at this point in the history
…istence

feat/support depgraph deptree coexistence from plugins
  • Loading branch information
anthogez committed Jun 16, 2020
2 parents 3ad3596 + 45440ef commit 43f5b5d
Show file tree
Hide file tree
Showing 16 changed files with 530 additions and 90 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"author": "snyk.io",
"license": "Apache-2.0",
"dependencies": {
"@snyk/cli-interface": "2.6.0",
"@snyk/cli-interface": "2.8.0",
"@snyk/dep-graph": "1.18.3",
"@snyk/gemfile": "1.2.0",
"@snyk/graphlib": "2.1.9-patch",
Expand Down
40 changes: 31 additions & 9 deletions src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as spinner from '../../../lib/spinner';
import * as analytics from '../../../lib/analytics';
import { MethodArgs, ArgsOptions } from '../../args';
import { apiTokenExists } from '../../../lib/api-token';
import { maybePrintDeps } from '../../../lib/print-deps';
import { maybePrintDepTree, maybePrintDepGraph } from '../../../lib/print-deps';
import { monitor as snykMonitor } from '../../../lib/monitor';
import { processJsonMonitorResponse } from './process-json-monitor';
import snyk = require('../../../lib'); // TODO(kyegupov): fix import
Expand All @@ -40,6 +40,7 @@ import {
GitRepoCommitStats,
execShell,
} from '../../../lib/monitor/dev-count-analysis';
import { FailedToRunTestError } from '../../../lib/errors';

const SEPARATOR = '\n-------------------------------------------------------\n';
const debug = Debug('snyk');
Expand Down Expand Up @@ -181,19 +182,42 @@ async function monitor(...args0: MethodArgs): Promise<any> {

// Post the project dependencies to the Registry
for (const projectDeps of perProjectResult.scannedProjects) {
if (!projectDeps.depGraph && !projectDeps.depTree) {
debug(
'scannedProject is missing depGraph or depTree, cannot run test/monitor',
);
throw new FailedToRunTestError(
'Your monitor request could not be completed. Please email support@snyk.io',
);
}
const extractedPackageManager = extractPackageManager(
projectDeps,
perProjectResult,
options as MonitorOptions & Options,
);

analytics.add('packageManager', extractedPackageManager);
maybePrintDeps(options, projectDeps.depTree);

debug(`Processing ${projectDeps.depTree.name}...`);
let projectName;

if (projectDeps.depGraph) {
debug(`Processing ${projectDeps.depGraph.rootPkg.name}...`);
maybePrintDepGraph(options, projectDeps.depGraph);
projectName = projectDeps.depGraph.rootPkg.name;
}

if (projectDeps.depTree) {
debug(`Processing ${projectDeps.depTree.name}...`);
maybePrintDepTree(options, projectDeps.depTree);
projectName = projectDeps.depTree.name;
}

const tFile = projectDeps.targetFile || targetFile;
const targetFileRelativePath = tFile
? pathUtil.join(pathUtil.resolve(path), tFile)
: '';
const targetFileRelativePath =
projectDeps.plugin.targetFile ||
(tFile && pathUtil.join(pathUtil.resolve(path), tFile)) ||
'';

const res: MonitorResult = await promiseOrCleanup(
snykMonitor(
path,
Expand All @@ -208,18 +232,16 @@ async function monitor(...args0: MethodArgs): Promise<any> {
);

res.path = path;
const projectName = projectDeps.depTree.name;

const monOutput = formatMonitorOutput(
extractedPackageManager,
res,
options,
projectName,
getSubProjectCount(inspectResult),
);
// push a good result
results.push({ ok: true, data: monOutput, path, projectName });
}
// push a good result
} catch (err) {
// push this error, the loop continues
results.push({ ok: false, data: err, path });
Expand Down

0 comments on commit 43f5b5d

Please sign in to comment.