From b1099f3ca661caa9e3727099912556e0db00d0d4 Mon Sep 17 00:00:00 2001 From: jdalton Date: Sun, 19 Apr 2026 12:23:59 -0400 Subject: [PATCH] perf(build): expand lib stub pattern to cover unused transitive externals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- .config/esbuild.config.mts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.config/esbuild.config.mts b/.config/esbuild.config.mts index fcb578fb..96b5286c 100644 --- a/.config/esbuild.config.mts +++ b/.config/esbuild.config.mts @@ -241,8 +241,21 @@ function createNodeProtocolPlugin() { * minimal lookup covering just those types. */ function createLibStubPlugin() { + // Heavy lib modules that are eagerly required but never exercised + // by the SDK's actual code paths. + // + // Never-reached by SDK gateway modules: + // - globs.js / sorts.js → only used by fs helpers the SDK skips + // - external/npm-pack.js / pico-pack.js → Arborist/pacote/fast-glob, + // SDK only needs validateFiles() from fs + // + // Never-reached transitive external shims: + // - external/cacache.js → destructures from npm-pack (already stubbed), + // SDK's cache-with-ttl path degrades gracefully + // - external/del.js → pulled in by fs's lazy getDel() for safeDelete, + // SDK never calls safeDelete/safeDeleteSync const libStubPattern = - /@socketsecurity\/lib\/dist\/(globs|sorts|external\/(npm-pack|pico-pack))\.js$/ + /@socketsecurity\/lib\/dist\/(globs|sorts|external\/(npm-pack|pico-pack|cacache|del))\.js$/ const mimeDbPattern = /mime-db\/db\.json$/