From 802a586a96222e4bc1fb458d599c9913d08bd3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dudak?= Date: Thu, 11 Apr 2024 14:06:20 +0200 Subject: [PATCH] [code-infra] Allow customizing hooks imports in API docs generator (#41828) --- packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts | 4 +++- packages/api-docs-builder/ProjectSettings.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts b/packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts index f02e5e6d9de344..2f48f39bc9d73f 100644 --- a/packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts +++ b/packages/api-docs-builder/ApiBuilders/HookApiBuilder.ts @@ -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\/.*/, @@ -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); diff --git a/packages/api-docs-builder/ProjectSettings.ts b/packages/api-docs-builder/ProjectSettings.ts index 2ba937f0a4e9b2..3ae895666b561e 100644 --- a/packages/api-docs-builder/ProjectSettings.ts +++ b/packages/api-docs-builder/ProjectSettings.ts @@ -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. */