feat(premium-analytics): port data package from next-woocommerce-analytics#49263
Conversation
|
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 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
0bc6f06 to
8ec819e
Compare
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. 🤷 |
c08daf2 to
2c8048b
Compare
1e32c96 to
1b2f9f3
Compare
1b2f9f3 to
9e656b7
Compare
dognose24
left a comment
There was a problem hiding this comment.
Reviewed as a package port — the bulk is the verbatim-copy commit, so I focused on the adaptations (import renames, the devtools-gate change, parent wiring) plus a spot-check of the copied source.
LGTM — clean, well-isolated port, and the commit-by-commit split + adaptation table made it easy to review. No blockers. Approving.
I left a handful of non-blocking suggestions. Most are latent issues carried verbatim from upstream that won't execute until the package is actually consumed (nothing imports it yet):
ensureCoreSettingsReady()memoizes rejections → one transient failure can wedge all subsequent route loads. This is the one I'd most encourage fixing here, or tracking for the first-consumer PR.formatGmtOffset()treatsgmt_offset === 0(UTC) as unset → falls back to the viewer's browser timezone.getProductImagesQueryKeysorts the caller's array in place during render.
And two attributable to the adaptation itself (both minor, currently moot since the package isn't bundled yet):
- the dev-only devtools gate still lazy-imports the
/productionbuild, leaving an unreachable chunk in prod bundles; - the
packages/data/**ESLint block disablesno-explicit-any/import/no-extraneous-dependenciesmore broadly than needed.
Nothing here needs to block the port. Thanks for the unusually thorough PR description!
| function formatGmtOffset( offset: number | undefined ): string { | ||
| if ( ! offset ) { | ||
| return DEFAULT_TIME_ZONE; | ||
| } |
There was a problem hiding this comment.
[suggestion] ! offset is also truthy for 0, so a site explicitly configured to UTC (empty timezone_string, gmt_offset === 0) falls through to DEFAULT_TIME_ZONE (the viewer's browser timezone) instead of +00:00. This affects both getSiteTimezone() and getSiteGmtOffset(). Prefer an explicit nullish check:
if ( offset == null ) {
return DEFAULT_TIME_ZONE;
}Upstream-carried; low frequency but produces shifted date ranges for UTC stores. Non-blocking.
…e-data-package-into-analytics # Conflicts: # pnpm-lock.yaml # projects/packages/premium-analytics/package.json
|
Thanks for the review! @dognose24 The UTC gmt_offset guard and the ESLint scoping I'll carry on the first-consumer follow-up. |
kangzj
left a comment
There was a problem hiding this comment.
Reviewed the migration/adaptation layer only (not the verbatim copy in cf0cc34). The port is clean — specifier rename and text-domain switch are complete and consistent, no leftover next-woo-analytics/admin-toolkit/react-router references, and the devtools decoupling is correct (gating lazy() on NODE_ENV drops the chunk from prod builds entirely). Two non-blocking suggestions inline.
| "@wordpress/api-fetch": "7.46.0", | ||
| "@wordpress/core-data": "7.46.0", | ||
| "@wordpress/data": "10.46.0", | ||
| "@wordpress/i18n": "^6.9.0", | ||
| "@wordpress/url": "4.46.0", |
There was a problem hiding this comment.
[suggestion] Leaf↔parent WordPress version drift. These pin @wordpress/api-fetch/core-data/data/url at 7.46.0/10.46.0/4.46.0, but the parent package.json (after the trunk rebase) resolves all of them at 7.48.0/10.48.0/4.48.0.
Harmless today since this leaf isn't a pnpm workspace member — the parent's deps are the load-bearing ones, as the PR notes. But it's misleading, and it becomes a real conflict the moment the first-consumer PR wires the leaf in with link:. Worth aligning these pins to the parent's .48 versions now.
| 'jsdoc/require-returns': 'off', | ||
| 'jsdoc/check-indentation': 'off', | ||
| '@typescript-eslint/no-explicit-any': 'off', | ||
| 'import/no-extraneous-dependencies': 'off', |
There was a problem hiding this comment.
[suggestion] Disabling import/no-extraneous-dependencies for the whole packages/data/** block silences more than the react false-positive the comment describes — it also masks any genuinely undeclared dependency in the ported code. Since this override is already documented as temporary, consider narrowing it (scope the off-rule to the specific files that trip the false-positive, or leave a TODO to re-enable once the leaf manifest becomes load-bearing) so a real missing dep can't slip through unnoticed.
There was a problem hiding this comment.
Added a TODO to re-enable. Full narrowing stays with the JSDoc/leaf-deps follow-up.
kangzj
left a comment
There was a problem hiding this comment.
Approving — the migration is clean and the two inline notes are non-blocking suggestions that can be addressed in this PR or a follow-up. Scoped my review to the adaptation layer (specifier rename, text-domain switch, devtools decoupling, parent wiring); the verbatim copy was not re-reviewed.
Proposed changes
Second leaf in M2 — Shared Packages Integration: port
@next-woo-analytics/datainto@automattic/jetpack-premium-analyticsas an internal package, stacked on the datetime port (#49221). Provides the analytics data layer — React Query report hooks, REST fetchers, query keys, response processing/normalization, prefetching, and the global query-client/error providers consumed by analytics widgets.Stacked on #49221 (WOOA7S-1312), which it consumes: every date/preset helper in this package now imports from the already-integrated
@jetpack-premium-analytics/datetime.Commits
Reviewed most easily commit-by-commit — the verbatim copy is isolated first, so every later diff shows exactly what the monorepo port changed.
cf0cc3460acf58d7c7cee48b30f4d5d472a680b99e656b7cd2Monorepo adaptations
name: @next-woo-analytics/dataname: @automattic/jetpack-premium-analytics-dataREADME.md): the import specifier (@jetpack-premium-analytics/data) comes fromwpPlugin.packageNamespace; thename:field is separate and uses the@automattic/...formimport … from '@next-woo-analytics/datetime'… from '@jetpack-premium-analytics/datetime'import type { FilterCondition } from '@next-woo-analytics/data'(self-import)../../types/filter-conditionimport { useExperiments } from '@automattic/admin-toolkit'(gates devtools)process.env.NODE_ENV !== 'production'admin-toolkitdependency; devtools stay lazy + Suspense-gated, rendered in dev builds only (no experiments system exists here)"wpModule": true@wordpress/buildequivalent iswpScriptModuleExports, deferred to the first-consumer PR@tanstack/react-routerindependencies*version specs@tanstack/react-query 5.90.8,@wordpress/api-fetch 7.46.0,@wordpress/url 4.46.0,@wordpress/core-data 7.46.0,@tanstack/react-query-devtools 5.90.2)my-jetpacketc.)'woocommerce-analytics'text domain'jetpack-premium-analytics'tsconfig.jsonincludes: [packages/**/*]and supplies the@jetpack-premium-analytics/*path alias; mirrorspackages/datetime/Parent-level wiring (
projects/packages/premium-analytics/):package.json: adds the real deps (@tanstack/react-query,@wordpress/api-fetch,@wordpress/core-data,@wordpress/url;date-fns/@date-fns/tz/@wordpress/data/@wordpress/i18nalready present) plus@tanstack/react-query-devtools(dev). The leaf isn't a pnpm workspace member (the root glob doesn't reach two levels in), so the parent's deps are the load-bearing ones. Nolink:dependency is added yet — nothing importsdata(same as datetime); the first consumer will add it.eslint.config.mjs(temporary): apackages/data/**-only block softens the JSDoc rules to land the port with upstream's JSDoc style, keeps upstream's intentionalas anygeneric-TDataescapes, and silences thereactextraneous-dependency false positive. The existingpackages/datetime/**block from feat(premium-analytics): port datetime package from next-woocommerce-analytics #49221 is untouched.tests/jest.config.cjs(extendsjetpack-js-tools/jest/config.base.js, maps@jetpack-premium-analytics/*to source), ababel.config.cjs(Jetpack webpack babel preset, for the test transform), atestscript, and@types/jest/jest/@automattic/jetpack-webpack-configdev deps — so the ported tests run and the test globals typecheck.What's intentionally not here
wpScriptModuleExportsyet — upstream's"wpModule": true(builddataas a standalone WP script module shared across routes) maps towpScriptModuleExportsin this repo's@wordpress/build. Adding it today breakspnpm build: bundling the module hits the@jetpack-premium-analytics/datetimeimports, and the externals plugin resolves them with plain Node resolution, which can't see the tsconfig-only alias (the leaf packages aren't pnpm workspace members). Verified working locally with the alias made resolvable, so it's deferred to the first-consumer PR together with thelink:wiring below.@automattic/admin-toolkit/ experiments dependency — replaced by the dev-builds-only devtools gate described above.@tanstack/react-router— unused upstream.link:dependency on the parent —dataisn't imported anywhere yet, so wiring it into the build is deferred to the first consumer (mirrors datetime). This also avoids theeslint-plugin-package-jsonlink:conflict feat(premium-analytics): port datetime package from next-woocommerce-analytics #49221 flagged.jsdoc/*rules are disabled forpackages/data/**only; writing real docs is deferred and tracked by the temporaryeslint.config.mjscomments.Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires Node 24 (repo
engineStrict).Optional — build
dataas a WP script module (confirms the upstreamwpModule: truebehavior carries over once the alias resolves):projects/packages/premium-analytics/packages/data/package.json:"module": "build-module/index.mjs"and"wpScriptModuleExports": "./build-module/index.mjs".mkdir -p node_modules/@jetpack-premium-analytics && ln -s ../../packages/datetime node_modules/@jetpack-premium-analytics/datetime(from the package root).pnpm build→ emitsbuild/modules/data/and registers@jetpack-premium-analytics/datainbuild/modules/registry.php.