JedWatson / react-select

The Select Component for React.js
https://react-select.com/
MIT License
27.55k stars 4.12k forks source link

Fix `exports` field #5626

Closed emmatown closed 1 year ago

emmatown commented 1 year ago

closes #5595 closes #4859

The exports field added in #5559 was wrong in a few ways, arethetypeswrong explains this well:

🐛 Imports of all entrypoints under resolution modes that use the import condition in package.json "exports" resolved through a conditional package.json export, but only after failing to resolve through an earlier condition. This behavior is a TypeScript bug and should not be relied upon.

🚭 The implementation resolved at all entrypoints uses ESM syntax, but the detected module kind is CJS. This will be an error in Node (and potentially other runtimes and bundlers). The module kind was decided based on the nearest package.json’s lack of a "type": "module" field.

This PR makes react-select use Preconstruct's exports field feature which does things correctly, I've also checked the build output on this branch with arethetypeswrong and it reports no errors. Of note is that there is still no bundle for Node ESM, the .mjs file used when the import condition matches just re-exports from the CJS bundle but fixes the default export (this is new to Preconstruct and is what "importConditionDefaultExport": "default" is doing), the lack of a Node ESM bundle is intentional so the dual package hazard can't happen. Bundlers will use the module condition to still have ESM there. There is also intentionally no types condition, that's unnecessary because Typescript will resolve to the import or default conditions and use the .d.mts and .d.ts files next to the implementations.

changeset-bot[bot] commented 1 year ago

🦋 Changeset detected

Latest commit: 603bd7a3a48528d3e5f5679d5dc5f590c9db8602

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------ | ----- | | react-select | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

codesandbox-ci[bot] commented 1 year ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 603bd7a3a48528d3e5f5679d5dc5f590c9db8602:

Sandbox Source
react-codesandboxer-example Configuration