Skip to content

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

@MattDevy

Description

@MattDevy

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)

  1. Remove src/ from files[] in the root package.json.
  2. 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
    
  3. 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

  • Remove src/ from files[] in package.json
  • Add postbuild step to strip dist/es/apis/schemas/*.d.ts, *.d.ts.map, *.js.map
  • Verify supply-chain scanners, npm view tooling, and GitHub Dependency Graph are unaffected by the files[] change
  • Confirm npm pack --dry-run shows expected tarball size
  • Update size metrics in this issue once implemented

Refs: #218

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions