-
Notifications
You must be signed in to change notification settings - Fork 145
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
fix: package types exports for ESM projects #970
Conversation
🦋 Changeset detectedLatest commit: 3223527 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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 3223527:
|
7e52187
to
4dd7df2
Compare
✅ PR title follows Conventional Commits specification. |
can you test this on react native project and confirm? AFAIK the exports field has no effect on RN projects yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ✅
Just check if things are not breaking on React Native
Ack. Will test on React Native soon as I get some time. |
Fixes #960
Description
TypeScript requires types to be declared in the
"types"
property under"exports"
section ofpackage.json
of npm packages to detect declaration files in a project setup that outputs ESM.(combination of
type:module
in project'spackage.json
andmodule:NodeNext
intsconfig.json
)I've added the missing fields. These fields are only used by TypeScript in an ESM setup so backwards compatibility shouldn't be affected.
Note: An alternate shorter solution is to rename the generated types files for web from
index.d.ts
toindex.web.d.ts
. While that would work for the above config, it will break types formoduleResolution:node
. Since the automatic detection of TypeScript varies based on the moduleResolution used, it's better to tell TypeScript explicitly where the types are for each export instead of relying on automatic detection. Renaming the generated file will also cause a backwards compatibility issue as pointed out by this code comment:https://github.com/razorpay/blade/blob/master/packages/blade/rollup.config.js#L127
Testing
Tested the below combinations in a web project.
Note: Haven't tested this solution for a react-native project.
Screenshots
References