Support string and conditional package.json exports#120
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveMainEntryhelper that handles every common shape ofpackage.jsonexports:"exports": "./lib/main.js")"exports": { ".": "./lib/main.js" })"exports": { "import": "./esm.js", "require": "./cjs.js" })"exports": { ".": { "import": { "default": "./esm.js" } } })options.main > pkg.main > pkg.exports > "./index.js"precedence.Why
src/run.jsusedpkg.exports?.["."]to pull the root export, which silently returnsundefinedfor the string form and for bare conditional maps, falling through to./index.js. This package's ownpackage.jsonhas"exports": "./src/index.js", so any README that importsreadme-assertby name would be rewritten to a nonexistent path. Reproduced with a fixture pkg whoseexportsis./lib/main.js— before: import rewritten to.../index.js; after:.../lib/main.js.Test plan
resolveMainEntryunit tests cover string / subpath / conditional / nested / null cases (9 cases).test/fixtures/pkg-string-exports/exercises the fullprocessMarkdown+runpath 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.