[Wasm] Print result of webpack and webpack process not into error log level, print everything from webpack to info log

^KT-64601 fixed
This commit is contained in:
Ilya Goncharov
2024-03-11 19:49:57 +01:00
committed by teamcity
parent 2880082c9a
commit 8a9fb7d954
6 changed files with 47 additions and 35 deletions
@@ -13,7 +13,7 @@ import org.gradle.internal.logging.progress.ProgressLogger
import org.jetbrains.kotlin.gradle.utils.clearAnsiColor import org.jetbrains.kotlin.gradle.utils.clearAnsiColor
import java.text.ParseException import java.text.ParseException
class TeamCityMessageCommonClient( open class TeamCityMessageCommonClient(
internal val clientType: LogType, internal val clientType: LogType,
internal val log: Logger internal val log: Logger
) : ServiceMessageParserCallback { ) : ServiceMessageParserCallback {
@@ -52,7 +52,7 @@ class TeamCityMessageCommonClient(
null null
} }
private fun printMessage(text: String, type: LogType?) { internal open fun printMessage(text: String, type: LogType?) {
val value = text.trimEnd() val value = text.trimEnd()
progressLogger?.progress(value) progressLogger?.progress(value)
@@ -78,10 +78,10 @@ class TeamCityMessageCommonClient(
} }
override fun regularText(text: String) { override fun regularText(text: String) {
if (clientType == LogType.ERROR || clientType == LogType.WARN) { if (clientType.isErrorLike()) {
printMessage(text, clientType) printMessage(text, clientType)
} else { } else {
printMessage(text, LogType.DEBUG) printMessage(text, LogType.INFO)
} }
} }
} }
@@ -18,6 +18,7 @@ internal fun SlfLogger.processLogMessage(
type = type, type = type,
error = ::error, error = ::error,
warn = ::warn, warn = ::warn,
lifecycle = ::info,
info = ::info, info = ::info,
debug = ::debug debug = ::debug
) )
@@ -33,6 +34,7 @@ internal fun GradleLogger.processLogMessage(
type = type, type = type,
error = ::error, error = ::error,
warn = ::warn, warn = ::warn,
lifecycle = ::lifecycle,
info = ::info, info = ::info,
debug = ::debug debug = ::debug
) )
@@ -43,6 +45,7 @@ private fun processLogMessageInternal(
type: LogType, type: LogType,
error: (text: String) -> Unit, error: (text: String) -> Unit,
warn: (text: String) -> Unit, warn: (text: String) -> Unit,
lifecycle: (text: String) -> Unit,
info: (text: String) -> Unit, info: (text: String) -> Unit,
debug: (text: String) -> Unit debug: (text: String) -> Unit
) { ) {
@@ -54,6 +57,7 @@ private fun processLogMessageInternal(
LogType.ERROR -> { LogType.ERROR -> {
error(nonColoredMessage) error(nonColoredMessage)
} }
LogType.LIFECYCLE -> lifecycle(nonColoredMessage)
LogType.INFO, LogType.LOG -> info(nonColoredMessage) LogType.INFO, LogType.LOG -> info(nonColoredMessage)
LogType.DEBUG -> debug(nonColoredMessage) LogType.DEBUG -> debug(nonColoredMessage)
} }
@@ -62,6 +66,7 @@ private fun processLogMessageInternal(
enum class LogType(val value: String) { enum class LogType(val value: String) {
ERROR("error"), ERROR("error"),
WARN("warn"), WARN("warn"),
LIFECYCLE("lifecycle"),
INFO("info"), INFO("info"),
DEBUG("debug"), DEBUG("debug"),
LOG("log"); LOG("log");
@@ -20,7 +20,7 @@ import java.io.OutputStream
* Calls [client] for each parsed message and regular text. * Calls [client] for each parsed message and regular text.
* *
* TeamCity server messages should ends with new line. * TeamCity server messages should ends with new line.
* Only messages short than [MESSAGE_LIMIT_BYTES] supported. * Only messages shorter than [MESSAGE_LIMIT_BYTES] supported.
*/ */
internal class TCServiceMessageOutputStreamHandler( internal class TCServiceMessageOutputStreamHandler(
private val client: ServiceMessageParserCallback, private val client: ServiceMessageParserCallback,
@@ -150,7 +150,6 @@ data class KotlinWebpackConfig(
appendSourceMaps() appendSourceMaps()
appendOptimization() appendOptimization()
appendDevServer() appendDevServer()
appendProgressReporter()
rules.forEach { rule -> rules.forEach { rule ->
if (rule.active) { if (rule.active) {
with(rule) { appendToWebpackConfig() } with(rule) { appendToWebpackConfig() }
@@ -313,34 +312,6 @@ data class KotlinWebpackConfig(
) )
} }
private fun Appendable.appendProgressReporter() {
if (!progressReporter) return
//language=ES6
appendLine(
"""
// Report progress to console
// noinspection JSUnnecessarySemicolon
;(function(config) {
const webpack = require('webpack');
const handler = (percentage, message, ...args) => {
const p = percentage * 100;
let msg = `${"$"}{Math.trunc(p / 10)}${"$"}{Math.trunc(p % 10)}% ${"$"}{message} ${"$"}{args.join(' ')}`;
${
if (progressReporterPathFilterInput == null) "" else """
msg = msg.replace(require('path').resolve(__dirname, ${progressReporterPathFilterInput!!.jsQuoted()}), '');
""".trimIndent()
};
console.log(msg);
};
config.plugins.push(new webpack.ProgressPlugin(handler))
})(config);
""".trimIndent()
)
}
private fun json(obj: Any) = StringWriter().also { private fun json(obj: Any) = StringWriter().also {
GsonBuilder().setPrettyPrinting().create().toJson(obj, it) GsonBuilder().setPrettyPrinting().create().toJson(obj, it)
}.toString() }.toString()
@@ -50,7 +50,7 @@ internal data class KotlinWebpackRunner(
clientType: LogType, clientType: LogType,
progressLogger: ProgressLogger? progressLogger: ProgressLogger?
): TeamCityMessageCommonClient { ): TeamCityMessageCommonClient {
return TeamCityMessageCommonClient(clientType, logger) return WebpackLogClient(clientType, logger)
.apply { .apply {
if (progressLogger != null) { if (progressLogger != null) {
this.progressLogger = progressLogger this.progressLogger = progressLogger
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.targets.js.webpack
import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.gradle.internal.LogType
import org.jetbrains.kotlin.gradle.internal.TeamCityMessageCommonClient
class WebpackLogClient(
clientType: LogType,
log: Logger
) : TeamCityMessageCommonClient(clientType, log) {
override fun regularText(text: String) {
if (WEBPACK_INITIAL_REGEX.matches(text)) {
printMessage(text, LogType.LIFECYCLE)
} else {
super.regularText(text)
}
}
override fun printMessage(text: String, type: LogType?) {
if (WEBPACK_COMPILED_REGEX.matches(text)) {
super.printMessage(text, LogType.LIFECYCLE)
} else {
super.printMessage(text, type)
}
}
companion object {
internal val WEBPACK_COMPILED_REGEX = "webpack (.+) compiled (.+) in .+\\s".toRegex()
internal val WEBPACK_INITIAL_REGEX = "<i> \\[.+] .+\\s".toRegex()
}
}