Skip to content

perf(build): expand lib stub pattern to cover unused transitive externals#599

Closed
John-David Dalton (jdalton) wants to merge 1 commit intomainfrom
perf/stub-unused-lib-externals
Closed

perf(build): expand lib stub pattern to cover unused transitive externals#599
John-David Dalton (jdalton) wants to merge 1 commit intomainfrom
perf/stub-unused-lib-externals

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

Summary

  • Expand createLibStubPlugin in .config/esbuild.config.mts to additionally stub @socketsecurity/lib/dist/external/del.js and @socketsecurity/lib/dist/external/cacache.js
  • These two shims are eagerly loaded by @socketsecurity/lib/dist/fs.js (via lazy getDel()) and by @socketsecurity/lib/dist/cacache.js (destructures from already-stubbed npm-pack), but the SDK never calls safeDelete/safeDeleteSync and its cache-with-ttl path degrades gracefully

Result

dist/index.js: 712,442 → 711,934 bytes (−508 bytes)

Modest on its own; the larger win flows from upstream socket-lib 5.19.0, which adds ~14 new stubs (sigstore/tuf/arborist internals) that cascade into the SDK's bundle automatically on the next lib bump.

Test plan

  • pnpm run build succeeds, emits type declarations
  • pnpm exec vitest run shows same pass/fail counts as main (739 passing; 1 pre-existing .claude/hooks/check-new-deps failure unrelated to this change)
  • CI green

…nals

The current createLibStubPlugin already stubs socket-lib's globs.js,
sorts.js, and the npm-pack / pico-pack external bundles since none of
their code paths are exercised by the SDK's runtime.

Extend the same pattern to two more transitive externals:

- @socketsecurity/lib/dist/external/del.js — pulled in by fs.js's
  lazy getDel() for safeDelete/safeDeleteSync. The SDK only uses
  validateFiles() from fs and never deletes.
- @socketsecurity/lib/dist/external/cacache.js — destructures from
  npm-pack (already stubbed), so the eager require would already
  yield undefined. Stubbing makes the intent explicit.

Result on dist/index.js: 712,442 → 711,934 bytes (−508 bytes).
Modest gain since socket-lib's own stubs (v5.19.0 +) cascade here
automatically once the lib dep bumps.

Full vitest suite runs with same pass/fail counts as main
(739 passing; 1 pre-existing .claude/hooks failure unrelated to
this change).
@jdalton
Copy link
Copy Markdown
Contributor Author

Rolled into #596 alongside the socket-lib 5.19.0 bump — consolidating the cascade work into one PR.

@jdalton John-David Dalton (jdalton) deleted the perf/stub-unused-lib-externals branch April 21, 2026 14:40
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.

1 participant