refactor(shared): make the argument guards tree-shakeable - #37
Merged
Conversation
`bindAsserts` built one object holding all fourteen guards and handed it back. A bundler can include or exclude that function, but it cannot take the object apart, so the destructure list in each `internal/guards.js` decided nothing about what shipped. Every package that touched the module carried all fourteen guards: jwks called three and shipped fourteen, and `assertBoolean` reached fifteen published packages without a single call site anywhere in the repo. Each guard is now a standalone `make…` factory taking the package's `wrap`, and each `internal/guards.js` imports the ones it calls and binds them. Named imports are something a bundler can follow, so the rest is dropped. The composer layer (`bindAsserts` / `defineGuards`) is gone — binding a guard is now one line, and the indirection bought nothing. Behaviour is unchanged: same errors, same codes, same messages, and every call site still imports the same names from its local guards module. Measured across the built bundles: otp -16.5%, jwk -18.2%, security -9.4%, jws -6.9%, crypto -6.7%, session -6.6% — about -9% over those packages together. oauth2 is unaffected because it never used this module. AGENTS.md's guard convention is rewritten to match, and now says why the import list has to track the call sites rather than leaving it as style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Independent. Internal only — no public API changes.
bindAssertsbuilt one object holding all fourteen guards and handed it back. A bundler can include or exclude that function, but it cannot take the object apart, so the destructure list in eachinternal/guards.jsdecided nothing about what shipped. Every package that touched the module carried all fourteen: jwks called three and shipped fourteen, andassertBooleanreached fifteen published packages without a single call site anywhere in the repo.Each guard is now a standalone
make…factory taking the package'swrap, and eachinternal/guards.jsimports the ones it calls:Named imports are something a bundler can follow, so the rest is dropped. The composer layer (
bindAsserts/defineGuards) is gone — binding a guard is one line now, and the indirection bought nothing.Measured across the built bundles
oauth2 is unaffected — it never used this module.
Behaviour is unchanged: same errors, same codes, same messages, and every call site still imports the same names from its local guards module.
AGENTS.md's guard convention is rewritten to match, and now says why the import list has to track the call sites rather than leaving it as style.