Skip to content

Commit

Permalink
chore: Update return types for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 31, 2019
1 parent 4c091ec commit 44cb8b5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 57 deletions.
22 changes: 2 additions & 20 deletions src/lib/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,9 @@ import * as pythonPlugin from 'snyk-python-plugin';
import * as goPlugin from 'snyk-go-plugin';
import * as nugetPlugin from 'snyk-nuget-plugin';
import * as phpPlugin from 'snyk-php-plugin';
import * as types from './types';

interface InspectResult {
plugin: {
name: string;
runtime: string;
};
package: any;
}

interface Options {
docker?: boolean;
traverseNodeModules?: boolean;
dev?: boolean;
strictOutOfSync?: boolean | 'true' | 'false';
}

interface Plugin {
inspect: (root: string, targetFile: string, options?: Options) => Promise<InspectResult>;
}

export function loadPlugin(packageManager: string, options: Options = {}): Plugin {
export function loadPlugin(packageManager: string, options: types.Options = {}): types.Plugin {
if (options.docker) {
return dockerPlugin;
}
Expand Down
21 changes: 5 additions & 16 deletions src/lib/plugins/npm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ import * as fs from 'then-fs';
import * as _ from 'lodash';
import {buildDepTree, PkgTree, LockfileType} from 'snyk-nodejs-lockfile-parser';
import * as snyk from '../../';
import * as types from '../types';

interface Options {
traverseNodeModules?: boolean;
dev?: boolean;
strictOutOfSync?: boolean | 'true' | 'false';
}

interface InspectResult {
plugin: {
name: string;
runtime: string;
};
package: PkgTree;
}

export async function inspect(root: string, targetFile: string, options: Options = {}): Promise<InspectResult> {
export async function inspect(root: string, targetFile: string, options: types.Options = {}):
Promise<types.InspectResult> {
const isLockFileBased = targetFile.endsWith('package-lock.json');
const targetFileFullPath = path.resolve(root, targetFile);
const isShrinkwrapPresent = await fs.exists(path.join(path.dirname(targetFileFullPath), 'npm-shrinkwrap.json'));
Expand All @@ -43,7 +31,8 @@ export async function inspect(root: string, targetFile: string, options: Options
};
}

async function generateDependenciesFromLockfile(root: string, targetFile: string, options: Options): Promise<PkgTree> {
async function generateDependenciesFromLockfile(root: string, targetFile: string, options: types.Options):
Promise<PkgTree> {
const lockFileFullPath = path.resolve(root, targetFile);

if (!await fs.exists(lockFileFullPath)) {
Expand Down
9 changes: 3 additions & 6 deletions src/lib/plugins/rubygems/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import {inspectors, Spec} from './inspectors';
import * as types from '../types';

interface InspectResult {
plugin: {
name: string;
runtime: string;
};
interface RubyGemsInspectResult extends types.InspectResult {
package: {
name: string;
targetFile: string;
files: any
};
}

export async function inspect(root: string, targetFile: string): Promise<InspectResult> {
export async function inspect(root: string, targetFile: string): Promise<RubyGemsInspectResult> {
const specs = await gatherSpecs(root, targetFile);

return {
Expand Down
18 changes: 18 additions & 0 deletions src/lib/plugins/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface InspectResult {
plugin: {
name: string;
runtime: string;
};
package: any;
}

export interface Options {
docker?: boolean;
traverseNodeModules?: boolean;
dev?: boolean;
strictOutOfSync?: boolean | 'true' | 'false';
}

export interface Plugin {
inspect: (root: string, targetFile: string, options?: Options) => Promise<InspectResult>;
}
17 changes: 2 additions & 15 deletions src/lib/plugins/yarn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,11 @@ import * as _ from 'lodash';
import * as Debug from 'debug';
import {buildDepTree, PkgTree, LockfileType} from 'snyk-nodejs-lockfile-parser';
import * as snyk from '../../';
import * as types from '../types';

const debug = Debug('snyk');

interface Options {
traverseNodeModules?: boolean;
dev?: boolean;
strictOutOfSync?: boolean | 'true' | 'false';
}

interface InspectResult {
plugin: {
name: string;
runtime: string;
};
package: PkgTree;
}

export async function inspect(root, targetFile, options: Options = {}): Promise<InspectResult> {
export async function inspect(root, targetFile, options: types.Options = {}): Promise<types.InspectResult> {
const isLockFileBased = targetFile.endsWith('yarn.lock');
const targetFileFullPath = path.resolve(root, targetFile);
const isShrinkwrapPresent = await fs.exists(path.join(path.dirname(targetFileFullPath), 'npm-shrinkwrap.json'));
Expand Down

0 comments on commit 44cb8b5

Please sign in to comment.