Skip to content

Commit

Permalink
Quietened tsc output w.r.t. typing issues (#166)
Browse files Browse the repository at this point in the history
Putting an empty array as compilerOptions types and typeRoots speeds up tsc a lot and removes tons of type checking warnings/errors (we do not care for types there anyway).
Also filtered the remaining stacktrace (if any) for tsc error codes.
  • Loading branch information
max-leuthaeuser authored May 12, 2022
1 parent 5d47fd8 commit 327b034
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ object TypescriptTranspiler {

val DEFAULT_MODULE: String = COMMONJS

private val tscTypingWarnings =
List("error TS", ".d.ts", "The file is in the program because", "Entry point of type library")

}

class TypescriptTranspiler(override val config: Config, override val projectPath: Path, subDir: Option[Path] = None)
Expand Down Expand Up @@ -69,8 +72,12 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
val content = FileUtils.readLinesInFile(customTsConfigFilePath).mkString("\n")
val mapper = new ObjectMapper()
val json = mapper.readTree(PackageJsonParser.removeComments(content))
Option(json.get("compilerOptions")).foreach { options =>
options.asInstanceOf[ObjectNode].remove("sourceRoot")
options.asInstanceOf[ObjectNode].putArray("types")
options.asInstanceOf[ObjectNode].putArray("typeRoots")
}
// --include is not available as tsc CLI argument; we set it manually:
Option(json.get("compilerOptions")).foreach(_.asInstanceOf[ObjectNode].remove("sourceRoot"))
json.asInstanceOf[ObjectNode].putArray("include").add("**/*")
val customTsConfigFile =
File
Expand Down Expand Up @@ -100,6 +107,9 @@ 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))

override protected def transpile(tmpTranspileDir: Path): Boolean = {
if (installTsPlugins()) {
File.usingTemporaryDirectory() { tmpForIgnoredDirs =>
Expand Down Expand Up @@ -142,14 +152,18 @@ class TypescriptTranspiler(override val config: Config, override val projectPath
else ""

val command =
s"${ExternalCommand.toOSCommand(tsc)} -sourcemap $sourceRoot --outDir $projOutDir -t ES2017 -m $module --jsx react --noEmit false $projCommand"
s"${ExternalCommand.toOSCommand(tsc)} --skipLibCheck -sourcemap $sourceRoot --outDir $projOutDir -t ES2017 -m $module --jsx react --noEmit false $projCommand"
logger.debug(
s"\t+ TypeScript compiling $projectPath $projCommand to $projOutDir (using $module style modules)"
)

ExternalCommand.run(command, projectPath.toString, extraEnv = NODE_OPTIONS) match {
case Success(_) => logger.debug("\t+ TypeScript compiling finished")
case Failure(exception) => logger.debug("\t- TypeScript compiling failed", exception)
case Success(_) =>
logger.debug("\t+ TypeScript compiling finished")
case Failure(exception) if isCleanTrace(exception) =>
logger.debug("\t+ TypeScript compiling finished")
case Failure(exception) =>
logger.debug(s"\t- TypeScript compiling failed: $exception")
}
}

Expand Down

0 comments on commit 327b034

Please sign in to comment.