feat(premium-analytics): port datetime package from next-woocommerce-analytics#49221
Conversation
…analytics Near-verbatim copy of next-woocommerce-analytics/packages/datetime/. Provides timezone-aware date helpers (date-fns + @date-fns/tz) and date-range presets used by analytics widgets. Monorepo adaptations: - Rename to @automattic/jetpack-premium-analytics-datetime per the internal-packages convention (parent README, "Internal packages"). - Pin date-fns 4.1.0 and @date-fns/tz 1.4.1 instead of upstream "*"; add @wordpress/i18n ^6.9.0 to match parent. - Drop the leaf tsconfig.json — parent already includes packages/**/* and packages/init has no leaf tsconfig either. - Replace `any[]` with `unknown[]` in GrowTuple constraint (tz.ts). - Add date-fns + @date-fns/tz to parent package.json so imports resolve from premium-analytics/node_modules (packages/datetime is not a pnpm workspace member, only the parent is). - ESLint text-domain autofix swept `woocommerce-analytics` → `jetpack-premium-analytics` in preset labels. - New eslint.config.mjs softens JSDoc rules for packages/datetime/** to keep upstream re-syncs mechanical (mirrors activity-log's DateRangePicker precedent). Refs WOOA7S-1312
|
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! |
…context - Title matches the import specifier consumers actually type. - Description swaps WooCommerce Analytics → Jetpack Premium Analytics. - Notes it's an internal (non-published) package and points to the parent README for the dual-naming convention. Formatter normalized list bullet spacing and one type-union wrap as a side-effect of saving the file. Refs WOOA7S-1312
Drop the upstream-path reference; note that backfilling JSDoc on the ported helpers should let us remove this whole config file. Refs WOOA7S-1312
Restores the behavior the upstream `wpModule: true` provided: emit the layout package as a standalone script module so consumers (routes, widgets) load it once via the script-module registry instead of re-bundling it into every consumer's chunk. Upstream emitted `build/packages/layout/index.js` + `index.asset.php`; in this repo the `@wordpress/build` equivalent of `wpModule: true` is `wpScript` + `wpScriptModuleExports`. Sibling `packages/init/` uses the same triple. wp-build's `dependency-graph.mjs` calls these out as the marker that distinguishes script-emitted packages from bundled ones — without them the package would be inlined into every consumer. After this change `pnpm build` emits `build/modules/layout/index.min.js` and registers it in `build/modules/registry.php` under id `@jetpack-premium-analytics/layout`, matching the upstream artifact shape. Differs from the datetime port (#49221), which intentionally has neither field because datetime is a pure utility library (`date-fns` wrappers) — upstream datetime had no `wpModule` either.
…and-typescript-for-internal-packages' into wooa7s-1312-integrate-datetime-package-into-analytics
dognose24
left a comment
There was a problem hiding this comment.
Walked through local verification (Node 24.14.0, branch tip):
pnpm typecheck— exit 0pnpm build— datetime transpiled (142ms), full build cleanpnpm exec eslint --flag v10_config_lookup_from_file --max-warnings=0 packages/datetime/— exit 0- Smoke import (
getDefaultDateRangePresets+type DateRangePresetfromroutes/dashboard/stage.tsx) — typecheck passes, the@jetpack-premium-analytics/*alias resolves end-to-end
Two small doc nits inline. Otherwise LGTM. Disclosure: downstream consumer of these presets via WOOA7S-1329 (date filters in dashboard route need exactly this).
Co-authored-by: Dognose <dognose24@users.noreply.github.com>
Co-authored-by: Dognose <dognose24@users.noreply.github.com>
Thanks @dognose24 Applied your suggestions. 🙌 |
Proposed changes
First leaf in M2 — Shared Packages Integration (WOOA7S-1312): port
@next-woo-analytics/datetimeinto@automattic/jetpack-premium-analyticsas an internal package. Provides timezone-aware date helpers (date-fns+@date-fns/tz) and date-range presets (Today, Last 7 days, Last Year, Custom, comparison ranges) consumed by analytics widgets.Chosen first because it's a true leaf — no internal deps, only
date-fns,@date-fns/tz,@wordpress/i18n. Stacked on #49189 (which sets up the@jetpack-premium-analytics/*tsconfig paths alias this work relies on).What's in the package
src/tz.tscreateTZDateFromParts,startOfDayTZ,endOfDayTZ, ISO format helpers)src/get-comparison-range.tssrc/presets/{primary,comparison,types}.tsMonorepo adaptations
name: @next-woo-analytics/datetimename: @automattic/jetpack-premium-analytics-datetimeREADME.md— the import specifier (@jetpack-premium-analytics/datetime) comes fromwpPlugin.packageNamespace; thename:field is separate and must use the@automattic/...formdate-fns: "*",@date-fns/tz: "*"date-fns: 4.1.0,@date-fns/tz: 1.4.1minimumReleaseAge: 1440which conflicts with"*"tsconfig.jsonincludes: [packages/**/*]; siblingpackages/init/has no leaf tsconfig eitherany[]inGrowTupleconstraintunknown[]@typescript-eslint/no-explicit-any'woocommerce-analytics'text domain'jetpack-premium-analytics'name(@automattic/jetpack-premium-analytics-datetime); the internal-package note was dropped (the parent README's dual-naming section was reverted in #49189)Two structural files added at the parent level:
package.json: addsdate-fnsand@date-fns/tzso the leaf's imports resolve.packages/datetime/is not a pnpm workspace member (the rootpnpm-workspace.yamlglobprojects/*/*doesn't reach in two levels), so the leaf's own dep declarations are decorative — only the parent's matter to pnpm. This mirrors howpackages/init/'s deps are declared at the parent level.eslint.config.mjs(new — temporary): softensjsdoc/require-*forpackages/datetime/**so the initial port can land with the upstream JSDoc style (/** @param value */without descriptions). The plan is to backfill proper JSDoc on the helpers in a follow-up and delete this config file entirely.What's intentionally not here
link:dep on the parent yet. The parent README documents the pattern (@jetpack-premium-analytics/datetime: link:packages/datetime), buteslint-plugin-package-json'svalid-dependenciesrule rejectslink:URLs by default. Since no route or sibling package importsdatetimeyet, the wiring isn't load-bearing — wp-build'spackages/*autodiscovery is enough for the package to exist. The first consumer PR will need to resolve the lint conflict (probably by relaxing the rule for thispackage.jsonor aligning with whatever feat(premium-analytics): resolve internal packages for build and types #49189's test plan assumed).eslint.config.mjs.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Requires Node 24 (repo
engineStrict).Optional — type/IDE resolution (confirms the tsconfig path alias works through the typechecker):
routes/dashboard/stage.tsx:pnpm typecheck— resolves and passes.Optional — build-time resolution via
link:(confirms wp-build tracks it as a module dependency):projects/packages/premium-analytics/package.jsondependencies:"@jetpack-premium-analytics/datetime": "link:packages/datetime"(thevalid-dependencieslint rejectslink:— relax it for the temp edit).routes/dashboard/stage.tsx(as above).pnpm install && pnpm build→build/routes/dashboard/content.min.asset.phplists the dependency:pnpm install.