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

fix: fix types for PackageJson exports #185

Merged
merged 5 commits into from
Jul 2, 2024
Merged

fix: fix types for PackageJson exports #185

merged 5 commits into from
Jul 2, 2024

Conversation

pi0
Copy link
Member

@pi0 pi0 commented Jul 2, 2024

Fixes regression from #183

Exports field can be string or a nested object. But not an array of string. Passes tests for vue.js case at least.

@pi0 pi0 requested review from sxzz and danielroe July 2, 2024 14:01
@pi0 pi0 self-assigned this Jul 2, 2024
@sxzz
Copy link
Member

sxzz commented Jul 2, 2024

According to nodejs doc, it can be an array, and TS resolves it.

@sxzz
Copy link
Member

sxzz commented Jul 2, 2024

@pi0
Copy link
Member Author

pi0 commented Jul 2, 2024

@sxzz Yes i saw that. But do you have a package example with it or link to spec how it works when array passed? (we can add back string[] but i need to make sure now)

@pi0
Copy link
Member Author

pi0 commented Jul 2, 2024

Update: Found it in resolution algorithm (PACKAGE_EXPORTS_RESOLVE) so strange that there is limited info about it and i've never saw it in any package..

PS it seems about subpaths?

image

@pi0
Copy link
Member Author

pi0 commented Jul 2, 2024

@sxzz Added back array type with correct specs (it should be only for subpaths and can be either string or object) seems good to you?

@sxzz
Copy link
Member

sxzz commented Jul 2, 2024

I created a minimal reproduction: https://stackblitz.com/edit/vitejs-vite-jmzo3v?file=index.ts&terminal=dev

Run pnpm install && pnpm tsc, and you'll see that index.d.ts is generated with the correct types, inferred from pkg/b.d.ts. The pkg/package.json is:

{
  "name": "test-pkg",
  "exports": ["./a.d.ts", "./b.d.ts", "./c.d.ts"]
}

This demonstrates that TypeScript can always resolve array-type exports, whether they are in the root path or a subpath.

@pi0
Copy link
Member Author

pi0 commented Jul 2, 2024

Thanks. I also confirmed with node resolution that does resolve array even more strange...

(updated PR to also include top level array 👍🏼 )

@pi0 pi0 merged commit 2f67cbc into main Jul 2, 2024
2 checks passed
@pi0 pi0 deleted the fix/exports branch July 2, 2024 19:40
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.

2 participants