Skip to content

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

Merged
manzoorwanijk merged 1 commit into
trunkfrom
fix/declare-missing-published-deps
Jun 15, 2026
Merged

Packages: Fix the published dependency surface of npm packages#79095
manzoorwanijk merged 1 commit into
trunkfrom
fix/declare-missing-published-deps

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Jun 10, 2026

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.

1 similar comment
@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

github-actions Bot commented Jun 10, 2026

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>
Co-authored-by: aduth <aduth@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 [Package] Blocks /packages/blocks labels Jun 10, 2026
@github-actions github-actions Bot added [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.58 MB

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

compressed-size-action

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

Flaky tests detected in fd1f7ad.
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/27562091144
📝 Reported issues:

@manzoorwanijk manzoorwanijk force-pushed the fix/declare-missing-published-deps branch 2 times, most recently from 2165ab9 to 9df9a7f Compare June 11, 2026 10:51
@aduth

aduth commented Jun 11, 2026

Copy link
Copy Markdown
Member
  • Some packages import react/jsx-runtime at runtime without declaring react at all.

Maybe we don't care anymore because we'd want to move away from @wordpress/element as an abstraction in favor of React directly, but this feels like it's a leakiness in the abstraction that react as a direct dependency makes its way into built outputs, instead of @wordpress/element.

Comment thread packages/design-system-mcp/package.json Outdated
@manzoorwanijk manzoorwanijk force-pushed the fix/declare-missing-published-deps branch 2 times, most recently from 1408d49 to b0d75df Compare June 13, 2026 05:57
@manzoorwanijk manzoorwanijk requested a review from aduth June 13, 2026 06:01
@manzoorwanijk manzoorwanijk added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 13, 2026
@manzoorwanijk manzoorwanijk force-pushed the fix/declare-missing-published-deps branch from b0d75df to f8e8f8f Compare June 15, 2026 13:59
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 f8e8f8f to fd1f7ad Compare June 15, 2026 16:51

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments, but generally LGTM 👍

"react-refresh": "^0.14.0",
"read-pkg-up": "^7.0.1",
"resolve-bin": "^0.4.0",
"rimraf": "^5.0.10",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a devDependencies? I only see it used in test files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that test directory gets published to npm, which we should probably avoid. I will do that as a follow-up.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #79204

"esbuild-esm-loader": "^0.3.3",
"storybook": "^10.2.8"
"storybook": "^10.2.8",
"stylelint": "^16.8.2"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea with making this a devDependency as well as an optional peer dependency to make sure that it's available in Gutenberg itself for type-checking?

Should that also apply to everything else we're defining as an optional peer dependency ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if you declare a dependency as peer and you also consume it in the package itself, then dev dependency is what works locally and peer for consumers.

@manzoorwanijk manzoorwanijk merged commit 3b19cea into trunk Jun 15, 2026
47 of 50 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/declare-missing-published-deps branch June 15, 2026 17:32
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 15, 2026
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 [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants