mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Improve stats logging to use pretty-bytes
so that 20B doesn't get output as 0kB, which is accurate, but confusing (#1329)
This commit is contained in:
parent
6ac2568ae3
commit
9cf2df81db
4 changed files with 13 additions and 2 deletions
5
.changeset/tame-rabbits-behave.md
Normal file
5
.changeset/tame-rabbits-behave.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Improve stats logging to use `pretty-bytes` so that 20B doesn't get output as 0kB, which is accurate, but confusing
|
|
@ -85,6 +85,7 @@
|
|||
"picomatch": "^2.2.3",
|
||||
"postcss": "^8.2.15",
|
||||
"postcss-icss-keyframes": "^0.2.1",
|
||||
"pretty-bytes": "^5.6.0",
|
||||
"prismjs": "^1.23.0",
|
||||
"resolve": "^1.20.0",
|
||||
"rollup": "^2.43.1",
|
||||
|
|
|
@ -4,6 +4,7 @@ import type { LogOptions } from '../logger';
|
|||
import { info, table } from '../logger.js';
|
||||
import { underline, bold } from 'kleur/colors';
|
||||
import gzipSize from 'gzip-size';
|
||||
import prettyBytes from 'pretty-bytes';
|
||||
|
||||
interface BundleStats {
|
||||
size: number;
|
||||
|
@ -85,8 +86,7 @@ export function logURLStats(logging: LogOptions, urlStats: URLStatsMap) {
|
|||
.get(url)
|
||||
?.stats.map((s) => s.gzipSize)
|
||||
.reduce((a, b) => a + b, 0) || 0;
|
||||
const kb = (bytes * 0.001).toFixed(2);
|
||||
const sizePart = kb + ' kB';
|
||||
const sizePart = prettyBytes(bytes, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
||||
log(info, urlPart, sizePart);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8577,6 +8577,11 @@ prettier@^2.2.1, prettier@^2.3.2:
|
|||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
|
||||
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
|
||||
|
||||
pretty-bytes@^5.6.0:
|
||||
version "5.6.0"
|
||||
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"
|
||||
integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==
|
||||
|
||||
pretty-format@^3.8.0:
|
||||
version "3.8.0"
|
||||
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-3.8.0.tgz#bfbed56d5e9a776645f4b1ff7aa1a3ac4fa3c385"
|
||||
|
|
Loading…
Reference in a new issue