Context
PR #218 (lazy-load ES schemas per endpoint) ships a significant package-size regression as a side effect of splitting Zod schemas into 588 per-endpoint files. The memory fix stands on its own, but the size impact needs a follow-up.
Measurements (main vs PR #218)
| Metric |
Main |
After #218 |
Multiplier |
dist/ total |
23 MB |
152 MB |
6.6× |
| npm tarball (compressed) |
2.4 MB |
21.9 MB |
9.1× |
| npm package unpacked |
25.7 MB |
196.1 MB |
7.6× |
Where the bytes live in dist/ post-#218:
| File type |
Main |
After #218 |
.js |
3 MB |
35 MB |
.d.ts |
15 MB |
72 MB |
.js.map |
2 MB |
26 MB |
.d.ts.map |
1 MB |
17 MB |
Nearly all of the growth (146 of 152 MB in dist/) is dist/es/apis/schemas/: 588 per-endpoint files, each with its transitive type closure inlined and compiled once per file. Source maps and declaration maps balloon disproportionately because Zod's generic types expand into detail.
Mitigation options
| Strategy |
Unpacked |
Complexity |
Current (ships src/ + full dist/) |
196 MB |
baseline |
Drop src/ from files[] |
152 MB |
one line |
Also drop *.map files |
108 MB |
.npmignore / files glob |
Also drop *.d.ts* under dist/es/apis/schemas/ |
~40 MB |
postbuild rm. No public-API loss — schemas carry @ts-nocheck so their external types are already any |
Drop all .d.ts* from dist/ |
~36 MB |
loses public-API types for non-schema code |
Proposed implementation (40 MB target)
- Remove
src/ from files[] in the root package.json.
- Add a postbuild step that strips schema artefacts that no consumer should rely on:
rm dist/es/apis/schemas/*.d.ts dist/es/apis/schemas/*.d.ts.map dist/es/apis/schemas/*.js.map
- Result: 196 MB → ~40 MB unpacked, 21.9 MB → ~5 MB tarball.
The 40 MB target preserves all public-API types. Stripping dist/es/apis/schemas/*.d.ts* is safe because those files already carry @ts-nocheck — consumers cannot meaningfully introspect their types anyway.
The remaining ~15 MB over the pre-#218 baseline is genuine new content (294 inlined Zod closures in .js). Further compression would require upstream work in elastic/elastic-client-generator-js#164 (ajv-standalone output).
Checklist
Refs: #218
Context
PR #218 (lazy-load ES schemas per endpoint) ships a significant package-size regression as a side effect of splitting Zod schemas into 588 per-endpoint files. The memory fix stands on its own, but the size impact needs a follow-up.
Measurements (main vs PR #218)
dist/totalWhere the bytes live in
dist/post-#218:.js.d.ts.js.map.d.ts.mapNearly all of the growth (146 of 152 MB in
dist/) isdist/es/apis/schemas/: 588 per-endpoint files, each with its transitive type closure inlined and compiled once per file. Source maps and declaration maps balloon disproportionately because Zod's generic types expand into detail.Mitigation options
src/+ fulldist/)src/fromfiles[]*.mapfiles.npmignore/filesglob*.d.ts*underdist/es/apis/schemas/rm. No public-API loss — schemas carry@ts-nocheckso their external types are alreadyany.d.ts*fromdist/Proposed implementation (40 MB target)
src/fromfiles[]in the rootpackage.json.The 40 MB target preserves all public-API types. Stripping
dist/es/apis/schemas/*.d.ts*is safe because those files already carry@ts-nocheck— consumers cannot meaningfully introspect their types anyway.The remaining ~15 MB over the pre-#218 baseline is genuine new content (294 inlined Zod closures in
.js). Further compression would require upstream work in elastic/elastic-client-generator-js#164 (ajv-standalone output).Checklist
src/fromfiles[]inpackage.jsondist/es/apis/schemas/*.d.ts,*.d.ts.map,*.js.mapnpm viewtooling, and GitHub Dependency Graph are unaffected by thefiles[]changenpm pack --dry-runshows expected tarball sizeRefs: #218