[Gradle, JS] Filter warning with source maps
#KT-39377 fixed
This commit is contained in:
+12
-4
@@ -217,9 +217,10 @@ data class KotlinWebpackConfig(
|
|||||||
enforce: "pre"
|
enforce: "pre"
|
||||||
});
|
});
|
||||||
config.devtool = ${devtool?.let { "'$it'" } ?: false};
|
config.devtool = ${devtool?.let { "'$it'" } ?: false};
|
||||||
config.stats = {
|
config.stats = config.stats || {}
|
||||||
|
Object.assign(config.stats, config.stats, {
|
||||||
warningsFilter: [/Failed to parse source map/]
|
warningsFilter: [/Failed to parse source map/]
|
||||||
}
|
})
|
||||||
|
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
@@ -369,6 +370,11 @@ data class KotlinWebpackConfig(
|
|||||||
;(function(config) {
|
;(function(config) {
|
||||||
const tcErrorPlugin = require('kotlin-test-js-runner/tc-log-error-webpack');
|
const tcErrorPlugin = require('kotlin-test-js-runner/tc-log-error-webpack');
|
||||||
config.plugins.push(new tcErrorPlugin(tcErrorPlugin))
|
config.plugins.push(new tcErrorPlugin(tcErrorPlugin))
|
||||||
|
config.stats = config.stats || {}
|
||||||
|
Object.assign(config.stats, config.stats, {
|
||||||
|
warnings: false,
|
||||||
|
errors: false
|
||||||
|
})
|
||||||
})(config);
|
})(config);
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
@@ -400,9 +406,11 @@ data class KotlinWebpackConfig(
|
|||||||
const handler = (percentage, message, ...args) => {
|
const handler = (percentage, message, ...args) => {
|
||||||
const p = percentage * 100;
|
const p = percentage * 100;
|
||||||
let msg = `${"$"}{Math.trunc(p / 10)}${"$"}{Math.trunc(p % 10)}% ${"$"}{message} ${"$"}{args.join(' ')}`;
|
let msg = `${"$"}{Math.trunc(p / 10)}${"$"}{Math.trunc(p % 10)}% ${"$"}{message} ${"$"}{args.join(' ')}`;
|
||||||
${if (progressReporterPathFilter == null) "" else """
|
${
|
||||||
|
if (progressReporterPathFilter == null) "" else """
|
||||||
msg = msg.replace(new RegExp(${progressReporterPathFilter.jsQuoted()}, 'g'), '');
|
msg = msg.replace(new RegExp(${progressReporterPathFilter.jsQuoted()}, 'g'), '');
|
||||||
""".trimIndent()};
|
""".trimIndent()
|
||||||
|
};
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,25 +10,50 @@ import {formatMessage, TYPED_MESSAGE} from "./src/teamcity-format";
|
|||||||
const ModuleNotFoundError = require("webpack/lib/ModuleNotFoundError")
|
const ModuleNotFoundError = require("webpack/lib/ModuleNotFoundError")
|
||||||
|
|
||||||
class TeamCityErrorPlugin {
|
class TeamCityErrorPlugin {
|
||||||
|
warningsFilter(value) {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
value = value ? [value] : [];
|
||||||
|
}
|
||||||
|
return value.map(filter => {
|
||||||
|
if (typeof filter === "string") {
|
||||||
|
return (warning, warningString) => warningString.includes(filter);
|
||||||
|
}
|
||||||
|
if (filter instanceof RegExp) {
|
||||||
|
return (warning, warningString) => filter.test(warningString);
|
||||||
|
}
|
||||||
|
if (typeof filter === "function") {
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
`Can only filter warnings with Strings or RegExps. (Given: ${filter})`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.done.tap('TeamCityErrorPlugin', (stats) => {
|
compiler.hooks.done.tap('TeamCityErrorPlugin', (stats) => {
|
||||||
|
|
||||||
|
const warningsFilters = this.warningsFilter(stats.compilation.options.stats.warningsFilter);
|
||||||
|
|
||||||
stats.compilation.errors.forEach(error => {
|
stats.compilation.errors.forEach(error => {
|
||||||
const type = 'error'
|
const type = 'error';
|
||||||
if (error instanceof ModuleNotFoundError) {
|
if (error instanceof ModuleNotFoundError) {
|
||||||
error.dependencies.forEach(dependency => {
|
error.dependencies.forEach(dependency => {
|
||||||
console[type](formatMessage(TYPED_MESSAGE, `Module '${dependency.request}' not found`, type))
|
console[type](formatMessage(TYPED_MESSAGE, `Module '${dependency.request}' not found`, type));
|
||||||
})
|
});
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console[type](formatMessage(TYPED_MESSAGE, error.message, type))
|
console[type](formatMessage(TYPED_MESSAGE, error.message, type));
|
||||||
})
|
});
|
||||||
|
|
||||||
stats.compilation.warnings.forEach(warning => {
|
stats.compilation.warnings
|
||||||
const type = 'warn'
|
.filter(warning => warningsFilters.every(warningFilter => warningFilter(warning)))
|
||||||
|
.forEach(warning => {
|
||||||
|
const type = 'warn';
|
||||||
|
|
||||||
console[type](formatMessage(TYPED_MESSAGE, warning.message, type))
|
console[type](formatMessage(TYPED_MESSAGE, warning.message, type));
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user