Skip to content

Commit

Permalink
Merge pull request #857 from snyk/feat/propagate-missing-deps
Browse files Browse the repository at this point in the history
feat: show missing deps for old monitor too
  • Loading branch information
lili2311 committed Nov 5, 2019
2 parents 779f0ef + 360e686 commit bd24a91
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/lib/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function filterOutMissingDeps(depTree: DepTree): FilteredDepTree {
const dep = depTree.dependencies[depKey];
if (
(dep as any).missingLockFileEntry ||
(dep as any).labels.missingLockFileEntry
((dep as any).labels && (dep as any).labels.missingLockFileEntry)
) {
// TODO(kyegupov): add field to the type
missingDeps.push(`${dep.name}@${dep.version}`);
Expand All @@ -143,6 +143,7 @@ export async function monitor(
targetFile?: string,
): Promise<MonitorResult> {
apiTokenExists();
let treeMissingDeps: string[] = [];

const packageManager = meta.packageManager;
analytics.add('packageManager', packageManager);
Expand All @@ -165,6 +166,11 @@ export async function monitor(
debug('total dependencies: %d', prePruneDepCount);
pkg = await pruneTree(info.package, meta.packageManager);
}
if (['npm', 'yarn'].includes(meta.packageManager)) {
const { filteredDepTree, missingDeps } = filterOutMissingDeps(info.package);
pkg = filteredDepTree;
treeMissingDeps = missingDeps;
}

const pluginMeta = info.plugin;
const policyPath = meta['policy-path'] || root;
Expand Down Expand Up @@ -206,6 +212,7 @@ export async function monitor(
org: config.org ? decodeURIComponent(config.org) : undefined,
pluginName: pluginMeta.name,
pluginRuntime: pluginMeta.runtime,
missingDeps: treeMissingDeps,
dockerImageId: pluginMeta.dockerImageId,
dockerBaseImage: pkg.docker ? pkg.docker.baseImage : undefined,
dockerfileLayers: pkg.docker
Expand Down
1 change: 0 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export interface MonitorOptions {

export interface MonitorMeta {
method: 'cli' | 'wizard';
missingDeps?: string[];
packageManager: SupportedPackageManagers;
'policy-path': string;
'project-name': string;
Expand Down
16 changes: 15 additions & 1 deletion test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3148,7 +3148,7 @@ test('`monitor npm-package`', async (t) => {
t.notOk(req.body.meta.prePruneDepCount, "doesn't send meta.prePruneDepCount");
});

test('`monitor npm-out-of-sync`', async (t) => {
test('`monitor npm-out-of-sync graph monitor`', async (t) => {
chdirWorkspaces();
await cli.monitor('npm-out-of-sync-graph', {
'experimental-dep-graph': true,
Expand All @@ -3168,6 +3168,20 @@ test('`monitor npm-out-of-sync`', async (t) => {
);
});

test('`monitor npm-out-of-sync old monitor`', async (t) => {
chdirWorkspaces();
await cli.monitor('npm-out-of-sync-graph', {
strictOutOfSync: false,
});
const req = server.popRequest();
t.match(req.url, '/monitor/npm', 'puts at correct url');
t.deepEqual(
req.body.meta.missingDeps,
['body-parser@^1.18.2'],
'missingDeps passed',
);
});

test('`monitor npm-package-pruneable --prune-repeated-subdependencies`', async (t) => {
chdirWorkspaces();

Expand Down

0 comments on commit bd24a91

Please sign in to comment.