Skip to content

Commit

Permalink
feat: add python to auto manifest discovery
Browse files Browse the repository at this point in the history
Adding support for Pipfile and requirements.txt with --all-projects.
Refactoring tests as well as adding tests for Pipfile and requirements.txt.
  • Loading branch information
lili2311 authored and gitphill committed Jan 29, 2020
1 parent a295643 commit e1651dd
Show file tree
Hide file tree
Showing 9 changed files with 578 additions and 190 deletions.
2 changes: 2 additions & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const AUTO_DETECTABLE_FILES: string[] = [
'Gopkg.lock',
'go.mod',
'vendor.json',
'Pipfile',
'requirements.txt',
];

// when file is specified with --file, we look it up here
Expand Down
22 changes: 22 additions & 0 deletions src/lib/find-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import * as fs from 'fs';
import * as pathLib from 'path';
import * as _ from 'lodash';
import { detectPackageManagerFromFile } from './detect';
import * as debugModule from 'debug';
const debug = debugModule('snyk');

// TODO: use util.promisify once we move to node 8

/**
Expand Down Expand Up @@ -180,25 +183,44 @@ function chooseBestManifest(
['package-lock.json', 'yarn.lock'].includes(path.base),
)[0];
if (lockFile) {
debug(
'Encountered multiple npm manifest files, defaulting to package-lock.json / yarn.lock',
);
return lockFile.path;
}
const packageJson = files.filter((path) =>
['package.json'].includes(path.base),
)[0];
debug(
'Encountered multiple npm manifest files, defaulting to package.json',
);
return packageJson.path;
}
case 'rubygems': {
debug(
'Encountered multiple gem manifest files, defaulting to Gemfile.lock',
);
const defaultManifest = files.filter((path) =>
['Gemfile.lock'].includes(path.base),
)[0];
return defaultManifest.path;
}
case 'cocoapods': {
debug(
'Encountered multiple cocoapod manifest files, defaulting to Podfile',
);
const defaultManifest = files.filter((path) =>
['Podfile'].includes(path.base),
)[0];
return defaultManifest.path;
}
case 'pip': {
debug('Encountered multiple pip manifest files, defaulting to Pipfile');
const defaultManifest = files.filter((path) =>
['Pipfile'].includes(path.base),
)[0];
return defaultManifest.path;
}
default: {
return null;
}
Expand Down
Loading

0 comments on commit e1651dd

Please sign in to comment.