Skip to content

chore: mark package as sideEffects: false to enable tree-shaking#160

Open
mvanhorn wants to merge 1 commit intochenglou:mainfrom
mvanhorn:chore/158-side-effects-false
Open

chore: mark package as sideEffects: false to enable tree-shaking#160
mvanhorn wants to merge 1 commit intochenglou:mainfrom
mvanhorn:chore/158-side-effects-false

Conversation

@mvanhorn
Copy link
Copy Markdown

Summary

Add "sideEffects": false to package.json so downstream bundlers can tree-shake unused exports of @chenglou/pretext.

Why this matters

Per #158, the darkroomengineering/fitbox maintainer's bundle audit shows ~129 KB of pretext modules ship to every consumer regardless of which exports they actually import:

File Size (raw)
analysis.js 37 KB
line-break.js 33 KB
generated/bidi-data.js 23 KB
layout.js 22 KB
measurement.js 8 KB
bidi.js 6 KB
Total ~129 KB raw

A consumer importing only prepareWithSegments, measureNaturalWidth, measureLineStats, layoutWithLines ships the full set today.

A scan of the published modules confirms there are no top-level side effects: let sharedWordSegmenter = null and the regex/Set initializers are pure expressions, evaluated lazily on first call. Marking the package side-effect-free is safe and lets bundlers drop unused exports based on what consumers import.

Realistic impact per #158: 20-40% bundle reduction for consumers using a subset of the API.

Changes

One line in package.json:

"sideEffects": false

Testing

  • bun run build:package — clean build
  • bun run checktsc && oxlint --type-aware src reports 0 warnings, 0 errors
  • bun test — 103 pass, 0 fail (417 expect calls)

No source code touched, no behavior change.

Fixes #158

Himaan1998Y pushed a commit to Himaan1998Y/pretext that referenced this pull request May 4, 2026
npm install from github: requires dist/ present — the prepack script
uses rm -rf (POSIX-only) and bun, so GitHub Actions/npm won't rebuild
it reliably. Pre-committing the dist built from our patched source
(PRs chenglou#160, chenglou#161, chenglou#132) ensures consumers get the correct artifact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "sideEffects": false to enable tree-shaking

1 participant