Skip to content

ESLint: Allow private API imports in development files of bundled packages - #85897

Merged
ntsekouras merged 5 commits into
WordPress:trunkfrom
dhananjaykuber:update/admin-ui-private-api-inline-disables
Dec 4, 2026
Merged

ntsekouras merged 5 commits into
WordPress:trunkfrom
dhananjaykuber:update/admin-ui-private-api-inline-disables

Conversation

@dhananjaykuber

@dhananjaykuber dhananjaykuber commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What?

Part of #82056

Allows private API imports in development files, such as tests and stories, of bundled packages, and moves Admin UI's lock-unlock.ts next to the stories that use it. This removes both Admin UI entries from tools/eslint/suppressions.json without inline disables.

Why?

The private API import rule for bundled packages protects against a second copy of @wordpress/private-apis in plugin bundles. Tests and stories are never bundled by plugins, so they don't need it, as proposed in #87050.

Admin UI only uses private APIs in its Storybook router decorator. Keeping lock-unlock.ts under src/stories means it's covered by the same exclusion, and shipped code can't import it without the rule flagging it.

How?

@wordpress/admin-ui stays in CORE_MODULES_USING_PRIVATE_APIS, since Storybook still opts in with it.

Testing Instructions

  1. Run npm run lint:js -- packages/admin-ui/src tools/eslint/config.mjs and confirm it passes.
  2. Add import '@wordpress/private-apis'; to a non-story file in packages/admin-ui/src and confirm npm run lint:js still reports no-restricted-imports.
  3. Run npm run storybook:dev and confirm Admin UI stories that use the router still render.

@github-actions github-actions Bot added the [Package] Admin UI /packages/admin-ui label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

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: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@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.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@ntsekouras ntsekouras left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

In #87050 @aduth proposes to exclude tests and stories from this rule. With that, with-router.tsx won't need a disable, and since only the stories use lock-unlock.ts, we could just move it under src/stories and drop the admin-ui suppressions without any disable comments.

I suggested there to extract those changes. Maybe this PR could be that separate one, with the tools/eslint/config.mjs change from #87050 and the move? @aduth what do you think?

@aduth

aduth commented Nov 20, 2026

Copy link
Copy Markdown
Member

Yes, I think your instinct here is correct @dhananjaykuber in the individual inline exceptions making sense because of how they're used in Storybook, but I'd go further to suggest that we should update the root ESLint rule as I did in #87050's 94ce5b9.

Although your pull request also surfaces an interesting related case of the lock-unlock.ts exception, which is convention for packages. We're okay with it if it's only used in tests or Storybook stories, but we don't really have any guarantees that it's used that way 🤔 Maybe the inline exception is fine enough for now in combination with the explaining comment, but it'd be nice if we could find a way that doesn't require exceptions while still providing some assurances it's only used in the places we expect (e.g. lock-unlock.ts being moved closer to the tests/stories, or inlining the actual lock/unlock call).

…kages

The private-apis restriction for bundled packages guards against a second
copy of private-apis in plugin bundles. Tests and stories are never
bundled by plugins, so they don't need it.
Only the Storybook router decorator uses the lock-unlock module, so it
now lives under src/stories, where the private api import rule doesn't
apply. This removes both admin ui entries from the eslint suppressions
without needing inline disables, and keeps shipped code from importing it.
@dhananjaykuber
dhananjaykuber force-pushed the update/admin-ui-private-api-inline-disables branch from ece535e to 49f3daf Compare December 1, 2026 07:38
@dhananjaykuber dhananjaykuber changed the title Admin UI: Replace private API lint suppressions with inline disables ESLint: Allow private API imports in development files of bundled packages Dec 1, 2026
@dhananjaykuber

Copy link
Copy Markdown
Contributor Author

Thanks @ntsekouras and @aduth. I've updated this PR to be the separate one: it brings in the tools/eslint/config.mjs change from #87050 so tests and stories are excluded from the rule, moves lock-unlock.ts under src/stories since only the stories use it, and drops the admin-ui suppressions without any inline disables. @aduth, once this lands you can drop that commit from #87050.

@ntsekouras ntsekouras added the [Type] Build Tooling Issues or PRs related to build tooling label Dec 1, 2026
@@ -1,5 +1,5 @@
import { privateApis as routePrivateApis } from '@wordpress/route';
import { unlock } from '../lock-unlock';
import { unlock } from './lock-unlock';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we also move @wordpress/private-apis to devDependencies now? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, moved @wordpress/private-apis to devDependencies and dropped it from tsconfig.build.json, since only the stories use it now.

@aduth

aduth commented Dec 2, 2026

Copy link
Copy Markdown
Member

moves lock-unlock.ts under src/stories since only the stories use it

I think this could be okay given the current usage, but it may cause some friction down the line if we decide to use it in other development files like test files, since a package can only call unlock once, and we'd need to put it somewhere "shared" that makes sense for both stories and tests to use. That's why it living in the root directory makes sense as an obvious place to "share" for an entire package. I think the change does well enough to reflect that we don't want it to be used in runtime code.

I agree with @ntsekouras comment about making it a dev dependency, but otherwise this looks like it's in good shape 👍

@dhananjaykuber

Copy link
Copy Markdown
Contributor Author

Thanks @aduth! Good point about sharing unlock between stories and tests. Since only the stories use it today I've kept it under src/stories, which the new developmentFiles ignore already covers. If tests need it later, we can move it somewhere shared then. I've also moved @wordpress/private-apis to devDependencies as suggested.

Comment thread packages/admin-ui/CHANGELOG.md Outdated

### Internal

- Move `@wordpress/private-apis` to development dependencies, since only Storybook stories use it ([#85897](https://github.com/WordPress/gutenberg/pull/85897)).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's move this under Unreleased section.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ntsekouras ntsekouras left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@ntsekouras
ntsekouras enabled auto-merge (squash) December 4, 2026 10:53
@ntsekouras
ntsekouras merged commit 7158481 into WordPress:trunk Dec 4, 2026
99 checks passed
@github-actions github-actions Bot added this to the Gutenberg 24.7 milestone Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Admin UI /packages/admin-ui [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants