diff --git a/package.json b/package.json index 6f2499c..af356f2 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,11 @@ "type": "object", "title": "Snyk vulnerability cost configuration", "properties": { + "vulnCost.ignorePaths": { + "type": "array", + "default": [], + "description:": "Paths which should not be scanned" + }, "vulnCost.typescriptExtensions": { "type": "array", "default": [ diff --git a/src/getImports/babelParser.js b/src/getImports/babelParser.js index 093b662..13c1878 100755 --- a/src/getImports/babelParser.js +++ b/src/getImports/babelParser.js @@ -2,6 +2,7 @@ import traverse from '@babel/traverse'; import * as t from '@babel/types'; import * as fs from 'fs'; import * as path from 'path'; +import { workspace } from 'vscode'; import { parse as jsParse } from '@babel/parser'; import { TYPESCRIPT } from './parser'; import logger from '../logger'; @@ -29,10 +30,27 @@ export function getPackages(fileName, source, language) { const packages = []; const visitor = { ImportDeclaration({ node }) { + const configuration = workspace.getConfiguration('vulnCost'); + let pathIgnored = false; + + for (let i = 0; i < configuration.ignorePaths.length; i++) { + const path = configuration.ignorePaths[i]; + pathIgnored = new RegExp(path).test(node.source.value); + + if (pathIgnored) { + continue; + } + } + + if (pathIgnored) { + logger.log(`Import ${node.source.value} matched ignored path: ${path}`); + return; + } + const target = path.dirname(fileName) + path.sep + node.source.value; const fileExists = fs.existsSync(target) || - fs.existsSync(target + '.js' ) || + fs.existsSync(target + '.js') || fs.existsSync(target + path.sep + 'index.js'); if (!fileExists) {