Skip to content

Support string and conditional package.json exports#120

Merged
laat merged 1 commit intomasterfrom
fix-exports-resolution
Apr 12, 2026
Merged

Support string and conditional package.json exports#120
laat merged 1 commit intomasterfrom
fix-exports-resolution

Conversation

@laat
Copy link
Copy Markdown
Owner

@laat laat commented Apr 12, 2026

Summary

  • Resolve the module main entry through a new resolveMainEntry helper that handles every common shape of package.json exports:
    • string ("exports": "./lib/main.js")
    • subpath map ("exports": { ".": "./lib/main.js" })
    • bare conditional ("exports": { "import": "./esm.js", "require": "./cjs.js" })
    • subpath + conditional nesting ("exports": { ".": { "import": { "default": "./esm.js" } } })
  • Preserves the existing options.main > pkg.main > pkg.exports > "./index.js" precedence.

Why

src/run.js used pkg.exports?.["."] to pull the root export, which silently returns undefined for the string form and for bare conditional maps, falling through to ./index.js. This package's own package.json has "exports": "./src/index.js", so any README that imports readme-assert by name would be rewritten to a nonexistent path. Reproduced with a fixture pkg whose exports is ./lib/main.js — before: import rewritten to .../index.js; after: .../lib/main.js.

Test plan

  • New resolveMainEntry unit tests cover string / subpath / conditional / nested / null cases (9 cases).
  • New integration fixture test/fixtures/pkg-string-exports/ exercises the full processMarkdown + run path through an ESM package with "exports": "./lib/main.js".
  • node --test test/*.test.js — 55 tests pass (11 new).
  • pnpm -r test — all 10 workspace example packages still pass.

@laat laat merged commit 13d1f3c into master Apr 12, 2026
2 checks passed
@laat laat deleted the fix-exports-resolution branch April 12, 2026 00:32
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