React-Docgen: Add tsconfig fallback chain and warning for monorepos#34353
Conversation
When using react-docgen-typescript in monorepos where only tsconfig.base.json or tsconfig.app.json exists in the root directory, Storybook silently failed to generate controls. - Add fallback chain: tsconfig.json → tsconfig.base.json → tsconfig.app.json - Log warning when using a fallback tsconfig - Log clear warning when no tsconfig variant is found at all - Apply consistent fallback in both Vite and Webpack paths - Add 5 tests covering all scenarios Fixes storybookjs#24585 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughSearch for TypeScript config now tries Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
code/renderers/react/src/componentManifest/utils.test.ts (1)
207-259: Consider wrappingloggerwithvi.mocked()for typed mock assertions.For consistency with mocking patterns in the codebase (e.g., manifests.test.ts), wrap the entire logger object when asserting on its methods:
expect(vi.mocked(logger).warn).not.toHaveBeenCalled()at lines 207, 242, and 259.This provides type safety and aligns with the guideline: "Use
vi.mocked()to type and access the mocked functions in Vitest tests."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@code/renderers/react/src/componentManifest/utils.test.ts` around lines 207 - 259, The tests call expect(logger.warn).not.toHaveBeenCalled() in several places; update those assertions to use Vitest's typed mock helper by wrapping the logger with vi.mocked, e.g., replace expect(logger.warn)... with expect(vi.mocked(logger).warn).not.toHaveBeenCalled() in the tests that reference logger (the ones around the findTsconfigPath tests), so all logger method assertions use vi.mocked(logger) for proper typed mocking.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@code/renderers/react/src/componentManifest/utils.test.ts`:
- Around line 191-254: The tests currently set
vi.mocked(find.up).mockImplementation inline inside individual tests; move this
mock setup into the existing beforeEach so all mock behavior follows repo Vitest
rules: create a local mapping variable (e.g. findUpMap) in the test file, set a
default mapping in beforeEach and call
vi.mocked(find.up).mockImplementation((name) => findUpMap[name]); then in each
test set/override entries on findUpMap (or assign a new map) before invoking
findTsconfigPath so tests still return the desired filenames (tsconfig.json,
tsconfig.base.json, tsconfig.app.json or undefined) and preserve assertions such
as expect(logger.warn).not.toHaveBeenCalled().
---
Nitpick comments:
In `@code/renderers/react/src/componentManifest/utils.test.ts`:
- Around line 207-259: The tests call expect(logger.warn).not.toHaveBeenCalled()
in several places; update those assertions to use Vitest's typed mock helper by
wrapping the logger with vi.mocked, e.g., replace expect(logger.warn)... with
expect(vi.mocked(logger).warn).not.toHaveBeenCalled() in the tests that
reference logger (the ones around the findTsconfigPath tests), so all logger
method assertions use vi.mocked(logger) for proper typed mocking.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4650ae5f-c8a1-4dfd-b46d-02abf259b79c
📒 Files selected for processing (1)
code/renderers/react/src/componentManifest/utils.test.ts
What this PR does
Fixes #24585
In monorepo setups (e.g., Nx, Turborepo), the root directory often has
tsconfig.base.jsoninstead oftsconfig.json. Storybook's tsconfigresolution silently failed, causing react-docgen-typescript to produce
no controls with zero warnings.
Changes
utils.ts—findTsconfigPath()now triestsconfig.json→tsconfig.base.json→tsconfig.app.jsonin order, with a warninglog when using a fallback
reactDocgenTypescript.ts— Warns when no tsconfig variant isfound, telling the user TypeScript controls won't work
react-docgen.ts/react-docgen-loader.ts— Consistentfallback chain for path alias resolution in Vite and Webpack
utils.test.ts— 5 new tests covering all scenariosHow to test
tsconfig.base.jsonin root (notsconfig.json)react-docgen-typescripttsconfig.base.jsonChecklist
Summary by CodeRabbit
Bug Fixes & Improvements
Tests