- 
                Notifications
    
You must be signed in to change notification settings  - Fork 4
 
Description
Description
When running joern-parse (which invokes jssrc2cpg) on a single JavaScript or TypeScript file, the process completes without any apparent errors, but the resulting CPG is empty (contains no AST from the source file).
This behavior is counter-intuitive, as users expect to be able to analyze a single file. Other Joern frontends typically support this workflow. The current implementation silently fails, which can be confusing.
Expected Behavior:
Running joern-parse my_file.js should produce a valid CPG containing the AST for my_file.js.
Actual Behavior:
Running joern-parse my_file.js produces an empty CPG. No error message is displayed to the user indicating why the file was not processed.
Steps to Reproduce
- Create a simple JavaScript file:
echo "console.log('Hello, World!');" > test.js
 - Run 
joern-parseon the single file:joern-parse test.js
 - Observe the output. The process will finish successfully.
 - Inspect the generated CPG:
The CPG is effectively empty.
joern joern> importCpg("cpg.bin.zip") joern> cpg.file.name.l // Result: List() joern> cpg.method("log").size // Result: 0
 
Root Cause Analysis
The issue stems from the interaction between jssrc2cpg's AstGenRunner (in Scala) and the astgen tool (in TypeScript).
- The 
jssrc2cpg'sAstGenRunner.scalareceives the single file path as itsinputPath. - It then attempts to execute the 
astgenbinary by setting theworkingDirof the external command to thisinputPath.// jssrc2cpg/utils/AstGenRunner.scala private def jsFiles(in: Path, out: Path): Try[Seq[String]] = { ExternalCommand .run((astGenCommand +: executableArgs) ++ Seq("-t", "ts", "-o", out.toString), workingDir = Option(in)) .toTry }
 - An operating system process cannot have a file as its working directory; it must be a directory. This causes the 
ExternalCommand.runto fail. - The failure is caught by a 
Try, andjssrc2cpgproceeds to look for generated JSON files. Sinceastgennever ran, no JSON files are found, and an empty CPG is produced. - The underlying 
astgentool itself appears to be designed to scan a directory provided via the--srcoption (or the current working directory by default) rather than accepting a single file path as a primary argument. 
Proposed Solution(s)
- Modify 
astgento accept one or more file paths directly as positional arguments or via a new flag. - If file paths are provided, 
astgenshould process only those files, bypassing the directory scanning logic inFileUtils.ts.