-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
ReactDocgen: Try using the latest version of the original #33487
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,8 @@ import type { | |
| TypescriptOptions as TypescriptOptionsBase, | ||
| WebpackConfiguration as WebpackConfigurationBase, | ||
| } from '@storybook/core-webpack'; | ||
| import type { PluginOptions as ReactDocgenTypescriptOptions } from '@storybook/react-docgen-typescript-plugin'; | ||
|
|
||
| import type { PluginOptions as ReactDocgenTypescriptOptions } from 'react-docgen-typescript-plugin'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check if the package exists and find its type definitions
if [ -d "node_modules/react-docgen-typescript-plugin" ]; then
echo "=== Package found ==="
# Check package.json for types field
echo "=== package.json types field ==="
cat node_modules/react-docgen-typescript-plugin/package.json | jq -r '.types // .main // "No types field"'
# Try to find type definition files
echo "=== Looking for type definitions ==="
find node_modules/react-docgen-typescript-plugin -name "*.d.ts" -type f | head -20
# Check main entry point
echo "=== Main file ==="
cat node_modules/react-docgen-typescript-plugin/package.json | jq -r '.main'
else
echo "Package not found in node_modules"
fiRepository: storybookjs/storybook Length of output: 98 🏁 Script executed: #!/bin/bash
# If the package is found, examine its exports more closely
if [ -f "node_modules/react-docgen-typescript-plugin/index.d.ts" ]; then
echo "=== Checking index.d.ts for PluginOptions ==="
cat node_modules/react-docgen-typescript-plugin/index.d.ts | grep -A 10 -B 2 "PluginOptions" | head -50
elif [ -f "node_modules/react-docgen-typescript-plugin/lib/index.d.ts" ]; then
echo "=== Checking lib/index.d.ts for PluginOptions ==="
cat node_modules/react-docgen-typescript-plugin/lib/index.d.ts | grep -A 10 -B 2 "PluginOptions" | head -50
else
echo "=== Looking for any PluginOptions definition ==="
rg "PluginOptions" node_modules/react-docgen-typescript-plugin --type ts -A 5 | head -80
fiRepository: storybookjs/storybook Length of output: 214 🏁 Script executed: #!/bin/bash
# Also check how the import is used in the actual file
echo "=== Full content of code/presets/react-webpack/src/types.ts ==="
if [ -f "code/presets/react-webpack/src/types.ts" ]; then
cat -n code/presets/react-webpack/src/types.ts
else
echo "File not found"
fiRepository: storybookjs/storybook Length of output: 1915 🏁 Script executed: #!/bin/bash
# Check package.json files for react-docgen-typescript-plugin dependency
echo "=== Checking root package.json ==="
if [ -f "package.json" ]; then
cat package.json | jq '.dependencies | select(. != null) | keys[] | select(contains("react-docgen"))' 2>/dev/null || echo "Not found in dependencies"
cat package.json | jq '.devDependencies | select(. != null) | keys[] | select(contains("react-docgen"))' 2>/dev/null || echo "Not found in devDependencies"
fi
echo -e "\n=== Checking workspace package.json files ==="
find . -name "package.json" -type f -path "*/presets/react*" | xargs grep -l "react-docgen-typescript-plugin" 2>/dev/null | head -10Repository: storybookjs/storybook Length of output: 188 🏁 Script executed: #!/bin/bash
# Search for all references to react-docgen-typescript-plugin in the codebase
echo "=== References to react-docgen-typescript-plugin in source code ==="
rg "react-docgen-typescript-plugin" --type ts --type tsx --type js --type json -A 2 -B 2 | head -100Repository: storybookjs/storybook Length of output: 177 🏁 Script executed: #!/bin/bash
# Check if the package exists on npm (via web search in code/types/npm info)
# Also check tsconfig.json for skipLibCheck settings that might affect this
echo "=== Looking for tsconfig.json in the project ==="
find code/presets/react-webpack -name "tsconfig.json" -o -name "tsconfig*.json" | xargs cat 2>/dev/nullRepository: storybookjs/storybook Length of output: 204 🏁 Script executed: #!/bin/bash
# Check the react-webpack preset package.json
echo "=== code/presets/react-webpack/package.json ==="
cat code/presets/react-webpack/package.jsonRepository: storybookjs/storybook Length of output: 2010 🏁 Script executed: #!/bin/bash
# Search for react-docgen-typescript-plugin with better file type handling
echo "=== All references to react-docgen-typescript-plugin ==="
rg "react-docgen-typescript-plugin" --type-list | head -5
rg "react-docgen-typescript-plugin" -A 2 -B 2 | head -150Repository: storybookjs/storybook Length of output: 10706 🏁 Script executed: #!/bin/bash
# Check if there's a types package or declaration file
echo "=== Looking for type declaration files ==="
find . -name "*.d.ts" -type f -exec grep -l "react-docgen-typescript-plugin" {} \;
echo -e "\n=== Checking all src files in react-webpack preset ==="
ls -la code/presets/react-webpack/src/Repository: storybookjs/storybook Length of output: 817 🌐 Web query:
💡 Result: Short answer: react-docgen-typescript-plugin@1.0.8 does not publish a named TypeScript type called PluginOptions — the package exposes a default class (ReactDocgenTypescriptPlugin) that accepts an options object (documented in the README), but no exported PluginOptions type is present in the published package. [1][2] Sources:
🏁 Script executed: #!/bin/bash
# Check how the package is imported and used in the test file
echo "=== framework-preset-react-docs.test.ts ==="
cat code/presets/react-webpack/src/framework-preset-react-docs.test.tsRepository: storybookjs/storybook Length of output: 4409 🏁 Script executed: #!/bin/bash
# Check how the package is used in create-react-app preset to verify consistency
echo "=== create-react-app types.ts for comparison ==="
cat code/presets/create-react-app/src/types.ts | head -40Repository: storybookjs/storybook Length of output: 900 Remove the incorrect type import — The import statement at line 7 references a type that does not exist in the upstream package. You must define a local type or infer the correct options interface from the plugin's documentation. The package exports a default class ( |
||
|
|
||
| export type { BuilderResult } from '@storybook/core-webpack'; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
react-docgen-typescript-plugin npm package version 1.0.8 API ReactDocgenTypeScriptPlugin💡 Result:
ReactDocgenTypeScriptPlugin (v1.0.8) — API summary
Constructor
tsconfigPath?: string | null;
compilerOptions?: object | null; // cannot be used together with tsconfigPath
docgenCollectionName?: string | null; // default: "STORYBOOK_REACT_CLASSES" (set null to disable)
setDisplayName?: boolean; // default: true
typePropName?: string; // default: "type"
exclude?: string[]; // glob[] default: []
include?: string[]; // glob[] default: ['/.tsx']
// plus any parser options supported by react-docgen-typescript
})
Usage notes
Sources: npm package readme and package docs. [1][2]
References
[1] react-docgen-typescript-plugin (npm) — README / options.
[2] react-docgen-typescript-plugin (npm.io) — Usage & options.
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 1184
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 474
🏁 Script executed:
Repository: storybookjs/storybook
Length of output: 855
🌐 Web query:
react-docgen-typescript-plugin default export import named export💡 Result:
Short answer: react-docgen-typescript (and the Storybook/Styleguidist integrations that use it) only reliably supports named exports. If you only use default exports the parser will not pick up component prop types — either add a named export for the component or use the parser helper getDefaultExportForFile in a custom componentNameResolver. [1][2]
How to fix (brief):
Sources:
🌐 Web query:
react-docgen-typescript-plugin savePropValueAsString option💡 Result:
The savePropValueAsString option (boolean) tells react-docgen-typescript to store prop defaultValue as a string instead of its raw AST/value. Enable it in the parser or plugin options:
react-docgen-typescript parse / withDefaultConfig / withCustomConfig:
const options = { savePropValueAsString: true };
const docs = docgen.withDefaultConfig(options).parse('./MyComponent.tsx'). [1]
react-docgen-typescript-plugin: pass the same option to the plugin constructor (it forwards parser options). e.g. new ReactDocgenTypescriptPlugin({ savePropValueAsString: true }). [2]
Effect: defaultValue for e.g. counter: 123 becomes defaultValue: '123' (and booleans become 'false', etc.). [1][2]
Sources:
[1] react-docgen-typescript README.
[2] react-docgen-typescript-plugin npm / README.
Fix import syntax to use default export.
The
react-docgen-typescript-pluginv1.0.8 exportsReactDocgenTypeScriptPluginas a default export, not a named export. Change line 43 from:to:
The
savePropValueAsStringoption is valid and correctly specified.🤖 Prompt for AI Agents