feat(premium-analytics): port layout package from next-woocommerce-analytics#49223
Conversation
…alytics WOOA7S-1315 — M2 leaf port; no internal deps. Brings packages/layout/ over as a near-verbatim copy of upstream @next-woo-analytics/layout. Two minimum-scaffolding tweaks vs. upstream are bundled here so the repo's pre-commit lint passes: * `"private": true` on the leaf package.json (satisfies the `package-json/require-repository` and `require-attribution` lint rules without inventing a repository field for an in-tree internal package) * `eslint.config.mjs` softening `jsdoc/require-*` for `packages/layout/**` — temporary; mirrors the override PR #49221 introduced for `packages/datetime/**`. Backfill proper JSDoc and delete the override in a follow-up. Jetpack conventions (rename, dep pinning, tsconfig drop, ReactNode types) follow as separate commits.
Bring the leaf manifest in line with Jetpack/datetime conventions:
* `name` → `@automattic/jetpack-premium-analytics-layout`
(`@jetpack-premium-analytics/layout` is reserved for the import
specifier, derived from `wpPlugin.packageNamespace`; the package
`name` field must use the `@automattic/...` form — see the parent
README's "Internal packages" section)
* `version` 1.0.0 → 0.1.0 (matches sibling `packages/init` and the
datetime port)
* drop unused `@automattic/ui` and `@wordpress/components` deps —
only `Stack` from `@wordpress/ui` is imported
* pin `@wordpress/ui` to `0.13.0` — every other Jetpack package
pins concrete versions, and the repo's `minimumReleaseAge: 1440`
conflicts with `*`
* drop `wpModule` and `exports: { build/src/index.js }` (CIAB-specific
build conventions; wp-build resolves via tsconfig paths in this repo)
* add `types`, `sideEffects: false` to match datetime
The parent `tsconfig.json` already `includes: [packages/**/*]` and the leaf's own `outDir: build` is irrelevant — wp-build/tsgo never read this file. Sibling `packages/init/` and the upstream datetime port (PR #49221) likewise carry no leaf tsconfig.
Upstream relied on a global `React` namespace, which isn't in scope under
this package's tsgo config:
packages/layout/src/base/base.tsx: error TS2503: Cannot find namespace 'React'.
Switch to an explicit `import type { ReactNode } from 'react'` — the
@types/react resolution we already get via the parent's React 18 dep.
Behaviorally identical.
Declares `@wordpress/ui@0.13.0` (which exports `Stack`) on the parent manifest so the leaf's `@wordpress/ui` import resolves through pnpm. `packages/layout/` is not a pnpm workspace member (the root `pnpm-workspace.yaml` glob `projects/*/*` doesn't recurse into the leaf), so the parent's deps are what pnpm actually wires up — same pattern as the datetime port adds `date-fns` here.
Documents the only export (`BaseLayout`), its props, and the `@wordpress/ui` Stack dependency. Mirrors the README style PR #49221 introduced for the datetime port.
|
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! |
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.
|
Have you looked if Admin UI package's Page component would work for you? |
No, but I just found that this package is not actually used so we don't really need it. I'll close this PR. |
Proposed changes
Second leaf in M2 — Shared Packages Integration (WOOA7S-1315): port
@next-woo-analytics/layoutinto@automattic/jetpack-premium-analyticsas an internal package. Provides a singleBaseLayoutprimitive — a vertical@wordpress/uiStackwith a header slot above the children — used by analytics routes to keep page chrome consistent.A true leaf — no internal deps, only
@wordpress/ui. Stacked on #49189 (which sets up the@jetpack-premium-analytics/*tsconfig paths alias this work relies on). Sibling to #49221 (datetime port); the two don't touch the same files.What's in the package
src/base/base.tsxBaseLayoutcomponent —Stack gap="lg" direction="column"withheader+childrenslotssrc/base/index.ts,src/index.tsREADME.mdMonorepo adaptations
name: @next-woo-analytics/layoutname: @automattic/jetpack-premium-analytics-layoutREADME.md— the import specifier (@jetpack-premium-analytics/layout) comes fromwpPlugin.packageNamespace; thename:field is separate and must use the@automattic/...formversion: 1.0.0version: 0.1.0packages/init/@wordpress/ui: "*"@wordpress/ui: 0.13.0minimumReleaseAge: 1440which conflicts with"*"@automattic/ui: "*",@wordpress/components: "*"Stackfrom@wordpress/uiis usedwpModule: true,exports: { ./build/src/index.js }wpScript: true,module: "build-module/index.mjs",wpScriptModuleExports: "./build-module/index.mjs"wpModule: truetold CIAB's wp-build to emit a standalone script module (build/packages/layout/index.js+index.asset.php).@wordpress/build'sdependency-graph.mjsuseswpScript/wpScriptModuleExportsfor the same role; siblingpackages/init/follows the same triple. Without these the package would be inlined into every consumer instead of loaded once via the script-module registry — same as upstream behaviortsconfig.jsonincludes: [packages/**/*]; siblingpackages/init/and the datetime port carry no leaf tsconfig eitherheader: React.ReactNode(global namespace)import type { ReactNode } from 'react';header: ReactNodeReactin scope under this package's config (TS2503: Cannot find namespace 'React'); behaviorally identical@wordpress/uiStackdependency — mirrors the datetime README styleTwo structural files touched at the parent level:
package.json: adds@wordpress/ui: 0.13.0so the leaf'sStackimport resolves.packages/layout/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. Same pattern as the datetime port addsdate-fns/@date-fns/tzhere.eslint.config.mjs(new — temporary): softensjsdoc/require-*forpackages/layout/**so the initial port can land with the upstream JSDoc style. Mirrors the override feat(premium-analytics): port datetime package from next-woocommerce-analytics #49221 introduced forpackages/datetime/**. Backfill proper JSDoc onBaseLayoutand delete this config file entirely in a follow-up.What's intentionally not here
link:dep on the parent yet. The parent README documents the pattern (@jetpack-premium-analytics/layout: link:packages/layout), buteslint-plugin-package-json'svalid-dependenciesrule rejectslink:URLs by default. Since no route or sibling package importslayoutyet, 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 (same blocker the datetime port called out).eslint.config.mjs.Related product discussion/links
wpScript) while layout is a script module (wpScript: true), matching each upstream package's roleDoes this pull request change what data or activity we track or use?
No.
Testing instructions
Requires Node 24 (repo
engineStrict).Confirm the script module is registered:
Optional smoke import, to confirm the 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 the package as a module dependency once a consumer imports it):projects/packages/premium-analytics/package.jsondependencies:"@jetpack-premium-analytics/layout": "link:packages/layout"(thevalid-dependencieslint rejectslink:— relax it for the temp edit).layoutexport inroutes/dashboard/stage.tsx.pnpm install && pnpm build→build/routes/dashboard/content.min.asset.phplists the dependency undermodule_dependencies.pnpm install.