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(vite): handle both vite.config.ts and vitest.config.ts #22521

Closed
wants to merge 1 commit into from

Conversation

MaximeBernard
Copy link

@MaximeBernard MaximeBernard commented Mar 26, 2024

Current Behavior

When a package has both vite.config.ts and vitest.config.ts, plugin fails to infer targets correctly (in my case, I had some packages with test targets, some with build targets).

Expected Behavior

Having both files should not bother nx plugin.

Related Issue(s)

Might fix #22244

@MaximeBernard MaximeBernard requested a review from a team as a code owner March 26, 2024 18:07
Copy link

vercel bot commented Mar 26, 2024

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Mar 27, 2024 1:12pm

@MaximeBernard
Copy link
Author

For the record, the build was green before I rebased 😉

@MaximeBernard
Copy link
Author

@AgentEnder since you recently worked on plugin configuration, maybe you could take a look at this PR?

@Coly010
Copy link
Contributor

Coly010 commented Apr 2, 2024

Closed in favour of: #22618

@Coly010 Coly010 closed this Apr 2, 2024
@MaximeBernard
Copy link
Author

@Coly010 #22618 is a nice fix but my suggestion seems fair as well (at least for clarity). Unless I missed the point?

Anyway, thanks for the feedback and fixing the underlying issue. ❤️

@Coly010
Copy link
Contributor

Coly010 commented Apr 3, 2024

Hey @MaximeBernard!

Sorry, I should have elaborated more and I also should have said this: Thanks for the PR to attempt to fix this! 🎉

There are two things really.

1. The issue was less about how the targets are created.
I tried your example locally, and although on first run after the cache was reset all targets were created successfully, subsequent runs only had the build, serve, preview etc targets. It was missing test for example.

The real issue was not about the conditional on the config file name. It was because both config files were generating the same hash as the parameters were the same, which led to one or the other of the config files overwriting the cache for the targets. Which config file did this was dictated by that conditional. Changing it only changed which config file overwrote the cache last.

2. Code style
There are two conditionals that dictate the targets that should be created. From a personal perspective, I find it easier to read code that does something for the truthy and falsey outcomes of that same conditional.

IF configFile != vitest THEN
 // Add Build Targets etc
 
 IF configFile == vitest THEN
// Add Test Target

So when it comes to reading it, you get an overall picture of what happens when the config file is or is not vitest.

Perhaps your suggestion would be more clear, but it's just semantics at that stage.

All this said, thank you again for taking a stab at this! Your suggestion in this PR helped me to identify the root cause of the issue more swiftly!

@MaximeBernard
Copy link
Author

Thank you so much for this answer ❤️

Agree with you it's more about semantic at this point.

In my case, I had 3 scenarios

  • vite.config.ts
  • vitest.config.ts
  • vite.config.ts & vitest.config.ts

When I investigated, this seemed awkward because I didn't expect 2 "runs" (1 on each file).

Thank you for the clarification, have a great day 🚀

Copy link

github-actions bot commented Apr 9, 2024

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Available tasks for a project missing after vite.config.ts
2 participants