Skip to content

Draft: Auto Compile typescript projects

Sumit Paul requested to merge sumitp302/jsfuzz:master into master

This pull request adds a new feature to jsfuzz. The new feature is a flag “–ts-compile” and a configuration file “.jsfuzzrc” that enable the fuzzer to compile TypeScript projects before fuzzing them. TypeScript is a superset language that adds static typing and other features to JavaScript. TypeScript projects need to be compiled to JavaScript before they can be executed by Node.js. Jsfuzz by default does not support fuzzing TypeScript projects and requires manual compilation or transformation of the code before fuzzing.

The new feature simplifies and automates the compilation process for TypeScript projects and saves the user from the manual and tedious task of compiling or transforming the code. It also ensures the consistency and correctness of the code that is fuzzed by jsfuzz.

The flag “–ts-compile” instructs the fuzzer that there is an underlying TypeScript project that needs to be compiled first and then the fuzzing process should start on the compiled version. The configuration file “.jsfuzzrc” provides some predefined configurations from the user, such as the build directory, the pre-compile scripts, the custom compile command, and the post-compile scripts.

The new feature is implemented by modifying the jsfuzz command line parser, core module, and main function. The modification demands a configuration file to be passed named .jsfuzzrc whenever the new flag --ts-compile is passed. The configuration file is in the format -

{
    "buildDirectory": "dist", // name of build folder
    "preCompile": [], // Pre-Complie scripts, accepts string[]. Runs before compilation starts
    "customCompileCommand": "npm run build", // Custom compile command to override the default command
    "postCompile": [] // Post-Complie scripts, accepts string[]. Runs after compilation is complete
}

The field "buildDirectory" serves to define the name of the build folder following the compilation process. It's important for this name to align with the tsconfig.json file of the project. This ensures that the fuzzer accurately identifies the build directory where the compiled code will reside after the compilation is complete.

The "preCompile" field accommodates scripts that the user intends to execute prior to initiating the compilation process. It accepts an array of strings comprising the commands that need to be executed.

For "customCompileCommand", this field allows the user to override the default TypeScript compilation command with a custom one that suits the project's needs.

Conversely, the "postCompile" field is designed for scripts that should run after the compilation process but before commencing the fuzzing process. Similar to "preCompile", it also accepts an array of strings containing the desired commands to be executed at this stage.

image

Merge request reports