Skip to content

Commit

Permalink
feat: propagate full plugin meta always
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 authored and gitphill committed Jan 24, 2020
1 parent 0ea23d5 commit e09faa0
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async function monitor(...args0: MethodArgs): Promise<any> {
generateMonitorMeta(options, packageManager),
projectDeps,
options,
perProjectResult.plugin as PluginMetadata,
projectDeps.plugin as PluginMetadata,
targetFileRelativePath,
),
spinner.clear(postingMonitorSpinnerLabel),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function convertMultiResultToMultiCustom(
plugin: inspectRes.plugin,
scannedProjects: convertScannedProjectsToCustom(
inspectRes.scannedProjects,
inspectRes.plugin,
(inspectRes.plugin.packageManager as SupportedPackageManagers) ||
packageManager,
targetFile,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/plugins/convert-scanned-projects-to-custom.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import * as cliInterface from '@snyk/cli-interface';
import { ScannedProjectCustom } from './get-multi-plugin-result';
import { SupportedPackageManagers } from '../package-managers';
import { PluginMetadata } from '@snyk/cli-interface/legacy/plugin';

export function convertScannedProjectsToCustom(
scannedProjects: cliInterface.legacyCommon.ScannedProject[],
pluginMeta: PluginMetadata,
packageManager?: SupportedPackageManagers,
targetFile?: string,
): ScannedProjectCustom[] {
// annotate the package manager & targetFile to be used
// for test & monitor
return scannedProjects.map((a) => {
(a as ScannedProjectCustom).plugin =
(a as ScannedProjectCustom).plugin || pluginMeta;
(a as ScannedProjectCustom).targetFile = a.targetFile || targetFile;
(a as ScannedProjectCustom).packageManager = (a as ScannedProjectCustom)
.packageManager
Expand Down
2 changes: 2 additions & 0 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 { PluginMetadata } from '@snyk/cli-interface/legacy/plugin';

export function convertSingleResultToMultiCustom(
inspectRes: pluginApi.SinglePackageResult,
Expand All @@ -19,6 +20,7 @@ export function convertSingleResultToMultiCustom(
plugin,
scannedProjects: [
{
plugin: plugin as any,
depTree,
meta,
targetFile: plugin.targetFile,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/plugins/get-multi-plugin-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as _ from 'lodash';
import * as path from 'path';
import * as cliInterface from '@snyk/cli-interface';

import { TestOptions, Options, MonitorOptions } from '../types';
import { TestOptions, Options, MonitorOptions, PluginMetadata } from '../types';
import { detectPackageManagerFromFile } from '../detect';
import { SupportedPackageManagers } from '../package-managers';
import { getSinglePluginResult } from './get-single-plugin-result';
Expand All @@ -12,6 +12,7 @@ import { convertMultiResultToMultiCustom } from './convert-multi-plugin-res-to-m
export interface ScannedProjectCustom
extends cliInterface.legacyCommon.ScannedProject {
packageManager: SupportedPackageManagers;
plugin: PluginMetadata;
}
export interface MultiProjectResultCustom
extends cliInterface.legacyPlugin.MultiProjectResult {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snyk-test/run-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ async function assembleLocalPayloads(

let body: PayloadBody = {
// WARNING: be careful changing this as it affects project uniqueness
targetFile: deps.plugin.targetFile,
targetFile: project.plugin.targetFile,
projectNameOverride: options.projectName,
originalProjectName: pkg.name,
policy: policy && policy.toString(),
Expand Down
16 changes: 0 additions & 16 deletions test/acceptance/cli-monitor/cli-monitor.all-projects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ export const AllProjectsTests: AcceptanceTests = {

// Ruby project

// Removing properties that are different for plugin and custom-plugin
// (pluginName, pluginRuntime)
delete rubyAll.body.meta.pluginName;
delete requestsRuby.body.meta.pluginName;
delete requestsRuby.body.meta.pluginRuntime;

t.deepEqual(
rubyAll.body,
requestsRuby.body,
Expand All @@ -189,11 +183,6 @@ export const AllProjectsTests: AcceptanceTests = {

// NPM project

// Removing properties that are different for plugin and custom-plugin
// (pluginName, pluginRuntime)
delete npmAll.body.meta.pluginName;
delete requestsNpm.body.meta.pluginName;
delete requestsNpm.body.meta.pluginRuntime;
t.deepEqual(
npmAll.body,
requestsNpm.body,
Expand All @@ -202,11 +191,6 @@ export const AllProjectsTests: AcceptanceTests = {

// Maven project

// Removing properties that are different for plugin and custom-plugin
// (pluginName, pluginRuntime)
delete mavenAll.body.meta.pluginName;
delete requestsMaven.body.meta.pluginName;
delete requestsMaven.body.meta.pluginRuntime;
t.deepEqual(
mavenAll.body,
requestsMaven.body,
Expand Down

0 comments on commit e09faa0

Please sign in to comment.