Skip to content

Commit

Permalink
Ignore some more tsc warnings (#292)
Browse files Browse the repository at this point in the history
This cleans the DEBUG log a lot as these tsc warnings are of no use for us at all.
For: https://shiftleftinc.atlassian.net/browse/SEN-1361
  • Loading branch information
max-leuthaeuser authored Aug 2, 2023
1 parent c5c18e5 commit 62b84ba
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/io/shiftleft/js2cpg/core/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ case class Config(
s"""
|\t- Source project: '$srcDir'
|\t- package.json location: '${createPathForPackageJson()}'
|\t- Module mode: '${moduleMode.getOrElse(TypescriptTranspiler.DEFAULT_MODULE)}'
|\t- Module mode: '${moduleMode.getOrElse(TypescriptTranspiler.DefaultModule)}'
|\t- Optimize dependencies: $optimizeDependencies
|\t- Fixed transpilations dependencies: $fixedTranspilationDependencies
|\t- Typescript transpiling: $tsTranspiling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Js2cpgArgumentsParser {
.hidden()
opt[String](MODULE_MODE)
.text(
s"set the module mode for transpiling (default is '${TypescriptTranspiler.DEFAULT_MODULE}', alternatives are e.g., esnext or es2015)"
s"set the module mode for transpiling (default is '${TypescriptTranspiler.DefaultModule}', alternatives are e.g., esnext or es2015)"
)
.action((module, c) => c.copy(moduleMode = Some(module)))
.hidden()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object FreshJsonParser {
val objectMapper = new ObjectMapper
FileUtils
.getFileTree(Paths.get(config.srcDir), config, List(".json"))
.filter(_.endsWith(TypescriptTranspiler.DENO_CONFIG))
.filter(_.endsWith(TypescriptTranspiler.DenoConfig))
.flatMap { file =>
val packageJson = objectMapper.readTree(IOUtils.readLinesInFile(file).mkString)
Option(packageJson.path("importMap").asText()).map(file.resolveSibling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import io.shiftleft.js2cpg.io.FileDefaults.TS_SUFFIX
import io.shiftleft.js2cpg.io.{ExternalCommand, FileUtils}
import io.shiftleft.js2cpg.parser.PackageJsonParser
import io.shiftleft.js2cpg.parser.TsConfigJsonParser
import io.shiftleft.js2cpg.preprocessing.TypescriptTranspiler.DEFAULT_MODULE
import io.shiftleft.js2cpg.preprocessing.TypescriptTranspiler.DENO_CONFIG
import io.shiftleft.js2cpg.preprocessing.TypescriptTranspiler.DefaultModule
import io.shiftleft.js2cpg.preprocessing.TypescriptTranspiler.DenoConfig
import io.shiftleft.utils.IOUtils
import org.slf4j.LoggerFactory
import org.apache.commons.io.{FileUtils => CommonsFileUtils}
Expand All @@ -19,12 +19,22 @@ import scala.util.{Failure, Success, Try}

object TypescriptTranspiler {

val DEFAULT_MODULE: String = "commonjs"
val DefaultModule: String = "commonjs"

private val tscTypingWarnings =
List("error TS", ".d.ts", "The file is in the program because", "Entry point of type library")
private val TscTypingWarnings = List(
"error TS",
".d.ts",
"The file is in the program because",
"Entry point of type library",
"does not exist on type",
"properties from type",
"are incompatible",
"was found on type",
"not assignable to",
"Overload "
)

val DENO_CONFIG: String = "deno.json"
val DenoConfig: String = "deno.json"

}

Expand All @@ -39,7 +49,7 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
private def hasTsFiles: Boolean =
FileUtils.getFileTree(projectPath, config, List(TS_SUFFIX)).nonEmpty

private def isFreshProject: Boolean = (File(projectPath) / DENO_CONFIG).exists
private def isFreshProject: Boolean = (File(projectPath) / DenoConfig).exists

private def isTsProject: Boolean =
(File(projectPath) / "tsconfig.json").exists || isFreshProject
Expand Down Expand Up @@ -108,7 +118,7 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
}

private def isCleanTrace(exception: Throwable): Boolean =
exception.getMessage.linesIterator.forall(l => TypescriptTranspiler.tscTypingWarnings.exists(l.contains))
exception.getMessage.linesIterator.forall(l => TypescriptTranspiler.TscTypingWarnings.exists(l.contains))

override protected def transpile(tmpTranspileDir: Path): Boolean = {
if (installTsPlugins()) {
Expand All @@ -131,7 +141,7 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
"" :: Nil
}

val module = config.moduleMode.getOrElse(DEFAULT_MODULE)
val module = config.moduleMode.getOrElse(DefaultModule)
val outDir = subDir.map(s => File(tmpTranspileDir.toString, s.toString)).getOrElse(File(tmpTranspileDir))

for (proj <- projects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ class VueTranspiler(override val config: Config, override val projectPath: Path)

private def nodeOptions(): Map[String, String] = {
// TODO: keep this until https://github.com/webpack/webpack/issues/14532 is fixed.
// This hack is not required on MacOS.
if (
!scala.util.Properties.isMac &&
nodeVersion().exists(v => v.startsWith("v17") || v.startsWith("v18") || v.startsWith("v19"))
) {
if (nodeVersion().exists(v => v.startsWith("v17") || v.startsWith("v18") || v.startsWith("v19"))) {
Map("NODE_OPTIONS" -> "--openssl-legacy-provider")
} else {
Map.empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class DependenciesPassTest extends AbstractPassTest {
| "envalid": "https://deno.land/x/[email protected]/mod.ts"
|}}""".stripMargin
),
(TypescriptTranspiler.DENO_CONFIG, """{"importMap": "./import_map.json"}""")
(TypescriptTranspiler.DenoConfig, """{"importMap": "./import_map.json"}""")
)
) { cpg =>
val deps = getDependencies(cpg).l
Expand Down

0 comments on commit 62b84ba

Please sign in to comment.