Skip to content

Example file API fails in monorepos #213

@wise-king-sullyman

Description

@wise-king-sullyman

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:

Steps to Reproduce

  1. Set up a monorepo with doc-core
  2. Configure content entries pointing to packages with example files
  3. Access an example endpoint: /api/v6/components/alert/react/examples/AlertDynamicLiveRegion
  4. Observe ENOENT error when the code tries to resolve the example file path

Completion Criteria

The issue is resolved when:

  1. Example files are successfully resolved in monorepos: The API endpoint can locate and return example source code when running in a monorepo configuration
  2. Package-aware path resolution: Import paths are resolved using the content configuration's package base paths rather than naive filesystem relative paths
  3. Backward compatibility maintained: Non-monorepo setups continue to work without regression
  4. 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
  5. 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.ts file already contains absolute base paths 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

Impact

This blocks the use of the examples API in monorepo configurations, preventing retrieval of example source code for documentation.

Metadata

Metadata

Labels

PF TeambugSomething isn't working

Type

No type

Projects

Status

Needs triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions