diff --git a/.changeset/gentle-chefs-smoke.md b/.changeset/gentle-chefs-smoke.md new file mode 100644 index 000000000000..313d20259d98 --- /dev/null +++ b/.changeset/gentle-chefs-smoke.md @@ -0,0 +1,12 @@ +--- +"wrangler": patch +--- + +Colorize Deployed Bundle Size +Most bundlers, and other tooling that give you size outputs will colorize their the text to indicate if the value is within certain ranges. +The current range values are: +red 100% - 90% +yellow 89% - 70% +green <70% + +resolves #1312 diff --git a/packages/wrangler/src/deployment-bundle/bundle-reporter.ts b/packages/wrangler/src/deployment-bundle/bundle-reporter.ts index 12f730ba8697..57385572cc1e 100644 --- a/packages/wrangler/src/deployment-bundle/bundle-reporter.ts +++ b/packages/wrangler/src/deployment-bundle/bundle-reporter.ts @@ -1,11 +1,12 @@ import { Blob } from "node:buffer"; import { gzipSync } from "node:zlib"; +import chalk from "chalk"; import { logger } from "../logger"; import type { CfModule } from "./worker"; import type { Metafile } from "esbuild"; const ONE_KIB_BYTES = 1024; -const ONE_MIB_BYTES = ONE_KIB_BYTES * 1024; +const ALLOWED_INITIAL_MAX = ONE_KIB_BYTES * 1024; // Current max is 1 MiB async function getSize(modules: CfModule[]) { const gzipSize = gzipSync( @@ -29,9 +30,18 @@ export async function printBundleSize( gzipSize / ONE_KIB_BYTES ).toFixed(2)} KiB`; - logger.log(`Total Upload: ${bundleReport}`); + const percentage = (gzipSize / ALLOWED_INITIAL_MAX) * 100; - if (gzipSize > ONE_MIB_BYTES && !process.env.NO_SCRIPT_SIZE_WARNING) { + const colorizedReport = + percentage > 90 + ? chalk.red(bundleReport) + : percentage > 70 + ? chalk.yellow(bundleReport) + : chalk.green(bundleReport); + + logger.log(`Total Upload: ${colorizedReport}`); + + if (gzipSize > ALLOWED_INITIAL_MAX && !process.env.NO_SCRIPT_SIZE_WARNING) { logger.warn( "We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time" );