Skip to content

Add recursive MDX module resolution - #21

Open
remorses wants to merge 2 commits into
mainfrom
recursive-mdx-modules
Open

Add recursive MDX module resolution#21
remorses wants to merge 2 commits into
mainfrom
recursive-mdx-modules

Conversation

@remorses

@remorses remorses commented May 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds mdxFiles support to resolveModules() so preprocessed .md and .mdx files can participate in normal MDX imports.
  • Walks nested MDX imports recursively while keeping JS/TS lazy glob imports working the same way.
  • Skips parsing imported markdown during module discovery when a cheap import-statement check shows it cannot contain nested imports.

Validation

  • pnpm test -- --run safe-mdx.test.tsx
  • pnpm build

Notes

This is the safe-mdx side of the Holocron imported Markdown simplification. Holocron can pass a preprocessed markdown registry and let safe-mdx own nested import resolution instead of generating wrapper modules per snippet.

Teach resolveModules to treat preprocessed Markdown and MDX files as first-class modules alongside lazy JavaScript imports. The resolver now walks nested MDX imports, creates module exports through a caller-provided factory, and uses a cheap import-statement regex so leaf Markdown snippets avoid an extra parse during import discovery.

This keeps recursive snippet rendering inside safe-mdx instead of forcing callers to hand-roll nested module maps. The shared modules object is intentionally captured by reference so circular or later-discovered imports remain visible when generated MDX components render.

Validation:
- pnpm test -- --run safe-mdx.test.tsx
- pnpm build

Session: ses_2bbe7a7767674a57abc0855d8b43490b

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf7ecd4744

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/parse.ts
Comment on lines +320 to +322
const file = typeof mdxFile === 'string'
? { markdown: mdxFile, baseUrl: currentBaseUrl }
: mdxFile

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve string MDX entries from their own directory

When an mdxFiles entry is provided as a plain string, its baseUrl is set to currentBaseUrl (the importer's directory) instead of the resolved file's directory. This makes nested relative imports inside that MDX resolve against the wrong path whenever the imported file lives in a subdirectory (for example importing ./sub/outer.md whose content imports ./inner.md), so recursive module discovery misses valid child modules.

Useful? React with 👍 / 👎.

Add a prepare script so branches used as temporary git dependencies build their dist files during installation. This lets downstream integration branches validate safe-mdx API changes before a release is cut.

Validation:
- pnpm build

Session: ses_2bbe7a7767674a57abc0855d8b43490b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant