Skip to content

Packages: Fix the published dependency surface of npm packages#79095

Open
manzoorwanijk wants to merge 2 commits into
trunkfrom
fix/declare-missing-published-deps
Open

Packages: Fix the published dependency surface of npm packages#79095
manzoorwanijk wants to merge 2 commits into
trunkfrom
fix/declare-missing-published-deps

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Member

What?

Follow up to #78882 (discussion).

Fixes every remaining case where a package's published artifact — its runtime JS or emitted build-types/*.d.ts — references a module that consumers installing from npm cannot resolve, as surfaced by auditing all packages with @mawesome/dependency-audit (wired into the repo as npm run lint:published-deps in #79094, so regressions are caught going forward).

Why?

#78882 declared @types/react where packages' emitted declarations reference React types, but a full audit of the published artifacts showed more gaps, and one placement issue in #78882 itself:

  • @types/react as a hard dependency while react is a peer is the wrong placement. When react is supplied by the consumer, the React type version must match the consumer's React too. A hard dependency drags in our own copy, which can collide with the consumer's @types/react (two structurally-incompatible JSX namespaces) and defeats the decoupling that made react a peer in the first place. The type surface should mirror the runtime surface: an optional peerDependency (optional so pure-JS consumers see no install warning). This is the established pattern in the React ecosystem.
  • Some packages import react/jsx-runtime at runtime without declaring react at all.
  • Some packages reference modules in their published files that resolve today only via root hoisting or a workspace link — the exact bug class of Fix missing dependencies for packages #74310 and components: Fix generated TS types referencing unavailable csstype #74655.
  • @wordpress/data leaked rememo's types into six consumers' declarations. createSelector was a bare re-export, so consumers' inferred selector types were emitted as ... & import("rememo").EnhancedSelector in their .d.ts, and they do not declare rememo. With skipLibCheck: true those exports silently degrade to any for npm consumers.

How?

  • @types/react moves from dependencies to an optional peerDependency in the 38 packages where react is a peer (or where only the types are referenced). @wordpress/element keeps it as a dependency since it depends on react directly.
  • react (^18.0.0) is added as a peer to the four packages that import react/jsx-runtime at runtime but never declared it: connectors, content-types, lazy-editor, react-i18n.
  • Genuinely missing dependencies are declared: @ariakit/react-core (components), redux (editor), @preact/signals-core (interactivity), rimraf (scripts); storybook moves from dev to prod dependencies in design-system-mcp (its emitted types reference it).
  • @wordpress/theme declares its bundler plugins' host tools — postcss, esbuild, vite — as optional peers, following its existing stylelint plugin pattern.
  • @wordpress/data now owns the createSelector types: create-selector.ts declares EnhancedSelector/GetDependants and annotates the export explicitly (same runtime function, zero behavior change), so consumers' emitted declarations reference import("@wordpress/data") instead of rememo. The two types are re-exported from the package index because TypeScript requires the type to be nameable through the package's public entry to emit a portable reference (TS2883 otherwise).

No runtime changes anywhere; npm run build type-checks clean and the regenerated packages/data/README.md API docs are included.

Testing Instructions

  1. npm ci
  2. npm run build — confirm the build and type checks pass.
  3. grep -r 'import("rememo")' packages/*/build-types/ — confirm zero hits (on trunk, 6 packages emit such references).
  4. Optionally audit any package's published surface: npx @mawesome/dependency-audit packages/<name>.

Testing Instructions for Keyboard

N/A — dependency declaration and type-only changes, no UI.

Screenshots or screencast

N/A.

Use of AI Tools

Used Claude Code (with the dependency-audit tool) to identify the affected packages, apply the dependency moves, and validate the results; the Codex CLI reviewed the createSelector type-ownership approach. The diff was reviewed before submission.

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

2 similar comments
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added [Package] Data /packages/data [Package] Server Side Render /packages/server-side-render [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] Viewport /packages/viewport [Package] Keycodes /packages/keycodes [Package] Plugins /packages/plugins [Package] Components /packages/components labels Jun 10, 2026
@github-actions github-actions Bot added [Package] Blocks /packages/blocks [Package] Editor /packages/editor [Package] Block library /packages/block-library [Package] Notices /packages/notices [Package] Rich text /packages/rich-text [Package] Block editor /packages/block-editor [Package] Primitives /packages/primitives [Package] Icons /packages/icons [Package] Keyboard Shortcuts /packages/keyboard-shortcuts [Package] React i18n /packages/reacti18n [Package] Style Engine /packages/style-engine [Package] Preferences /packages/preferences [Package] Media Utils /packages/media-utils [Package] Interactivity /packages/interactivity [Package] DataViews /packages/dataviews [Package] Fields /packages/fields [Package] Router /pacakges/router [Package] Theme /packages/theme [Package] UI /packages/ui labels Jun 10, 2026
@manzoorwanijk manzoorwanijk force-pushed the fix/declare-missing-published-deps branch 2 times, most recently from 6e586bd to 0b27173 Compare June 10, 2026 15:48
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

Size Change: +3 B (0%)

Total Size: 8.46 MB

📦 View Changed
Filename Size Change
build/scripts/data/index.min.js 9.74 kB +3 B (+0.03%)

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in 0b27173.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27288185074
📝 Reported issues:

Declare every module that packages' published artifacts (runtime JS and
emitted .d.ts) reference but did not declare, and stop leaking rememo's
types into consumers' declarations:

- Move @types/react from dependencies to an optional peerDependency in the
  38 packages where react itself is a peer (or types-only), so the consumer's
  React type version is always used and pure-JS consumers see no warning.
- Add the missing react peer to packages that import react/jsx-runtime at
  runtime: connectors, content-types, lazy-editor, react-i18n.
- Declare genuinely missing dependencies: @ariakit/react-core (components),
  redux (editor), @preact/signals-core (interactivity), rimraf (scripts);
  move storybook to dependencies in design-system-mcp.
- Declare bundler build tools as optional peers of theme (postcss, esbuild,
  vite), matching its existing stylelint plugin pattern.
- Own createSelector's types in @wordpress/data so consumers' emitted
  declarations reference @wordpress/data instead of rememo, which they do
  not declare.
@manzoorwanijk manzoorwanijk force-pushed the fix/declare-missing-published-deps branch from 0b27173 to 2165ab9 Compare June 11, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Block library /packages/block-library [Package] Blocks /packages/blocks [Package] Components /packages/components [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] Data /packages/data [Package] DataViews /packages/dataviews [Package] Editor /packages/editor [Package] Fields /packages/fields [Package] Icons /packages/icons [Package] Interactivity /packages/interactivity [Package] Keyboard Shortcuts /packages/keyboard-shortcuts [Package] Keycodes /packages/keycodes [Package] Media Utils /packages/media-utils [Package] Notices /packages/notices [Package] Plugins /packages/plugins [Package] Preferences /packages/preferences [Package] Primitives /packages/primitives [Package] React i18n /packages/reacti18n [Package] Rich text /packages/rich-text [Package] Router /pacakges/router [Package] Server Side Render /packages/server-side-render [Package] Style Engine /packages/style-engine [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Viewport /packages/viewport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant