Skip to content

refactor(flags): extract framework-agnostic shared/ module (1/3)#412

Draft
dferber90 wants to merge 1 commit into
mainfrom
shared/extraction
Draft

refactor(flags): extract framework-agnostic shared/ module (1/3)#412
dferber90 wants to merge 1 commit into
mainfrom
shared/extraction

Conversation

@dferber90

Copy link
Copy Markdown
Collaborator

Stacked PR 1 of 3 · base: main

Both flags/next and flags/sveltekit implemented the same flag pipeline twice and had drifted. This first layer lifts the parts that are framework-agnostic (or trivially so) into src/shared/, with each framework keeping thin wrappers for its differences.

Zero public API change — the generated .d.ts for flags, flags/next and flags/sveltekit are byte-identical to main.

  • shared/seal.tssealHeaders / sealCookies / transformToHeaders (was duplicated in next/evaluate.ts and sveltekit/index.ts)
  • shared/overrides.tsreadOverrides + memoized decrypt; SvelteKit now gets the override memoization Next already had. Removes next/overrides.ts.
  • shared/precompute.tscombine / serialize / deserialize / generatePermutations + getPrecomputed core
  • shared/discovery.ts — shared authorize → 401-or-data → version-header control flow

Named shared rather than core to avoid confusion with the separate @vercel/flags-core package.

Verification

112/112 tests pass unchanged · type-check · biome · attw all green · public .d.ts diff empty · @flags-sdk/vercel still builds.

🤖 Generated with Claude Code

Both flags/next and flags/sveltekit implemented the same flag pipeline
twice and had drifted. This lifts the parts that are framework-agnostic
(or trivially so) into src/shared/, with each framework keeping thin
wrappers for its differences. Zero public API change — the generated
.d.ts for flags, flags/next and flags/sveltekit are byte-identical.

- shared/seal.ts: sealHeaders/sealCookies/transformToHeaders
  (was duplicated in next/evaluate.ts and sveltekit/index.ts)
- shared/overrides.ts: readOverrides + memoized decrypt; SvelteKit now
  gets the override memoization Next already had. Removes next/overrides.ts.
- shared/precompute.ts: combine/serialize/deserialize/generatePermutations
  + getPrecomputed core. Frameworks keep wrappers for secret defaulting
  and the getPrecomputed(flag) vs getPrecomputed(key) signatures.
- shared/discovery.ts: shared authorize -> 401-or-data -> version-header
  control flow behind createFlagsDiscoveryEndpoint.

Named "shared" rather than "core" to avoid confusion with the separate
@vercel/flags-core package.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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