Skip to content

Commit

Permalink
Merge pull request #964 from snyk/feat/add-python-to-auto-detect
Browse files Browse the repository at this point in the history
Feat: add python to auto detect for `--all-projects`
  • Loading branch information
gitphill committed Jan 29, 2020
2 parents c52e45a + e1651dd commit e08bc8f
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
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
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

0 comments on commit e08bc8f

Please sign in to comment.