Skip to content

Commit

Permalink
Handle cases when displayName in manifest is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Oct 15, 2024
1 parent 6fbf877 commit 0623f5b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions bin/api-docs/gen-components-docs/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,29 @@ function getTypeDocsForComponent( {
componentFilePath
);

const typeDocs = docgen
.parse( resolvedPath, OPTIONS )
.find( ( obj ) => obj.displayName === displayName );
const typeDocs = docgen.parse( resolvedPath, OPTIONS );

if ( typeof typeDocs === 'undefined' ) {
if ( typeDocs.length === 0 ) {
throw new Error(
`react-docgen-typescript could not generate type docs for ${ displayName } in ${ resolvedPath }`
`react-docgen-typescript could not generate any type docs from ${ resolvedPath }`
);
}

return typeDocs;
const matchingTypeDoc = typeDocs.find(
( obj ) => obj.displayName === displayName
);

if ( typeof matchingTypeDoc === 'undefined' ) {
const unmatchedTypeDocs = typeDocs
.map( ( obj ) => `\`${ obj.displayName }\`` )
.join( ', ' );

throw new Error(
`react-docgen-typescript could not find type docs for ${ displayName } in ${ resolvedPath }. (Found ${ unmatchedTypeDocs })`
);
}

return matchingTypeDoc;
}

async function parseManifest( manifestPath ) {
Expand Down

0 comments on commit 0623f5b

Please sign in to comment.