Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Warn private API in auto-generated readmes #68317

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

mirka
Copy link
Member

@mirka mirka commented Dec 26, 2024

What?

Detects private API status from the component's Storybook file to add a warning in the auto-generated README.

Why?

Although the READMEs for private components are not published to the Block Editor Handbook, people can see the READMEs directly in the repo. And currently they don't show which components are still private.

Testing Instructions

npm run docs:components to regenerate

@mirka mirka added [Type] Developer Documentation Documentation for developers [Package] Components /packages/components labels Dec 26, 2024
@mirka mirka self-assigned this Dec 26, 2024
Copy link

Flaky tests detected in 1111d07.
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/12503252241
📝 Reported issues:

Comment on lines +32 to +36
tags.includes( 'status-private' ) && [
{
p: '🔒 This component is locked as a [private API](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-private-apis/). We do not yet recommend using this outside of the Gutenberg project.',
},
],
Copy link
Member Author

Choose a reason for hiding this comment

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

Using normal Markdown instead of a div callout, because the intended audience is not on Block Editor Handbook.

Comment on lines +6 to +7


Copy link
Member Author

Choose a reason for hiding this comment

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

Redundant newlines will be fixed in #68301.

Comment on lines +11 to +16
const meta: Meta< typeof Badge > = {
component: Badge,
title: 'Components/Containers/Badge',
id: 'components-badge',
tags: [ 'status-private' ],
} satisfies Meta< typeof Badge >;
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Normalizing this declaration to our standard format (not TS satisfies) for easier AST parsing.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this 👍 The satisfies syntax seemed to cause some issues when parsing files for component usage as well.

*/
export async function getTagsFromStorybook( filePath ) {
const fileContent = await fs.readFile( filePath, 'utf8' );
const parsedFile = babel.parse( fileContent, {
Copy link
Member Author

Choose a reason for hiding this comment

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

These bin scripts aren't set up to process TS files yet (e.g. index.story.tsx files), so we can't read data from import()ed meta objects. At the moment I think it's simpler to do a quick AST parse than set up TS transpilation just for this, but we can maybe revisit when there are more use cases.

@mirka mirka marked this pull request as ready for review December 26, 2024 11:47
@mirka mirka requested a review from a team December 26, 2024 11:47
Copy link

github-actions bot commented Dec 26, 2024

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: mirka <0mirka00@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment on lines +11 to +16
const meta: Meta< typeof Badge > = {
component: Badge,
title: 'Components/Containers/Badge',
id: 'components-badge',
tags: [ 'status-private' ],
} satisfies Meta< typeof Badge >;
};
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this 👍 The satisfies syntax seemed to cause some issues when parsing files for component usage as well.

const mainDocsJson = [
{ h1: typeDocs.displayName },
'<!-- This file is generated automatically and cannot be edited directly. Make edits via TypeScript types and TSDocs. -->',
tags.includes( 'status-private' ) && [
{
p: '🔒 This component is locked as a [private API](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-private-apis/). We do not yet recommend using this outside of the Gutenberg project.',
Copy link
Member

Choose a reason for hiding this comment

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

In an ideal world, and accoding to @jsnajdr's latest suggestions, a 3rd party developer simply should be unable to use private APIs outside of Gutenberg.

@mirka mirka merged commit 962a589 into trunk Dec 27, 2024
75 of 76 checks passed
@mirka mirka deleted the autogen-readme-private branch December 27, 2024 17:22
@github-actions github-actions bot added this to the Gutenberg 20.0 milestone Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants