Skip to content

Commit

Permalink
fix doc build
Browse files Browse the repository at this point in the history
  • Loading branch information
amcdnl committed May 13, 2024
1 parent 68cf30f commit e23c828
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
"prettier": "^3.2.5",
"react": "^18.0.0",
"react-docgen": "^7.0.3",
"react-docgen-typescript": "^2.2.2",
"react-dom": "^18.0.0",
"react-hook-form": "^7.51.1",
"rollup-plugin-peer-deps-external": "2.2.4",
Expand Down
51 changes: 48 additions & 3 deletions scripts/docs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { readFileSync, writeFileSync } from 'fs';
import fg from 'fast-glob';
import { resolve } from 'path';
// import { parse } from 'react-docgen-typescript';
import { parse } from 'react-docgen';
import { parse, builtinResolvers } from 'react-docgen';

const {
ChainResolver,
FindAllDefinitionsResolver,
FindAnnotatedDefinitionsResolver,
} = builtinResolvers;

const resolver = new ChainResolver(
[new FindAnnotatedDefinitionsResolver(), new FindAllDefinitionsResolver()],
{ chainingLogic: ChainResolver.Logic.ALL },
);

const defaultPlugins = [
'jsx',
'asyncDoExpressions',
'decimal',
'decorators',
'decoratorAutoAccessors',
'destructuringPrivate',
'doExpressions',
'explicitResourceManagement',
'exportDefaultFrom',
'functionBind',
'functionSent',
'importAssertions',
'importReflection',
'moduleBlocks',
'partialApplication',
['pipelineOperator', { proposal: 'minimal' }],
'recordAndTuple',
'regexpUnicodeSets',
'throwExpressions',
];

/**
* Builds the doc types.
Expand All @@ -19,7 +51,20 @@ function buildDocs() {

try {
const code = readFileSync(file, { encoding: 'utf-8' });
const documentation = parse(code, { reactDocgen: 'react-docgen' });
const documentation = parse(code, {
// Stolen from website
// https://github.com/reactjs/react-docgen/blob/main/packages/website/src/components/playground/Playground.tsx#L85
resolver,
babelOptions: {
babelrc: false,
babelrcRoots: false,
configFile: false,
filename: 'playground.js',
parserOpts: {
plugins: [...defaultPlugins, 'typescript'],
},
}
});
if (documentation) {
result.push(...documentation);
count++;
Expand Down

0 comments on commit e23c828

Please sign in to comment.