Skip to content

Build: Fix ESM declaration resolution - #82022

Merged
ciampo merged 20 commits into
trunkfrom
codex/esm-declaration-specifiers
Aug 26, 2026
Merged

Build: Fix ESM declaration resolution#82022
ciampo merged 20 commits into
trunkfrom
codex/esm-declaration-specifiers

Conversation

@ciampo

@ciampo ciampo commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Closes #80206
Supersedes #80606

What?

Fixes the published TypeScript declarations for the four ESM packages that emitted extensionless relative specifiers:

  • @wordpress/design-system-mcp
  • @wordpress/theme
  • @wordpress/video-conversion
  • @wordpress/vips

It also adds final-package validation for current and future published ESM packages.

Why?

TypeScript preserves source import specifiers in declaration output. Extensionless specifiers work with moduleResolution: "bundler", but they fail Node-style ESM resolution.

Declaration files are exempt from TypeScript's allowImportingTsExtensions restriction. A published declaration can therefore import ./types.ts, resolve it to types.d.ts under Node16 or NodeNext, and work without that flag in the consumer project.

TypeScript 4.x rejects these explicit source extensions in declaration files. This change therefore establishes TypeScript 5 as the minimum for TypeScript consumers of the four affected packages, and their changelogs classify the change as breaking.

How?

The affected production sources now use explicit .ts and .tsx relative specifiers, and their declaration-build projects enable allowImportingTsExtensions. The runtime build continues to convert these specifiers to .mjs.

After the production build, the declaration check packs each public ESM package once. For packages that publish declarations, it mirrors only the packed files into an isolated package tree and checks those declarations under NodeNext with the repository TypeScript compiler. It reuses the same archive for @arethetypeswrong/cli checks under Node16 ESM and bundler resolution. CSS-only exports are excluded because TypeScript cannot resolve CSS assets.

Testing Instructions

  1. Run npm run test:unit tools/build-scripts/test/check-esm-package-types.test.js.
  2. Run npm run typecheck.
  3. Run npm run build.
  4. Run npm run check:type-declarations.
  5. Confirm that NodeNext passes and the packed-package tables are green for Node16 ESM and bundler resolution for all four packages.

Testing Instructions for Keyboard

Not applicable. This PR does not change the UI.

Use of AI Tools

Codex was used to implement the changes, run verification, and draft this PR description.

@github-actions github-actions Bot added the [Package] Theme /packages/theme label Aug 25, 2026
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.91 MB

compressed-size-action

@ciampo ciampo self-assigned this Aug 25, 2026
@ciampo ciampo added the [Type] Build Tooling Issues or PRs related to build tooling label Aug 25, 2026
@ciampo
ciampo marked this pull request as ready for review August 25, 2026 11:03
@ciampo
ciampo requested review from a team, desrosj and manzoorwanijk as code owners August 25, 2026 11:03
@github-actions

github-actions Bot commented Aug 25, 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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: i-am-chitti <iamchitti@git.wordpress.org>

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

@ciampo
ciampo requested a review from aduth August 25, 2026 11:04
@ciampo
ciampo marked this pull request as draft August 25, 2026 11:05
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown

Flaky tests detected in 193c6bc.
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/32959355605
📝 Reported tests:

should be disabled when post is being saved in /test/e2e/specs/editor/various/publish-button.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeDisabled() failed

Locator:  getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Publish' })
Expected: disabled
Received: enabled
Timeout:  5000ms

Call log:
  - Expect "toBeDisabled" with timeout 5000ms
  - waiting for getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Publish' })
    14 × locator resolved to <button type="button" aria-disabled="false" aria-expanded="false" class="components-button editor-post-publish-panel__toggle editor-post-publish-button__button is-primary is-compact">Publish</button>
       - unexpected value "enabled"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/publish-button.spec.js:62:5

@ciampo
ciampo marked this pull request as ready for review August 25, 2026 11:56
Comment thread packages/design-system-mcp/tsconfig.build.json
Comment thread tools/build-scripts/packages/check-esm-package-types.mjs
Comment thread tools/build-scripts/packages/check-esm-package-types.mjs Outdated
Comment thread tools/build-scripts/packages/check-esm-package-types.mjs Outdated
Comment thread tools/build-scripts/packages/check-esm-package-types.mjs Outdated
Comment thread .github/workflows/static-checks.yml Outdated
@ciampo
ciampo force-pushed the codex/esm-declaration-specifiers branch from 6ef7ec7 to 8e69f72 Compare August 25, 2026 15:05
@ciampo
ciampo requested a review from manzoorwanijk August 25, 2026 15:14

@manzoorwanijk manzoorwanijk 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.

Two minor things. Looks good otherwise.

Comment thread tools/build-scripts/packages/check-esm-package-types.mjs Outdated
Comment thread tools/build-scripts/packages/check-esm-package-types.mjs Outdated
@ciampo
ciampo force-pushed the codex/esm-declaration-specifiers branch from 8e69f72 to 9431677 Compare August 26, 2026 09:05
@ciampo
ciampo requested a balanced review from Copilot August 26, 2026 09:12

This comment was marked as low quality.

@ciampo

ciampo commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@manzoorwanijk before merging, just double-checking: do we have any policies areound min supported TS version? The changes from this PR will cause errors on TS < 5 . I assumed it's fine, since latest version is 7, and version 5 was introduced in 2023 — but wanted to double-check

@manzoorwanijk

Copy link
Copy Markdown
Member

We don’t have any such policy and it should be fine.

@ciampo
ciampo enabled auto-merge (squash) August 26, 2026 11:31
@ciampo
ciampo merged commit 22e0df3 into trunk Aug 26, 2026
63 checks passed
@ciampo
ciampo deleted the codex/esm-declaration-specifiers branch August 26, 2026 11:52
@github-actions github-actions Bot added this to the Gutenberg 23.9 milestone Aug 26, 2026
@aduth

aduth commented Aug 26, 2026

Copy link
Copy Markdown
Member

If we're adding all these extensions, should we also update the package's TypeScript configs to specify "moduleResolution": "nodenext" instead of "moduleResolution": "bundler"? IIRC the primary reason for using "bundler" is for the extensionless imports. And presumably we'd want the restrictiveness to avoid extensionless imports being added in the future?

'bundler' for use with bundlers. Like node16 and nodenext, this mode supports package.json "imports" and "exports", but unlike the Node.js resolution modes, bundler never requires file extensions on relative paths in imports.

https://www.typescriptlang.org/tsconfig/#moduleResolution

@ciampo

ciampo commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Good point, opened #82088 to address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Theme /packages/theme [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Establish a shared ESM declaration strategy for WordPress packages

4 participants