snyk 1.867.0 → 1.868.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -873,8 +873,16 @@ async function loadAndParseTerraformFiles(pathToScan, parsedFiles, failedFiles,
873
873
  // this is because we need all files in the same directory to share the same variable context
874
874
  for (const currentDirectory of allDirectories) {
875
875
  const filePathsInDirectory = getFilesForDirectory(pathToScan, currentDirectory);
876
- if (filePathsInDirectory.length === 0)
877
- continue; // skip directories that have 0 files but have other directories
876
+ if (filePathsInDirectory.length === 0 || // skip directories that have 0 files but have other directories
877
+ (filePathsInDirectory.length === 1 && allParsedFiles.length === 1) // skip single files that have already been parsed
878
+ )
879
+ continue;
880
+ if (filePathsInDirectory.length === 1 &&
881
+ allParsedFiles.length === 0 &&
882
+ (!handle_terraform_files_utils_1.shouldBeParsed(filePathsInDirectory[0]) ||
883
+ handle_terraform_files_utils_1.isIgnoredFile(filePathsInDirectory[0]))) {
884
+ throw new file_loader_1.NoFilesToScanError();
885
+ }
878
886
  try {
879
887
  const tfFilesToParse = await file_loader_1.loadContentForFiles(filePathsInDirectory);
880
888
  const { parsedFiles: parsedTfFiles, failedFiles: failedTfFiles, } = file_parser_1.parseTerraformFiles(tfFilesToParse);
@@ -883,7 +891,8 @@ async function loadAndParseTerraformFiles(pathToScan, parsedFiles, failedFiles,
883
891
  }
884
892
  catch (err) {
885
893
  if (allParsedFiles.length !== 0 && err instanceof file_loader_1.NoFilesToScanError) {
886
- // ignore this error since we might only have .tf files in the folder and we have separated them
894
+ // ignore this error since we might only have TF files in the folder and we have separated them,
895
+ // or if we have a single file scan of a non-TF file, and we have already parsed it
887
896
  }
888
897
  else {
889
898
  throw err;
@@ -900,12 +909,9 @@ exports.loadAndParseTerraformFiles = loadAndParseTerraformFiles;
900
909
  * @returns {string[]} An array with all the non-empty nested directories in this path
901
910
  */
902
911
  function getAllDirectoriesForPath(pathToScan, maxDepth) {
903
- // if it is a single file (it has an extension)
912
+ // if it is a single file (it has an extension), we return the current path
904
913
  if (handle_terraform_files_utils_1.isSingleFile(pathToScan)) {
905
- if (!handle_terraform_files_utils_1.shouldBeParsed(pathToScan) || handle_terraform_files_utils_1.isIgnoredFile(pathToScan)) {
906
- throw new file_loader_1.NoFilesToScanError();
907
- }
908
- return [path.resolve(pathToScan)]; // we return the current path if it is a single file
914
+ return [path.resolve(pathToScan)];
909
915
  }
910
916
  // if the path we scanned itself is an empty directory, finish the scan here
911
917
  if (fs.readdirSync(pathToScan).length === 0) {