Add recursive MDX module resolution - #21
Conversation
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
There was a problem hiding this comment.
💡 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".
| const file = typeof mdxFile === 'string' | ||
| ? { markdown: mdxFile, baseUrl: currentBaseUrl } | ||
| : mdxFile |
There was a problem hiding this comment.
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
Summary
mdxFilessupport toresolveModules()so preprocessed.mdand.mdxfiles can participate in normal MDX imports.Validation
pnpm test -- --run safe-mdx.test.tsxpnpm buildNotes
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.