feat: per-entry hooks to filter, reshape, and rewrite snapshots - #39
Merged
Merged
Conversation
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.
Closes #38
Adds three per-entry hooks to
ApiSnapshotOptions, at increasing depth of intervention:entryFilter(ctx)— skip an entry point entirely (ctx: { packageName, entryName }; returnfalseto skip). Solves the UnoCSS case of dropping low-signal data entries like./theme/./colorswhile keeping the rest of the package guarded.transformEntries(entries, ctx)— modify the internal structural representation (the extractedEntry[]of{ name, kind, text }per surface) before it is serialized: mutate in place or return a replacement array. Enables e.g. collapsing a known large object export to an opaque declaration while everything else stays guarded.transformSnapshot(ctx)— rewrite the final snapshot string (header excluded) before it is written or compared; return the new string ornull/undefinedto keep it.Because the hooks live on
ApiSnapshotOptionsand are bound through a single sharedcreateEntryHookshelper, they behave identically across every integration:snapshotApiPerEntry/describePackagesApiSnapshots(Vitest),generateApiSnapshot,snapshotPackage/snapshotFiles, and the rolldown plugin. In the Vitest integration, filtered entries are skipped at test-registration time (no danglingitblocks), and transformed content flows through the breaking-change update guard, so the guard compares what will actually be written.Also, as noted in the issue,
typeWideningandcategorizedExportswere not forwarded through the VitestSnapshotApiOptions— they now are, and theEntry/EntryKind/ hook-context types are exported from bothtsnapiandtsnapi/vitest.Covered by new core tests (
test/hooks.test.ts) and a hooked fixture in the Vitest integration test with committed snapshots.This PR was created with the help of an agent.