Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val cpgVersion = "1.7.37"
val joernVersion = "4.0.384"
val cpgVersion = "1.7.49"
val joernVersion = "4.0.444"

val gitCommitString = SettingKey[String]("gitSha")

Expand Down
4 changes: 2 additions & 2 deletions js2cpg.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

SCRIPT_ABS_PATH=$(readlink -f "$0")
SCRIPT_ABS_DIR=$(dirname $SCRIPT_ABS_PATH)
SCRIPT_ABS_DIR=$(dirname "$SCRIPT_ABS_PATH")

$SCRIPT_ABS_DIR/target/universal/stage/bin/js2cpg -Dlog4j.configurationFile=$SCRIPT_ABS_DIR/src/main/resources/log4j2.xml $@
exec "$SCRIPT_ABS_DIR/target/universal/stage/bin/js2cpg" "-Dlog4j.configurationFile=$SCRIPT_ABS_DIR/src/main/resources/log4j2.xml" "$@"
5 changes: 4 additions & 1 deletion src/main/scala/io/shiftleft/js2cpg/core/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object Config {
val DEFAULT_WITH_NODE_MODULES_FOLDER: Boolean = false
val DEFAULT_OPTIMIZE_DEPENDENCIES: Boolean = true
val DEFAULT_FIXED_TRANSPILATION_DEPENDENCIES: Boolean = false
val DEFAULT_SERVER_MODE: Boolean = false

}

Expand All @@ -59,7 +60,9 @@ case class Config(
moduleMode: Option[String] = Config.DEFAULT_MODULE_MODE,
withNodeModuleFolder: Boolean = Config.DEFAULT_WITH_NODE_MODULES_FOLDER,
optimizeDependencies: Boolean = Config.DEFAULT_OPTIMIZE_DEPENDENCIES,
fixedTranspilationDependencies: Boolean = Config.DEFAULT_FIXED_TRANSPILATION_DEPENDENCIES
fixedTranspilationDependencies: Boolean = Config.DEFAULT_FIXED_TRANSPILATION_DEPENDENCIES,
serverMode: Boolean = Config.DEFAULT_SERVER_MODE,
serverTimeoutSeconds: Option[Int] = None
) {

def createPathForPackageJson(): Path = Paths.get(packageJsonLocation) match {
Expand Down
21 changes: 21 additions & 0 deletions src/main/scala/io/shiftleft/js2cpg/core/Js2CpgMain.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
package io.shiftleft.js2cpg.core

import io.joern.x2cpg.utils.server.FrontendHTTPServer

object Js2CpgMain {
def main(args: Array[String]): Unit = {
val argumentsParser = new Js2cpgArgumentsParser()
argumentsParser.parse(args) match {
case Some(config) if config.serverMode =>
val server: FrontendHTTPServer = new FrontendHTTPServer(
FrontendHTTPServer.defaultExecutor(),
arguments => {
val config = argumentsParser.parse(arguments)
config.foreach(Js2Cpg().run(_))
}
)

val port = server.startup()
println(s"FrontendHTTPServer started on port $port")
try {
config.serverTimeoutSeconds match {
case Some(value) => server.stopServerAfterTimeout(value)
case None => Thread.sleep(Long.MaxValue)
}
} finally {
server.stop()
}
case Some(config) =>
new Js2Cpg().run(config)
case None =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ object Js2cpgArgumentsParser {
val OPTIMIZE_DEPENDENCIES: String = "optimize-dependencies"
val ALL_DEPENDENCIES: String = "all-dependencies"
val FIXED_TRANSPILATION_DEPENDENCIES: String = "fixed-transpilation-dependencies"
val SERVER_MODE: String = "server"
val SERVER_MODE_TIMEOUT_MINUTES: String = "server-timeout-minutes"
val ENABLE_EARLY_SCHEMA_CHECKING: String = "enable-early-schema-checking"
}

class Js2cpgArgumentsParser {
Expand Down Expand Up @@ -203,6 +206,15 @@ class Js2cpgArgumentsParser {
)
.action((module, c) => c.copy(moduleMode = Some(module)))
.hidden()
opt[Unit](SERVER_MODE)
.action((module, c) => c.copy(serverMode = true))
.hidden()
.text("runs this frontend in server mode (disabled by default)")
opt[Int](SERVER_MODE_TIMEOUT_MINUTES)
.action((minutes, c) => c.copy(serverTimeoutSeconds = Some(minutes * 60)))
.hidden()
.text("timeout after which the server should terminate (use with --server)")
opt[Unit](ENABLE_EARLY_SCHEMA_CHECKING).text("does nothing, just here for compat with joern frontends").hidden()
}

def parse(args: Array[String]): Option[Config] = parser.parse(args, Config())
Expand Down
28 changes: 26 additions & 2 deletions updateDependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ check_installed() {

check_installed curl

# macOS is known to ship 'bash' version < 4
if [[ "$OSTYPE" == "darwin"* ]]; then
BASH_VERSION=`bash --version | grep "GNU bash, version " | awk '{print $4}' | cut -d. -f1`
if [[ $BASH_VERSION -lt 4 ]]; then
echo "error: 'bash' version detected is less than 4"
if [ "$NON_INTERACTIVE_OPTION" == "--non-interactive" ]
then
echo "update 'bash' using 'brew install bash'? [Y/n]"
read ANSWER
if [ -z $ANSWER ] || [ "y" == $ANSWER ] || [ "Y" == $ANSWER ]
then
brew install bash
else
exit 1
fi
else
echo "error: Please upgrade bash version and re-run"
exit 1
fi
fi
fi

# check if xmllint is installed
if type xmllint > /dev/null; then
USE_XMLLINT=1 #true
Expand Down Expand Up @@ -58,13 +80,13 @@ function update {
if [ "$NON_INTERACTIVE_OPTION" == "--non-interactive" ]
then
echo "non-interactive mode, auto-updating $NAME: $OLD_VERSION -> $VERSION"
sed -i "s/$SEARCH/$REPLACE/" build.sbt
sed -i'.bak' "s/$SEARCH/$REPLACE/" build.sbt
else
echo "update $NAME: $OLD_VERSION -> $VERSION? [Y/n]"
read ANSWER
if [ -z $ANSWER ] || [ "y" == $ANSWER ] || [ "Y" == $ANSWER ]
then
sed -i "s/$SEARCH/$REPLACE/" build.sbt
sed -i'.bak' "s/$SEARCH/$REPLACE/" build.sbt
fi
fi
fi
Expand All @@ -77,3 +99,5 @@ else
DEPENDENCY="${DEPENDENCY#--only=}"
update $DEPENDENCY
fi

rm -f build.sbt.bak # Remove back-up files generated by 'sed'