Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions packages/kbn-ui-shared-deps/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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: '[email protected]',
value: Fs.statSync(Path.resolve(DIST_DIR, '[email protected]')).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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think just tracking the current default CSS (v7 light) is the best solution for the long term. I am trying to think of a reason to also track dark vs light and v7 vs v8 but can't think of any logical reason, especially considering it would add noise since they are pretty closely related.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also expect that once we switch to v8 we'll remove the v7 theme and this will break, forcing us to move over to the v8 theme. And I think what really matters is the default experience.

},
];

log.debug('metrics:', metrics);

await reporter.metrics(metrics);
}

log.success(`webpack completed in about ${took} seconds`);
return;
}
Expand All @@ -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', () => {
Expand All @@ -83,7 +112,7 @@ run(
return;
}

onCompilationComplete(
await onCompilationComplete(
await new Promise((resolve, reject) => {
compiler.run((error, stats) => {
if (error) {
Expand Down