From e6bf2e50c39f5d322268f61abe505b120628b0ab Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Fri, 12 Jun 2026 12:33:55 +0900 Subject: [PATCH] premium-analytics: build the ui and data packages as script modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Declare wpScriptModuleExports on the internal ui and data packages so each bundles once into a registered script module, and consumer bundles externalize the import (the same mechanism that externalizes @wordpress/* script modules) instead of bundling per-consumer copies. Per-package rationale: - ui: styled components (CSS modules) can be delivered to build contexts with no style support — the module is built from the Phase-1 transpile output, where the scss is already compiled via the style runtime. - data: its module-scope QueryClient and global-error manager become genuine page-wide singletons (shared report cache across widgets instead of one cache per consumer bundle), and widget metadata modules that import helpers like getDefaultQueryParams stop bundling the data package (TanStack Query included) per widget. Adds the link: deps for the internal packages these modules' bundles resolve (datetime, formatters) plus ui itself for future importers — the resolution mechanism documented in #49189. Notably, tsconfig paths route bundled internal imports to src regardless of package.json entry fields (esbuild honors tsconfig paths), so wpScriptModuleExports externalization is the only way to deliver an internal package's compiled build output to consumers. --- pnpm-lock.yaml | 9 +++++++++ .../premium-analytics/changelog/update-ui-script-module | 4 ++++ projects/packages/premium-analytics/package.json | 3 +++ .../premium-analytics/packages/data/package.json | 2 ++ .../packages/premium-analytics/packages/ui/package.json | 2 ++ 5 files changed, 20 insertions(+) create mode 100644 projects/packages/premium-analytics/changelog/update-ui-script-module diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecb34606e45c..4ff2e575fb95 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3877,6 +3877,15 @@ importers: '@date-fns/tz': specifier: 1.4.1 version: 1.4.1 + '@jetpack-premium-analytics/datetime': + specifier: link:packages/datetime + version: link:packages/datetime + '@jetpack-premium-analytics/formatters': + specifier: link:packages/formatters + version: link:packages/formatters + '@jetpack-premium-analytics/ui': + specifier: link:packages/ui + version: link:packages/ui '@tanstack/react-query': specifier: 5.90.8 version: 5.90.8(react@18.3.1) diff --git a/projects/packages/premium-analytics/changelog/update-ui-script-module b/projects/packages/premium-analytics/changelog/update-ui-script-module new file mode 100644 index 000000000000..11aa098e8bab --- /dev/null +++ b/projects/packages/premium-analytics/changelog/update-ui-script-module @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Build the internal ui and data packages as registered script modules (wpScriptModuleExports) so consumers externalize them instead of bundling per-consumer copies: styled ui components stay out of style-less builds, and data's QueryClient becomes a genuine page-wide singleton. diff --git a/projects/packages/premium-analytics/package.json b/projects/packages/premium-analytics/package.json index e0c33bcdeae1..002d12f6ab34 100644 --- a/projects/packages/premium-analytics/package.json +++ b/projects/packages/premium-analytics/package.json @@ -35,6 +35,9 @@ "@automattic/number-formatters": "workspace:*", "@automattic/ui": "1.0.2", "@date-fns/tz": "1.4.1", + "@jetpack-premium-analytics/datetime": "link:packages/datetime", + "@jetpack-premium-analytics/formatters": "link:packages/formatters", + "@jetpack-premium-analytics/ui": "link:packages/ui", "@tanstack/react-query": "5.90.8", "@wordpress/api-fetch": "7.48.0", "@wordpress/boot": "0.14.1", diff --git a/projects/packages/premium-analytics/packages/data/package.json b/projects/packages/premium-analytics/packages/data/package.json index b4d211f35b47..ac732cc47a35 100644 --- a/projects/packages/premium-analytics/packages/data/package.json +++ b/projects/packages/premium-analytics/packages/data/package.json @@ -4,6 +4,8 @@ "private": true, "type": "module", "main": "src/index.ts", + "module": "build-module/index.mjs", + "wpScriptModuleExports": "./build-module/index.mjs", "types": "src/index.ts", "sideEffects": false, "dependencies": { diff --git a/projects/packages/premium-analytics/packages/ui/package.json b/projects/packages/premium-analytics/packages/ui/package.json index 1a0ef18366fe..434d0b4688d1 100644 --- a/projects/packages/premium-analytics/packages/ui/package.json +++ b/projects/packages/premium-analytics/packages/ui/package.json @@ -4,6 +4,8 @@ "private": true, "type": "module", "main": "src/index.ts", + "module": "build-module/index.mjs", + "wpScriptModuleExports": "./build-module/index.mjs", "types": "src/index.ts", "sideEffects": [ "*.scss"