monosize
CLAUDE.md48 starsChanged 3 years agoMITView on GitHub
monosize is a CLI tool that measures bundle sizes for packages and monorepos and compares them against a stored baseline (typically main). This repo is itself a Yarn 4 + Nx monorepo of the CLI plus first-party adapter packages. The packages/ directory has three roles: Adapters are wired up by users in their own monosize.config.mjs; this repo does not consume itself end-to-end. When changing the BundlerAdapter / StorageAdapter shape, every adapter package must be updated in lockstep. Per-package and full-graph…
The file
We split this CLAUDE.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 74
One change file per affected package: If a PR changes both monosize and monosize-bundler-webpack, expect two files — yarn change walks you …
- Very specific: line 79
Source layout: Every package is ESM, sources in src/*.mts, compiled output in dist/, declarations emitted via tsc --build tsconfig.lib.json.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Repository overview
monosize is a CLI tool that measures bundle sizes for packages and monorepos and compares them against a stored baseline (typically main). This repo is itself a Yarn 4 + Nx monorepo of the CLI plus first-party adapter packages.
The packages/ directory has three roles:
monosize— the CLI (commands:measure,compare-reports,upload-report). Defines theBundlerAdapterandStorageAdaptercontracts inpackages/monosize/src/types.mts.monosize-bundler-*(webpack, rspack, vite) — implementBundlerAdapter. Each exposes a factory that takes a config-enhancer callback and returns{ buildFixture, buildFixtures, name }.buildFixtureruns one fixture through the bundler;buildFixturesruns many in a single pass (multi-entry) and is what the CLI uses in default--build-mode=batch. Vite is the exception: itsbuildFixturesis a sequential loop because rollup's es-lib mode doesn't natively emit multiple self-contained bundles in one pass.monosize-storage-*(git, upstash) — implementStorageAdapter(getRemoteReport,uploadReportToRemote).
Adapters are wired up by users in their own monosize.config.mjs; this repo does not consume itself end-to-end. When changing the BundlerAdapter / StorageAdapter shape, every adapter package must be updated in lockstep.
Common commands
yarn build # nx affected:build (since main)
yarn lint # nx affected:lint
yarn test # nx affected:test
yarn check-dependencies # syncpack lint (prod + peer must align across packages)
yarn change # beachball change — interactive prompt to create a change file (see below)Per-package and full-graph operations (use npx nx ...):
npx nx run-many --target=build --all # build everything
npx nx run-many --target=build --all --parallel --max-parallel=3
npx nx run <pkg>:build # e.g. monosize-bundler-webpack:build
npx nx run <pkg>:test
npx nx run <pkg>:lint
npx nx run <pkg>:typecheck # tsc --noEmit per packageSingle test file or single test name (Vitest under the hood):
npx vitest run packages/monosize-bundler-webpack/src/runTerser.test.mts
npx vitest run -t 'should throw on compilation errors'Note: tests resolve workspace packages via the @monosize/source condition (see tsconfig.base.json and each vitest.config.mts), so tests pick up sibling-package changes from src/ without a rebuild.
Change files (beachball)
This repo follows semver and uses beachball to manage versioning and changelogs. Every PR that modifies shipped code must include a change file — CI runs beachball check on PRs (.github/workflows/ci-change.yml) and fails when one is missing.
yarn change # interactive: pick a bump type per affected package, write a comment
yarn change -m "fix: ..." # non-interactive, reuse the same comment for all packages
npx beachball check # what CI runs; verifies a change file exists for every affected packageyarn change is wired to beachball change --no-commit, so it stages the new file(s) under change/<packageName>-<uuid>.json but leaves committing to you. Each file looks like:
{
"type": "patch",
"comment": "Fix bin script to import from dist instead of src",
"packageName": "monosize",
"email": "olfedias@microsoft.com",
"dependentChangeType": "patch"
}Notes:
- Allowed bump types:
patch,minor,none.majoris blocked bydisallowedChangeTypesinbeachball.config.js. Usenonefor changes that touch a package but shouldn't trigger a release (e.g. internal refactors with no consumer impact). - Pick the type from the comment prefix.
fix:→patch,feat:→minor,chore:/docs:/refactor:/test:→ usuallynone. The comment becomes the changelog line, so write it for end users (no PR numbers, no internal jargon). - Files that don't require a change file are listed in
beachball.config.js#ignorePatterns:__fixtures__/,*.test.mts,eslint.config.*,vitest.config.mts,project.json,README.md. PRs that only touch those (or repo-root tooling like workflows,nx.json, etc.) won't be flagged bybeachball check. - One change file per affected package. If a PR changes both
monosizeandmonosize-bundler-webpack, expect two files —yarn changewalks you through them. - Change files are consumed and deleted by the release pipeline (
beachball publish), which then commitsapplying package updateswith the version bumps and CHANGELOG entries. Don't hand-editCHANGELOG.md/CHANGELOG.json.
Architecture notes
- Source layout. Every package is ESM, sources in
src/*.mts, compiled output indist/, declarations emitted viatsc --build tsconfig.lib.json.tsconfig.spec.jsonexcludes*.test.mtsfrom the lib build.isolatedDeclarationsis on, so all exported APIs need explicit return types. - Source vs built consumption. Each package's
exportsmap has a@monosize/sourcecondition pointing atsrc/index.mtsand adefaultpointing atdist/index.mjs. Tooling configured with that condition (Vitest, type-checks, internal tools) reads sources directly; published consumers get the compiled output. Don't add cross-package imports that would bypass this — go through the public entry point. - Bundler adapter contract.
BundlerAdapter.buildFixturesis the batch path (3–15× faster);buildFixtureis the sequential path used when the user passes--build-mode=sequential, which is mostly a debugging aid. Both return{ name, outputDir, debugOutputPath? }per fixture.outputDiris a per-fixture directory the CLI walks non-recursively; the JS bundle lives at<outputDir>/index.js. Debug output (whendebug: true) is a beautified*.debug.jsfile written alongsideoutputDir, not inside it (so the extension scan doesn't double-count). - Asset types and report shape. The CLI classifies files in
outputDirby extension againstMonoSizeConfig.assetTypes(closed'js' | 'json' | 'css'union; default['js'], opt in to'css'/'json'explicitly). Each report entry carries top-levelminifiedSize/gzippedSize(sums) plus aPartial<Record<AssetType, AssetSize>>breakdown. Threshold gates on totals only; per-type deltas surface in the diff renderers (CLI sub-rows, markdown### Breakdown<details>blocks). measureoutput. Each package producesdist/bundle-size/monosize.json;compare-reportsandupload-reportglob those (defaultpackages/**/dist/bundle-size/monosize.json). Package-name resolution defaults topackage.json#name/project.json#nameand can be overridden viaMonoSizeConfig.reportResolvers.- Versioning. Beachball, configured in
beachball.config.js—disallowedChangeTypes: ['major'](no major bumps allowed in this repo) andgitTags: false. Theprecommithook inbeachball.hooks.jsrunsyarn install --no-immutableafter version bumps so the lockfile stays in sync;prepublishruns the full build before publishing so artifacts pick up the bumped versions. - Pre-commit.
simple-git-hooksrunsnano-staged, which formats staged JS/TS/JSON via Prettier and refreshes Markdown TOCs via doctoc. Don't bypass with--no-verify— the lockfile-sync precommit hook above is part of the release flow. - Lint specifics.
eslint.config.mjsenforces@nx/enforce-module-boundariesandimport-x/no-extraneous-dependencies(devDependencies disallowed in prod source).*.mtsfiles additionally requireunicorn/prefer-moduleandunicorn/prefer-node-protocol(import path from 'node:path', not'path'). Tests, fixtures, andvitest.config.mtsare exempt from the extraneous-deps rule.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

