Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compartment mapper should take first matching of conditional exports #2276

Closed
kriskowal opened this issue May 8, 2024 · 1 comment · Fixed by #2275
Closed

Compartment mapper should take first matching of conditional exports #2276

kriskowal opened this issue May 8, 2024 · 1 comment · Fixed by #2275
Assignees
Labels
bug Something isn't working

Comments

@kriskowal
Copy link
Member

Describe the bug

Node.js package conditional imports should take the entries under the first matching tag and ignore all subsequent tags. This is hinted with the express advice that default must appear last if present.

Steps to reproduce

Create a bundle from a package that has conditional exports e.g., endo and default and note that default wins.

Expected behavior

The first match (node in the example) should win.

@kriskowal
Copy link
Member Author

This fix is necessary for progress toward native XS support #400.

kriskowal added a commit that referenced this issue May 28, 2024
…rts (#2275)

Closes: #2276

## Description

If a `package.json` `"exports"` is a list of ordered constraints, Endo’s
Compartment Mapper currently uses all of the accepted entries and not
just the first. This causes subsequent entries to override the first if
they produce matching paths. I believe the intended behavior is to use
the first that matches.

### Security Considerations

This amounts to a difference in behavior between Endo and Node in the
treatment of Package Exports.

### Scaling Considerations

None.

### Documentation Considerations

Fixing this issue will bring Endo into accord with Node.js’s somewhat
light documentation on this feature.

### Testing Considerations

Existing snapshot tests cover the behavior and must be updated to
reflect the correct interpretation.

### Compatibility Considerations

This will improve ecosystem compatibility. No known bundles depend on
the existing behavior, but we cannot rule out the possibility.

There is a possibility that this change will break existing bundles that
depend on the current erroneous behavior, for example preferring
`default` over an `endo` tag. I am considering this a bugfix and not a
breaking change since it is a bug to rely on the current behavior.

### Upgrade Considerations

Even if this behavior might break the bundling process for existing
contracts, it will not invalidate existing bundles. This change should
not break upgrades but may create a speed bump for upgrading tool
dependencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant