Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/quiet-bundle-watches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,9 @@ jobs:
turbo-token: ${{ secrets.TURBO_TOKEN }}

# No continue-on-error: an over-budget chunk fails this job, which is the gate.
# Enforcement rides on this job's exit code, not the `bundlewatch` commit status
# (which collides across packages and can be masked by a sibling's pass).
- name: Check size using bundlewatch
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
CI_BRANCH: ${{ github.ref }}
CI_BRANCH_BASE: refs/heads/main
CI_COMMIT_SHA: ${{ github.event_name == 'merge_group' && github.event.merge_group.head_sha || github.event.pull_request.head.sha }}
CI_REPO_NAME: ${{ vars.REPO_NAME }}
CI_REPO_OWNER: ${{ vars.REPO_OWNER }}
run: pnpm turbo bundlewatch $TURBO_ARGS

static-analysis:
Expand Down
8 changes: 6 additions & 2 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ In some cases, we might need to add new methods to our publicly exposed APIs tha

### Bundle size checks

CI runs [bundlewatch](https://github.com/bundlewatch/bundlewatch) against `@clerk/clerk-js` and `@clerk/ui`. It fails when a built file grows past its `maxSize` in the package's `bundlewatch.config.json`. This can happen on a PR that was previously green, for example after rebasing on `main` brings in other size increases.
CI runs [bundlewatch](https://github.com/bundlewatch/bundlewatch) against `@clerk/clerk-js`, `@clerk/ui`, and `@clerk/mosaic`. It fails when a built file grows past its `maxSize` in the package's `bundlewatch.config.json`. This can happen on a PR that was previously green, for example after rebasing on `main` brings in other size increases.

The check exists so that size growth is acknowledged, not to block it. If the growth is expected, raise the limits:

Expand All @@ -231,7 +231,11 @@ pnpm turbo build --filter=@clerk/clerk-js
pnpm --filter @clerk/clerk-js bundlewatch:fix
```

Use `@clerk/ui` in place of `@clerk/clerk-js` for the UI package. The script measures the files in `dist/`, so build first. It sets each failing file's `maxSize` to its current size plus 1KB, rounded up to the nearest KB, and prints the diff. Commit the updated `bundlewatch.config.json` and mention the bump in your PR description.
Use `@clerk/ui` or `@clerk/mosaic` in place of `@clerk/clerk-js` for the other packages. The command runs BundleWatch's `update-max-sizes --write --headroom 1KB` against the files already in `dist/`, so build first. It raises only exceeded limits to fit the largest matching file plus 1KB, rounded up to the next KB, and prints the diff. It runs locally without contacting GitHub or the BundleWatch service. Commit the updated `bundlewatch.config.json` and mention the bump in your PR description.

To preview proposed limits without writing them, run `pnpm --filter @clerk/clerk-js exec bundlewatch update-max-sizes --headroom 1KB --config bundlewatch.config.json`.

These checks use `compare: false` because CI runs on pull requests and merge queues without saving a baseline on `main`. Each package has its own status prefix (`clerk-js`, `ui`, or `mosaic`). The Bundle size job enforces the limits through its exit code and uses the `BUNDLEWATCH_GITHUB_TOKEN` secret to report results. Turbo can reuse successful checks when their inputs are unchanged; failed checks are not cached.

If the growth is larger than your change explains, investigate before bumping.

Expand Down
26 changes: 0 additions & 26 deletions packages/clerk-js/bundlewatch-fix.mjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/clerk-js/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"prefix": "clerk-js",
"compare": false,
"files": [
{ "path": "./dist/clerk.js", "maxSize": "557KB" },
{ "path": "./dist/clerk.browser.js", "maxSize": "84KB" },
Expand Down
5 changes: 2 additions & 3 deletions packages/clerk-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"build:sandbox": "pnpm --filter @clerk/ui build:umd && rspack build --config rspack.config.mjs --env production --env sandbox",
"build:stats": "rspack build --config rspack.config.mjs --env production --json=stats.json --env variant=\"clerk.browser\"",
"bundlewatch": "FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json",
"bundlewatch:fix": "node bundlewatch-fix.mjs",
"bundlewatch:fix": "bundlewatch update-max-sizes --write --headroom 1KB --config bundlewatch.config.json && git -c color.ui=always --no-pager diff -- bundlewatch.config.json",
"clean": "rimraf ./dist",
"dev": "rspack serve --config rspack.config.mjs",
"dev:origin": "rspack serve --config rspack.config.mjs --env devOrigin=http://localhost:${PORT:-4000}",
Expand Down Expand Up @@ -110,9 +110,8 @@
"@rspack/dev-server": "catalog:rspack",
"@rspack/plugin-react-refresh": "catalog:rspack",
"@types/cloudflare-turnstile": "^0.2.2",
"bundlewatch": "^0.4.2",
"bundlewatch": "^1.2.0",
"jsdom": "27.0.0",
"minimatch": "^10.2.6",
"webpack-merge": "^5.10.0"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions packages/mosaic/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"prefix": "mosaic",
"compare": false,
"files": [
{ "path": "./dist/.bundlewatch/eager/index.js", "maxSize": "28KB" },
{ "path": "./dist/.bundlewatch/total/index.js", "maxSize": "310KB" },
Expand Down
3 changes: 2 additions & 1 deletion packages/mosaic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
"build:css": "tsdown --config tsdown.css.config.mts",
"build:js": "tsdown --config tsdown.config.mts",
"bundlewatch": "node ./scripts/bundle-for-size.mjs && FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json",
"bundlewatch:fix": "node ./scripts/bundle-for-size.mjs && bundlewatch update-max-sizes --write --headroom 1KB --config bundlewatch.config.json && git -c color.ui=always --no-pager diff -- bundlewatch.config.json",
"check:bundle": "node ./scripts/check-bundle.mjs",
"check:docs-exports": "node ./scripts/check-docs-exports.mjs",
"clean": "rimraf ./dist ./dist-css",
Expand Down Expand Up @@ -537,7 +538,7 @@
"@types/react": "catalog:react",
"@types/react-dom": "catalog:react",
"axe-core": "^4.11.3",
"bundlewatch": "^0.4.2",
"bundlewatch": "^1.2.0",
"eslint-plugin-boundaries": "7.3.0",
"eslint-plugin-react-you-might-not-need-an-effect": "1.0.2",
"happy-dom": "^20.8.9",
Expand Down
26 changes: 0 additions & 26 deletions packages/ui/bundlewatch-fix.mjs

This file was deleted.

2 changes: 2 additions & 0 deletions packages/ui/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"prefix": "ui",
"compare": false,
"files": [
{ "path": "./dist/ui.browser.js", "maxSize": "45KB" },
{ "path": "./dist/ui.legacy.browser.js", "maxSize": "86KB" },
Expand Down
5 changes: 2 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"build:rsdoctor": "RSDOCTOR=true rspack build --config rspack.config.js --env production",
"build:umd": "rspack build --config rspack.config.js --env production",
"bundlewatch": "FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json",
"bundlewatch:fix": "node bundlewatch-fix.mjs",
"bundlewatch:fix": "bundlewatch update-max-sizes --write --headroom 1KB --config bundlewatch.config.json && git -c color.ui=always --no-pager diff -- bundlewatch.config.json",
"check:no-rhc": "node ../../scripts/search-for-rhc.mjs directory dist/no-rhc",
"clean": "rimraf ./dist",
"dev": "rspack serve --config rspack.config.js",
Expand Down Expand Up @@ -124,8 +124,7 @@
"@rspack/plugin-react-refresh": "catalog:rspack",
"@svgr/rollup": "^8.1.0",
"@svgr/webpack": "^6.5.1",
"bundlewatch": "^0.4.2",
"minimatch": "^10.2.5",
"bundlewatch": "^1.2.0",
"tsdown": "catalog:repo",
"webpack-merge": "^5.10.0"
},
Expand Down
Loading
Loading