[kbn/ui-shared-deps] track asset sizes (#78718)

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Spencer 2020-09-29 22:14:59 -07:00 committed by GitHub
parent 4c4d28ad35
commit 353595617b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,18 +18,21 @@
*/ */
const Path = require('path'); const Path = require('path');
const Fs = require('fs');
const { run, createFailError } = require('@kbn/dev-utils'); const { run, createFailError, CiStatsReporter } = require('@kbn/dev-utils');
const webpack = require('webpack'); const webpack = require('webpack');
const Stats = require('webpack/lib/Stats'); const Stats = require('webpack/lib/Stats');
const del = require('del'); const del = require('del');
const { getWebpackConfig } = require('../webpack.config'); const { getWebpackConfig } = require('../webpack.config');
const DIST_DIR = Path.resolve(__dirname, '../target');
run( run(
async ({ log, flags }) => { async ({ log, flags }) => {
log.info('cleaning previous build output'); log.info('cleaning previous build output');
await del(Path.resolve(__dirname, '../target')); await del(DIST_DIR);
const compiler = webpack( const compiler = webpack(
getWebpackConfig({ getWebpackConfig({
@ -38,10 +41,38 @@ run(
); );
/** @param {webpack.Stats} stats */ /** @param {webpack.Stats} stats */
const onCompilationComplete = (stats) => { const onCompilationComplete = async (stats) => {
const took = Math.round((stats.endTime - stats.startTime) / 1000); const took = Math.round((stats.endTime - stats.startTime) / 1000);
if (!stats.hasErrors() && !stats.hasWarnings()) { if (!stats.hasErrors() && !stats.hasWarnings()) {
if (!flags.dev) {
const reporter = CiStatsReporter.fromEnv(log);
const metrics = [
{
group: '@kbn/ui-shared-deps asset size',
id: 'kbn-ui-shared-deps.js',
value: Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.js')).size,
},
{
group: '@kbn/ui-shared-deps asset size',
id: 'kbn-ui-shared-deps.@elastic.js',
value: Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.@elastic.js')).size,
},
{
group: '@kbn/ui-shared-deps asset size',
id: 'css',
value:
Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.css')).size +
Fs.statSync(Path.resolve(DIST_DIR, 'kbn-ui-shared-deps.v7.light.css')).size,
},
];
log.debug('metrics:', metrics);
await reporter.metrics(metrics);
}
log.success(`webpack completed in about ${took} seconds`); log.success(`webpack completed in about ${took} seconds`);
return; return;
} }
@ -56,11 +87,9 @@ run(
if (flags.watch) { if (flags.watch) {
compiler.hooks.done.tap('report on stats', (stats) => { compiler.hooks.done.tap('report on stats', (stats) => {
try { onCompilationComplete(stats).catch((error) => {
onCompilationComplete(stats);
} catch (error) {
log.error(error.message); log.error(error.message);
} });
}); });
compiler.hooks.watchRun.tap('report on start', () => { compiler.hooks.watchRun.tap('report on start', () => {
@ -83,7 +112,7 @@ run(
return; return;
} }
onCompilationComplete( await onCompilationComplete(
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
compiler.run((error, stats) => { compiler.run((error, stats) => {
if (error) { if (error) {