-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
Description
Problem Summary
The example file API endpoint (/api/v6/components/{component}/{tab}/examples/{example}) fails in monorepo setups with the error:
ENOENT: no such file or directory, open '../react-core/src/components/Alert/examples/Alert.mdx'
This occurs when trying to retrieve example source code for components in monorepo configurations after integrating doc-core into the organization structure.
Context: Related Fixes
This is related to but NOT a duplicate of issue #118:
- Issue Monorepos are not properly supported #118 (Fixed in PR fix(cli): support monorepos #136, v1.13.1): Fixed monorepo support at the CLI level by implementing package discovery that walks up the directory tree to find
node_modulesin monorepo structures - Commit 9fd87fb (PR fix(API): address issues with text API in monorepos #185): Fixed monorepo issues in the text API endpoint by adding fallback tab handling
- Current Issue Example file API fails in monorepos #213: The examples API endpoint still uses naive path resolution and needs the same monorepo-aware treatment
Steps to Reproduce
- Set up a monorepo with doc-core
- Configure content entries pointing to packages with example files
- Access an example endpoint:
/api/v6/components/alert/react/examples/AlertDynamicLiveRegion - Observe ENOENT error when the code tries to resolve the example file path
Completion Criteria
The issue is resolved when:
- Example files are successfully resolved in monorepos: The API endpoint can locate and return example source code when running in a monorepo configuration
- Package-aware path resolution: Import paths are resolved using the content configuration's package base paths rather than naive filesystem relative paths
- Backward compatibility maintained: Non-monorepo setups continue to work without regression
- Consistent with existing fixes: The solution follows the same monorepo-handling patterns established in PR fix(cli): support monorepos #136 and PR fix(API): address issues with text API in monorepos #185
- Error handling: Clear error messages when example files genuinely don't exist vs. path resolution failures
Technical Notes
- The issue is in
src/pages/api/[version]/[section]/[page]/[tab]/examples/[example].ts:114 - Current implementation uses
resolve(contentEntryFilePath, '../', cleanFilePath)which doesn't understand monorepo package structure - The
content.tsfile already contains absolutebasepaths to packages (generated by the CLI's monorepo-aware package discovery) - Import paths in MDX files use relative paths that work in bundler context but not in raw filesystem resolution
Related Links
- Related issue: Monorepos are not properly supported #118 (Monorepos are not properly supported) - CLOSED
- Jira: PF-3601
- Fix for CLI monorepo support: PR fix(cli): support monorepos #136 (commit 33f76fb)
- Fix for text API monorepo issues: PR fix(API): address issues with text API in monorepos #185 (commit 9fd87fb)
Impact
This blocks the use of the examples API in monorepo configurations, preventing retrieval of example source code for documentation.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Needs triage