Skip to content

Shrink published package size - #924

Merged
theoephraim merged 5 commits into
mainfrom
shrink-published-bundle
Jul 24, 2026
Merged

Shrink published package size#924
theoephraim merged 5 commits into
mainfrom
shrink-published-bundle

Conversation

@theoephraim

@theoephraim theoephraim commented Jul 21, 2026

Copy link
Copy Markdown
Member

Reduces the varlock npm package size, which grew notably in 1.12 with the proxy work, and adds CI so future creep is visible.

Size changes

Rebuild the proxy cert authority on low-level asn1 packages. cert-authority.ts now builds X.509 certs directly from @peculiar/asn1-x509 / -schema / -ecc plus native WebCrypto, instead of the @peculiar/x509 prebundle. That prebundle inlined tsyringe + reflect-metadata and couldn't be tree-shaken, shipping as a ~436KB JS chunk plus a ~992KB sourcemap. The public API is unchanged (only the internal EphemeralCa shape changed, and no external consumer used the removed field). @peculiar/x509 is kept as a test-only devDependency to independently verify the DER we emit, plus a new test that runs a minted DNS-host leaf through Node's real TLS hostname verification.

Strip third-party source text from release sourcemaps. A post-build step nulls out sourcesContent for node_modules sources while keeping all mappings (frames still resolve) and keeping our own source embedded (varlock's code stays debuggable). Release builds only; local/dev keep full maps.

Import only the semver functions we use. Switched the three call sites (plugin version matching + bun version check) from import semver from 'semver' to subpath imports. Same node-semver, identical range semantics, tree-shakes the rest. ~24KB off the startup path.

Together these cut the release dist/ from ~6.6MB to ~5.1MB.

Bundle-size reporting (new)

So this doesn't silently regress again:

  • scripts/report-bundle-size.ts measures a built dist/ (total / JS / sourcemaps / type defs) and renders a delta table vs a baseline. Runnable locally via bun run bundle-size.
  • Bundle size check (unprivileged, pull_request): builds varlock in release mode and compares against a baseline, the base branch on normal PRs, or the last published release on the bumpy version PR, writes the report to the job summary, and uploads it as an artifact.
  • Bundle size comment (privileged, workflow_run): posts/updates a sticky comment from that artifact. Mirrors the existing fork-safe Bumpy check->comment split (never runs PR code, resolves the PR from the trusted event, treats the artifact body as text only).

Note: the normal-PR path rebuilds the base branch to get an exact per-PR delta, so it adds a build on varlock-touching PRs (path-filtered). Can be cached later if it drags.

Build the proxy cert authority from the low-level @peculiar/asn1-*
packages plus WebCrypto instead of the @peculiar/x509 prebundle, which
inlined tsyringe + reflect-metadata and couldn't be tree-shaken. Drops
~264KB of bundled JS and its ~992KB vendor sourcemap. @peculiar/x509 is
kept as a test-only devDependency to independently verify the certs we
emit; added a test that runs a minted DNS-host leaf through Node TLS
hostname verification.

Also strip embedded third-party source text from release sourcemaps
(node_modules sourcesContent), keeping mappings intact so frames still
resolve and keeping our own source embedded. Runs on release builds
only; local/dev builds keep full maps.

Together these cut the release dist payload from ~6.6MB to ~5.1MB.
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

bumpy-frog

The changes in this PR will be included in the next version bump.

patch Patch releases

  • varlock 1.13.0 → 1.13.1

Bump files in this PR

Click here if you want to add another bump file to this PR


This comment is maintained by bumpy.

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/varlock@924

commit: 85b7b7d

Switch the three semver call sites (plugin version matching + bun version
check) from the default `import semver from 'semver'` to subpath imports
(semver/functions/valid, ranges/valid, functions/satisfies, functions/gte).
Same node-semver, identical range semantics, but lets the bundler tree-shake
away the unused functions. Trims ~24KB from the startup path.
A measurement script (scripts/report-bundle-size.ts) plus two workflows that
surface how a change moves varlock's published dist, so size creep like 1.12's
gets caught at review time instead of after release.

- report-bundle-size.ts: measures a built dist/ (total / JS / sourcemaps / type
  defs), emits markdown or JSON, and renders a delta table against a baseline.
  Also wired as a local `bun run bundle-size`.
- bundle-size-check.yaml (unprivileged, pull_request): builds varlock in release
  mode, compares against a baseline (the base branch for normal PRs; the last
  published release for the bumpy version PR), writes the report to the job
  summary, and uploads it as an artifact.
- bundle-size-comment.yaml (privileged, workflow_run): posts/updates a sticky
  PR comment from that artifact. Mirrors the fork-safe Bumpy check->comment
  split: never runs PR code, resolves the target PR from the trusted event, and
  treats the artifact body as text only.
@theoephraim
theoephraim merged commit d1ea2c7 into main Jul 24, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant