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

feat(helpers): Handle Vite config declarations with satisfies keyword #82

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

Lms24
Copy link
Contributor

@Lms24 Lms24 commented Sep 12, 2023

πŸ”— Linked issue

Still relevant for #68

fixes getsentry/sentry-wizard#445

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds support for the satisfies keyword when it's used in Vite configs. Specifically for the case, when a config object is declared as a variable (with satisfies) before it's exported:

import { somePlugin1, somePlugin2 } from 'some-module'

import type { UserConfig } from 'vite';

const myConfig = defineConfig({
  plugins: [somePlugin1(), somePlugin2()]
}) satisfies UserConfig;

export default myConfig;

I also added support for using satisfies in conjuction with defineConfig but I'd argue this is pretty unlikely to be used, so happy to remove if reviewers would prefer that.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Sep 12, 2023

Codecov Report

Merging #82 (f1c301a) into main (a8752c8) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
+ Coverage   92.31%   92.40%   +0.09%     
==========================================
  Files          23       23              
  Lines        1730     1751      +21     
  Branches      313      322       +9     
==========================================
+ Hits         1597     1618      +21     
  Misses        133      133              
Files Changed Coverage Ξ”
src/helpers/config.ts 90.41% <100.00%> (+0.55%) ⬆️
src/helpers/vite.ts 97.07% <100.00%> (+0.32%) ⬆️

@antfu
Copy link
Member

antfu commented Sep 14, 2023

That's weird, ideally, it should have already been forwarded by

case "TSSatisfiesExpression": {

@antfu
Copy link
Member

antfu commented Sep 14, 2023

Oh I see, it's direct AST manipulation. I think ideally we better call proxify to generate subtree so magicast could handle them automatically, and we don't need to do code generation and parsing again in the helpers. I am fine with having this for now.

@antfu antfu merged commit 6b2ef88 into unjs:main Sep 14, 2023
3 checks passed
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.

Vite plugin isn't inserted correctly when config is declared as variable and satisfies is used
2 participants