Skip to content

chore: reduce npm package size by ~78%#285

Merged
margaretjgu merged 2 commits into
mainfrom
chore/reduce-package-size
May 11, 2026
Merged

chore: reduce npm package size by ~78%#285
margaretjgu merged 2 commits into
mainfrom
chore/reduce-package-size

Conversation

@margaretjgu
Copy link
Copy Markdown
Member

Closes #250.

Summary

Two targeted changes to cut the published package from 25.8 MB → 5.7 MB unpacked (2.3 MB → 0.9 MB tarball):

1. Remove src/ from files[]

The source tree was never needed at runtime — only dist/ is consumed. Removes 3.3 MB from the published package with no functional impact.

2. postbuild script: strip schema declaration artefacts

dist/es/apis/schemas/ contains 48 per-namespace files compiled into *.d.ts, *.d.ts.map, and *.js.map (~8.3 MB combined). Consumers cannot meaningfully introspect these types (they reference internal Zod generics and large transitive type closures). Stripping them has no public-API impact.

The *.js runtime files are preserved — they are imported lazily by the CLI at command execution time.

Measurements

Metric Before After Reduction
dist/ total 33 MB 15 MB −55%
npm tarball 2.3 MB 0.9 MB −61%
npm unpacked 25.8 MB 5.7 MB −78%
total files 3,710 2,884 −826 files

Implementation

The postbuild script runs automatically after every npm run build via npm's lifecycle hooks:

"postbuild": "node -e \"..strip dist/es/apis/schemas/*.d.ts *.d.ts.map *.js.map..\""

This uses only Node.js built-ins (fs, path) — no extra dev dependencies needed.

Checklist

  • Remove src/ from files[]
  • Add postbuild step to strip dist/es/apis/schemas/*.d.ts, *.d.ts.map, *.js.map
  • npm pack --dry-run shows expected tarball size (0.9 MB)
  • All tests pass

Two targeted changes to cut the published package from 25.8 MB → 5.7 MB
unpacked (2.3 MB → 0.9 MB tarball):

1. Remove `src/` from `files[]`
   The source tree was never needed at runtime; only `dist/` is. This saves
   the entire 3.3 MB source directory from the tarball.

2. Add `postbuild` script to strip schema declaration artefacts
   `dist/es/apis/schemas/` contains 48 per-namespace files each compiled
   as *.d.ts, *.d.ts.map, and *.js.map (~8.3 MB combined). Consumers
   cannot meaningfully introspect these types (they reference internal Zod
   generics), so stripping them has no public-API impact.
   The *.js runtime files are preserved — they are imported lazily by the
   CLI at command execution time.

Before / after (local build):
  dist/ total:     33 MB → 15 MB  (-55%)
  npm tarball:    2.3 MB → 0.9 MB (-61%)
  npm unpacked:  25.8 MB → 5.7 MB (-78%)
  total files:     3710  → 2884   (-826 files)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 4.81s
✅ REPOSITORY gitleaks yes no no 69.18s
✅ REPOSITORY git_diff yes no no 0.46s
✅ REPOSITORY secretlint yes no no 13.42s
✅ REPOSITORY trivy yes no no 18.24s

See detailed reports in MegaLinter artifacts
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@margaretjgu margaretjgu marked this pull request as draft May 8, 2026 14:43
@margaretjgu margaretjgu marked this pull request as ready for review May 8, 2026 14:54
@margaretjgu margaretjgu requested review from JoshMock and MattDevy May 8, 2026 17:45
Copy link
Copy Markdown
Contributor

@MattDevy MattDevy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@margaretjgu margaretjgu merged commit 1f2e9ba into main May 11, 2026
18 checks passed
@margaretjgu margaretjgu deleted the chore/reduce-package-size branch May 11, 2026 15:52
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.

chore: reduce npm package size after per-endpoint schema split

2 participants