Skip to content

fix: fix types for PackageJson exports#185

Merged
pi0 merged 5 commits into
mainfrom
fix/exports
Jul 2, 2024
Merged

fix: fix types for PackageJson exports#185
pi0 merged 5 commits into
mainfrom
fix/exports

Conversation

@pi0

@pi0 pi0 commented Jul 2, 2024

Copy link
Copy Markdown
Member

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 danielroe and sxzz July 2, 2024 14:01
@pi0 pi0 self-assigned this Jul 2, 2024
@sxzz

sxzz commented Jul 2, 2024

Copy link
Copy Markdown
Member

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

@sxzz

sxzz commented Jul 2, 2024

Copy link
Copy Markdown
Member

@pi0

pi0 commented Jul 2, 2024

Copy link
Copy Markdown
Member Author

@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

pi0 commented Jul 2, 2024

Copy link
Copy Markdown
Member Author

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

pi0 commented Jul 2, 2024

Copy link
Copy Markdown
Member Author

@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

sxzz commented Jul 2, 2024

Copy link
Copy Markdown
Member

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

pi0 commented Jul 2, 2024

Copy link
Copy Markdown
Member Author

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
@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