Skip to content

[code-infra] Allow customizing hooks imports in API docs generator #41828

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

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ const extractInfoFromType = async (
* @param filename The filename where its defined (to infer the package)
* @returns an array of import command
*/
const getHookImports = (name: string, filename: string) => {
const defaultGetHookImports = (name: string, filename: string) => {
const githubPath = toGitHubPath(filename);
const rootImportPath = githubPath.replace(
/\/packages\/mui(?:-(.+?))?\/src\/.*/,
Expand Down Expand Up @@ -552,6 +552,8 @@ export default async function generateHookApi(
if (annotatedDescriptionMatch !== null) {
reactApi.description = reactApi.description.slice(0, annotatedDescriptionMatch.index).trim();
}

const { getHookImports = defaultGetHookImports } = projectSettings;
reactApi.filename = filename;
reactApi.name = name;
reactApi.imports = getHookImports(name, filename);
Expand Down
6 changes: 5 additions & 1 deletion packages/api-docs-builder/ProjectSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ export interface ProjectSettings {
*/
importTranslationPagesDirectory?: string;
/**
* Returns an array of import commands used for the API page header.
* Returns an array of import commands used for the component API page header.
*/
getComponentImports?: (name: string, filename: string) => string[];
/**
* Returns an array of import commands used for the hook API page header.
*/
getHookImports?: (name: string, filename: string) => string[];
/**
* Settings to configure props definition tests.
*/
Expand Down
Loading