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: add Vite plugin at a given index #53

Merged
merged 2 commits into from
May 6, 2023
Merged

Conversation

Lms24
Copy link
Contributor

@Lms24 Lms24 commented May 2, 2023

This PR adds an optional parameter to the addVitePlugin helper function to specify an optional index where the plugin should be inserted. This makes it possible to use this helper if a plugin if the plugin to be inserted needs to run first or appear before/after a certain plugin.
If the index parameter is not specified, the function will append the plugin to the end of the array just like before.

This PR also adds a test to show the behaviour for inserting plugins at the beggining, middle and end of the array.

Reason for this change:
I need this feature for our Sentry SDK installation wizard. It's pretty simple to do without a high-level helper but I thought I'd contribute it upstream as well as IMO it would be nice to have out of the box. Feel free to close this if you want to take this API into another direction.

Thanks for taking the time to consider this.

@@ -37,12 +37,17 @@ export interface UpdateVitePluginConfigOptions {

export function addVitePlugin(
magicast: ProxifiedModule<any>,
plugin: AddVitePluginOptions
plugin: AddVitePluginOptions,
index?: number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this part of the options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, done!

@Lms24 Lms24 requested a review from antfu May 4, 2023 10:32
@antfu antfu changed the title feat: Add Vite plugin at a given index feat: add Vite plugin at a given index May 6, 2023
@codecov
Copy link

codecov bot commented May 6, 2023

Codecov Report

Merging #53 (88d285c) into main (9675560) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   91.51%   91.56%   +0.05%     
==========================================
  Files          24       24              
  Lines        1591     1601      +10     
  Branches      308      310       +2     
==========================================
+ Hits         1456     1466      +10     
  Misses        135      135              
Impacted Files Coverage Δ
src/helpers/vite.ts 94.44% <100.00%> (+0.56%) ⬆️

@antfu antfu merged commit a76cc20 into unjs:main May 6, 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.

None yet

2 participants