Premium Analytics: author widget metadata in widget.json, not widget.ts - #50703
Conversation
widget.ts keeps icon/attributes/example; stories use the createStoryWidgetType helper
reflect widget.json metadata + createStoryWidgetType story helper
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so: 🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so: Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryThis PR did not change code coverage! That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷 |
What?
Follow-up to #50615. Moves declarative widget metadata (
name,title,help) out of each widget'swidget.tsmodule and into itswidget.jsonmanifest, across all 74 widgets.widget.tsnow carries only the non-serializable runtime fields (icon,attributes,example). Stories build their widget type from the manifest via a new sharedcreateStoryWidgetType()helper.Why?
#50615 wired the
widget.json→ PHP → REST metadata pipeline, with the dashboard merging the REST manifest over the lazily-imported module. That already madename/title/helpon the module dead weight in production, since the REST value always wins. This follow-up completes the split the pipeline enabled:widget.jsonis the single source of truth for declarative metadata, andwidget.tsholds only what cannot be serialized to JSON (a React icon element, attribute field components, example data). It also unifies how stories construct the widget type and removes ~50 ad-hocas WidgetType[...]casts.How?
widget.ts→widget.json: movedhelp(unwrapping__()) into the manifest for 71 widgets, removedname/title/helpfrom everywidget.ts, and dropped the 44 now-orphan__imports. Done with a TypeScript AST script (locate + extract + delete by text range, so formatting is preserved).widgets/stories/create-story-widget-type.ts.createStoryWidgetType( manifest, moduleDefinition )combines identity + declarative metadata (fromwidget.json) with the runtime-only fields (fromwidget.ts), centralizing the casts in one place. It mirrors the runtime REST-over-module merge, which Storybook has no REST layer to perform.widgetType={ widgetDefinition }), spread, and explicit-object patterns all collapse to a single helper call. Incidental win: stories that previously omittedhelp/attributesnow render them.AGENTS.mdandrules/widgets.mdupdated (folder contract,namebullet, pitfall, and the story template future widgets copy).Testing
pnpm run typecheck: clean.eslint(touchedts/tsx): clean.pnpm run test: 1105/1109 pass. The 4 failures (clicks/referrersdrill-down) are timeout flakes under load and pass in isolation (12/12). Those tests renderrender.tsxwith attributes and touch none of the changed code.widget.json.Follow-ups
widget.jsonstrings are emitted by wp-build as bare PHP literals in the generated manifest, which no gettext extractor picks up (unlikeblock.json, which WP-CLI extracts via a dedicatedBlockExtractor). The runtime translate pipeline added in Premium Analytics: carrywidget.jsonmetadata through the registry and REST #50615 therefore has no strings to look up. This is pre-existing (thetitle/descriptionalready inwidget.jsonwere never extracted either), but this PR widens it tohelp. The fix belongs upstream in@wordpress/build(emit translatable strings wrapped in__()with the text domain). Tracked separately.