1515
1616logger = logging .getLogger (__name__ )
1717
18+ # Folder paths to exclude from npm package scanning
19+ # Add folder paths here that should be skipped during package.json discovery
20+ # Paths should be relative to the repository root (e.g., "deps/v8/tools/turbolizer")
21+ # You can also use folder names for broader exclusions (e.g., "test" excludes all test folders)
22+ EXCLUDE_PATHS = [
23+ # Specific path exclusions
24+ "deps/v8/tools/turbolizer" ,
25+
26+ # General folder name exclusions (will match any folder with this name)
27+ "test" ,
28+ "tests" ,
29+ "examples" ,
30+ "example" ,
31+ "docs" ,
32+ "documentation" ,
33+ "demo" ,
34+ "demos" ,
35+ "coverage" ,
36+ ".git" ,
37+ ".github"
38+ ]
39+
1840
1941class NPMAuditChecker :
2042 """Handles npm audit vulnerability checking for package.json files"""
2143
2244 def __init__ (self , repo_path : Path , timeout : int = 300 ):
2345 self .repo_path = repo_path
2446 self .timeout = timeout
47+ self .exclude_paths = EXCLUDE_PATHS # Use the static exclusion list
2548
2649 def find_package_json_files (self ) -> List [Path ]:
27- """Find all package.json files in the deps/ folder only"""
50+ """Find all package.json files in the deps/ folder only, excluding specified folders """
2851 package_json_files = []
52+ excluded_count = 0
53+
2954 try :
3055 # Only search within the deps/ folder
3156 deps_path = self .repo_path / "deps"
@@ -36,9 +61,30 @@ def find_package_json_files(self) -> List[Path]:
3661 # Use pathlib to recursively find package.json files in deps/ folder
3762 for package_json in deps_path .rglob ("package.json" ):
3863 # Skip node_modules directories
39- if "node_modules" not in str (package_json ):
64+ if "node_modules" in str (package_json ):
65+ continue
66+
67+ # Check if the package.json is in an excluded path
68+ is_excluded = False
69+ package_relative_path = str (package_json .relative_to (self .repo_path ))
70+
71+ for exclude_path in self .exclude_paths :
72+ # Check for exact path match or if path starts with the exclusion
73+ if (package_relative_path .startswith (exclude_path + "/" ) or
74+ package_relative_path == exclude_path or
75+ exclude_path in package_json .parts ): # Also support folder name matching
76+ is_excluded = True
77+ excluded_count += 1
78+ logger .debug (f"Excluding { package_json } (matches exclusion: { exclude_path } )" )
79+ break
80+
81+ if not is_excluded :
4082 package_json_files .append (package_json )
83+
4184 logger .info (f"Found { len (package_json_files )} package.json files in deps/ folder" )
85+ if excluded_count > 0 :
86+ logger .info (f"Excluded { excluded_count } package.json files based on exclusion list: { self .exclude_paths } " )
87+
4288 return package_json_files
4389 except Exception as e :
4490 logger .error (f"Error finding package.json files in deps/ folder: { e } " )
0 commit comments