@wordpress/theme: deduplicate addFallbackToVar helper#78666
Open
ciampo wants to merge 2 commits into
Open
Conversation
Extract the regex/replacement logic into a single generic `add-fallback-to-var.mjs` that takes the token fallback map as an argument. `ds-token-fallbacks.mjs` now becomes a thin wrapper that prebinds the package's generated fallback map, so the PostCSS, esbuild, and Vite plugins keep their existing import and behavior. Addresses task B4 from #77462.
|
Size Change: -15 kB (-0.18%) Total Size: 8.16 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in 09abf9f. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26443059759
|
24 tasks
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.
What?
Addresses task B4 from #77462 — deduplicates the
addFallbackToVarhelper that lived in bothpostcss-plugins/add-fallback-to-var.tsandpostcss-plugins/ds-token-fallbacks.mjs.Why?
The regex + replacement logic was copy-pasted across two files, with comments warning future maintainers to keep them in sync. That's exactly the kind of duplication the stabilization assessment flagged as risk-prone.
How?
packages/theme/src/postcss-plugins/add-fallback-to-var.mjsholds the single generic implementation (takes the token fallback map as a parameter, with optionalescapeQuotes). JSDoc preserves the type information that the previous.tsfile expressed inline.packages/theme/src/postcss-plugins/ds-token-fallbacks.mjsis now a thin wrapper that pre-binds the package's generated fallback map and re-exportsaddFallbackToVar. The PostCSS, esbuild, and Vite plugins keep their existing imports unchanged.add-fallback-to-var.tsis removed; its companion unit test now imports the new.mjssource.Testing Instructions
npm run test:unit -- packages/theme— all 38 tests still pass (including the 14-caseadd-fallback-to-varsuite and the 5-case preboundds-token-fallbackssuite)../postcss-plugins/postcss-ds-token-fallbacks,./esbuild-plugins/esbuild-ds-token-fallbacks, and./vite-plugins/vite-ds-token-fallbacksentry points are unchanged on disk, so external consumers see no behavior change.Checklist