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

chore: Validate "exports" field in package.json #5350

Merged
merged 11 commits into from May 1, 2023
Merged

chore: Validate "exports" field in package.json #5350

merged 11 commits into from May 1, 2023

Conversation

lachlancollins
Copy link
Member

@lachlancollins lachlancollins commented Apr 30, 2023

According to publint:

This entrypoint has types at build/lib/index.d.ts but it is not exported from pkg.exports. Consider adding it to pkg.exports["."].types to be compatible with TypeScript's "moduleResolution": "bundler" compiler option. ([More info](https://publint.dev/rules.html#types_not_exported))

This was actually working with bundler mode because the .d.ts files are adjacent to the .js files. However, this is obviously more correct, and the other query packages do this already.

I've added a check to validate-packages.ts to look for exports['.']['default'], and also moved the entries logic into config.ts. In the future, it might be possible to add publint to this file - however I ran into a CJS/ESM error which I will investigate at a later time.

@vercel
Copy link

vercel bot commented Apr 30, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
query ⬜️ Ignored (Inspect) May 1, 2023 11:40am

@nx-cloud
Copy link

nx-cloud bot commented Apr 30, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f3a83cc. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@lachlancollins
Copy link
Member Author

@TkDodo any idea why these checks failed?

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 30, 2023

Yeah alpha is broken currently since I merged main back to it, where we added distributed task execution in nx. @ZackDeRose is looking into it. Sorry for the inconvenience 🙈

@lachlancollins
Copy link
Member Author

@TkDodo no stress! The Nx distributed agents speed gains are 💯. Are checks on main also broken?

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 30, 2023

@lachlancollins upgrade to node18 fixed the issue

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 30, 2023

build validation fails now with:

Validating packages...
Error: Missing entry for "types" in svelte-query/package.json!

@lachlancollins
Copy link
Member Author

I'm on it!

@lachlancollins
Copy link
Member Author

Hi @TkDodo , could you please review my changes to validate-packages.ts? I've added a check to make sure packages have exports['.']['default'] field - eslint-plugin-query was failing this test so I've added exports to it. If this is too far outside the scope of this PR let me know and I'll split it. Or I could rename this PR more generally related to package.json :)

@lachlancollins lachlancollins changed the title fix(svelte-query): Add "types" field to exports in package.json chore: Validate "exports" field in package.json May 1, 2023
@codesandbox-ci
Copy link

codesandbox-ci bot commented May 1, 2023

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 f3a83cc:

Sandbox Source
@tanstack/query-example-react-basic-typescript Configuration
@tanstack/query-example-solid-basic-typescript Configuration
@tanstack/query-example-svelte-basic Configuration
@tanstack/query-example-vue-basic Configuration

@codecov-commenter
Copy link

codecov-commenter commented May 1, 2023

Codecov Report

Patch coverage has no change and project coverage change: -3.89 ⚠️

Comparison is base (5e43e00) 92.27% compared to head (63f7cf3) 88.39%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5350      +/-   ##
==========================================
- Coverage   92.27%   88.39%   -3.89%     
==========================================
  Files         112       24      -88     
  Lines        4271      491    -3780     
  Branches     1114      152     -962     
==========================================
- Hits         3941      434    -3507     
+ Misses        309       52     -257     
+ Partials       21        5      -16     

see 88 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TkDodo
Copy link
Collaborator

TkDodo commented May 1, 2023

@lachlancollins I don't think the eslint-plugin needs an exports entry. Maybe we could add exports to entries in scripts/config.ts so that it becomes:

entries: ['main', 'module', 'types', 'exports'],

for most packages, but leave it out for the eslint one?

scripts/config.ts Outdated Show resolved Hide resolved
@lachlancollins
Copy link
Member Author

lachlancollins commented May 1, 2023

@TkDodo I'd have to do something like exportsEntries: ['default', 'import', '...'], since exports is a bit more complex to check. Would be easier in the long-term to replace all this logic with publint!

Is there any harm in adding exports to the eslint package? It is the "replacement" to main/module/types and is used by all the other packages. I could do something like checkExports: false if you definitely don't want it.

Also, I'm happy to add back module and types to svelte-query, but I don't think it's even possible to build svelte with a bundler that doesn't support exports :P

@TkDodo
Copy link
Collaborator

TkDodo commented May 1, 2023

Is there any harm in adding exports to the eslint package?

I suppose not.

Also, I'm happy to add back module and types to svelte-query, but I don't think it's even possible to build svelte with a bundler that doesn't support exports

Alright, just wanted to double check 👍

@TkDodo
Copy link
Collaborator

TkDodo commented May 1, 2023

not sure why codesandbox build is failing now and I can't re-trigger that. can you add an empty commit to re-run it?

@lachlancollins
Copy link
Member Author

lachlancollins commented May 1, 2023

@TkDodo what gets run on codesandbox? It seems like nx run root:rollup completes successfully, then whatever happens immediately after causes the error.

EDIT: nvm, it was just the old flaky tests which were only fixed on alpha.
EDIT EDIT: And it's broken again...

@lachlancollins lachlancollins merged commit f1ac845 into TanStack:main May 1, 2023
11 checks passed
@lachlancollins lachlancollins deleted the svelte-types-export branch May 1, 2023 11:42
@lachlancollins
Copy link
Member Author

@TkDodo I saw webpack mentioned on the svelte subreddit so I panicked and added back the non-exports fields 😅

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.

None yet

3 participants