diff --git a/packages/kbn-ui-shared-deps/scripts/build.js b/packages/kbn-ui-shared-deps/scripts/build.js index af4e3481e624d..86251536b8876 100644 --- a/packages/kbn-ui-shared-deps/scripts/build.js +++ b/packages/kbn-ui-shared-deps/scripts/build.js @@ -18,18 +18,21 @@ */ 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 Stats = require('webpack/lib/Stats'); const del = require('del'); const { getWebpackConfig } = require('../webpack.config'); +const DIST_DIR = Path.resolve(__dirname, '../target'); + run( async ({ log, flags }) => { log.info('cleaning previous build output'); - await del(Path.resolve(__dirname, '../target')); + await del(DIST_DIR); const compiler = webpack( getWebpackConfig({ @@ -38,10 +41,38 @@ run( ); /** @param {webpack.Stats} stats */ - const onCompilationComplete = (stats) => { + const onCompilationComplete = async (stats) => { const took = Math.round((stats.endTime - stats.startTime) / 1000); 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`); return; } @@ -56,11 +87,9 @@ run( if (flags.watch) { compiler.hooks.done.tap('report on stats', (stats) => { - try { - onCompilationComplete(stats); - } catch (error) { + onCompilationComplete(stats).catch((error) => { log.error(error.message); - } + }); }); compiler.hooks.watchRun.tap('report on start', () => { @@ -83,7 +112,7 @@ run( return; } - onCompilationComplete( + await onCompilationComplete( await new Promise((resolve, reject) => { compiler.run((error, stats) => { if (error) {