Repository navigation
ESLint: Allow private API imports in development files of bundled packages - #85897
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
There was a problem hiding this comment.
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?
|
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 |
…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.
ece535e to
49f3daf
Compare
|
Thanks @ntsekouras and @aduth. I've updated this PR to be the separate one: it brings in the |
| @@ -1,5 +1,5 @@ | |||
| import { privateApis as routePrivateApis } from '@wordpress/route'; | |||
| import { unlock } from '../lock-unlock'; | |||
| import { unlock } from './lock-unlock'; | |||
There was a problem hiding this comment.
Should we also move @wordpress/private-apis to devDependencies now? 🤔
There was a problem hiding this comment.
Done, moved @wordpress/private-apis to devDependencies and dropped it from tsconfig.build.json, since only the stories use it now.
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 I agree with @ntsekouras comment about making it a dev dependency, but otherwise this looks like it's in good shape 👍 |
|
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. |
|
|
||
| ### Internal | ||
|
|
||
| - Move `@wordpress/private-apis` to development dependencies, since only Storybook stories use it ([#85897](https://github.com/WordPress/gutenberg/pull/85897)). |
There was a problem hiding this comment.
Let's move this under Unreleased section.
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.tsnext to the stories that use it. This removes both Admin UI entries fromtools/eslint/suppressions.jsonwithout inline disables.Why?
The private API import rule for bundled packages protects against a second copy of
@wordpress/private-apisin 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.tsundersrc/storiesmeans it's covered by the same exclusion, and shipped code can't import it without the rule flagging it.How?
ignores: developmentFilesto the bundled packages override intools/eslint/config.mjs, from Admin UI: Configure router Link to match exact to fix duplicate aria-current in breadcrumbs #87050.packages/admin-ui/src/lock-unlock.tstopackages/admin-ui/src/stories/lock-unlock.tsand updates the import inwith-router.tsx.suppressions.json. No other entries became prunable.@wordpress/admin-uistays inCORE_MODULES_USING_PRIVATE_APIS, since Storybook still opts in with it.Testing Instructions
npm run lint:js -- packages/admin-ui/src tools/eslint/config.mjsand confirm it passes.import '@wordpress/private-apis';to a non-story file inpackages/admin-ui/srcand confirmnpm run lint:jsstill reportsno-restricted-imports.npm run storybook:devand confirm Admin UI stories that use the router still render.