Skip to main content

Crate wasmcheck

Crate wasmcheck 

Source
Expand description

A WASM bundle size budget checker.

wasmcheck measures the raw, gzip and brotli size of .wasm bundles, keeps a committed baseline with deltas, and fails CI when a budget is exceeded. It is the WASM equivalent of size-limit, not a profiler: twiggy explains why a binary is big, wasmcheck decides whether you may merge it.

§Example

use wasmcheck::{Budget, Metric, SizeReport};

let mut budget = Budget::new();
budget.set_limit(Metric::Gzip, Some("250 KB".parse()?));

let report = SizeReport::new("app.wasm", 675_212, 240_928, 205_110);
assert!(budget.exceeded_metrics(&report).is_empty());

Sizes are given as strings such as "280 KB" or "2.5 MB" and parsed into a validated Size, so a bad budget is rejected while the config is read instead of while a bundle is measured.

§Exit codes

The wasmcheck binary exits with 0 when every file is under budget and 1 when a budget is exceeded or an error occurred. Use WasmCheckError::is_budget_exceeded to tell those two cases apart when embedding the library.

Structs§

Baseline
The recorded sizes of every checked file, keyed by the files entry that selected it.
Compression
The gzip level and brotli quality used to measure a bundle.
Config
The contents of a .wasmcheck.json file.
Limits
Limits of some kind, one optional value per Metric.
Percent
A percentage with up to two decimal places, stored in hundredths of a percent — 5% is 500, 0.5% is 50.
ResolvedFile
A .wasm file selected for checking.
Size
A non-negative byte count.
SizeDelta
The signed difference between a measurement and its baseline, in bytes.
SizeReport
The raw, gzip and brotli size of one bundle, in bytes.

Enums§

Metric
One of the three sizes measured for every bundle.
Threshold
How much a bundle is allowed to grow over its baseline.
WasmCheckError
Everything that can go wrong while reading a config, measuring a bundle or parsing a wasm module.

Constants§

CONFIG_FILE
The config file name wasmcheck looks for when --config is not given.
DEFAULT_BASELINE_FILE
The baseline file name used when the config does not name one.

Functions§

delta_str
Formats the difference between a measured value and its baseline, e.g. "+5.64 KB" or "±0 B".
find_wasm_files
The .wasm files directly inside dir, sorted by path.
format_size
Formats a byte count for humans: "675.21 KB", "1.50 MB", "500 B".
resolve_files
Decides which .wasm files a run should measure.
top_functions
The n largest functions in the module at path, as (size, name) pairs sorted by descending size.

Type Aliases§

Budget
Absolute per-metric size caps — the budget config key.
MaxDelta
Per-metric growth allowances over the committed baseline — the max_delta config key. Each threshold is either an absolute size ("50 KB") or a percentage of the baseline ("5%").