-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
spalger
merged 4 commits into
elastic:master
from
spalger:implement/ui-shared-deps-metrics
Sep 30, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[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, | ||
}, | ||
]; | ||
|
||
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) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.