Skip to content

Conversation

yyxi
Copy link
Contributor

@yyxi yyxi commented Jul 11, 2025

Summary

Adds support for Vitest's projects configuration that allows defining test projects through inline configurations and external file patterns. External project files are resolved from glob patterns and their dependencies are correctly assigned to their respective workspace locations.

Resolves #1114

Changes

  • Added projects field to VitestConfig interface supporting both inline configs and glob patterns
  • Implemented dynamic glob resolution for external project files using _glob utility
  • External project configurations loaded using toConfig() for proper workspace assignment
  • Created test fixture with both inline and external project configurations
  • Dependencies from external projects are correctly attributed to their respective config files

Test plan

  • All existing tests pass
  • New vitest9 test verifies both inline and external project dependency detection
  • External project configs loaded via glob patterns work correctly
  • Backward compatibility maintained for workspace configuration
  • No regressions introduced

@yyxi
Copy link
Contributor Author

yyxi commented Jul 14, 2025

@webpro ready for review

Copy link
Member

@webpro webpro left a comment

Choose a reason for hiding this comment

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

Thanks! Happy to merge, but I do have a few remarks.

@yyxi
Copy link
Contributor Author

yyxi commented Jul 17, 2025

External project configurations now use toConfig()

  • Replaced _load() with toConfig() for external project files in vitest plugin
  • Dependencies are now correctly assigned to the workspace where the config file is located
  • The resolveConfig function is re-executed with each external config file

Test fixtures simplified and made more realistic

  • Disabled vitest coverage to reduce fixture complexity
  • Test now verifies proper workspace assignment of dependencies

@yyxi yyxi force-pushed the feat/vitest-projects-support branch from 84d1a3c to 515cafc Compare July 17, 2025 09:47
@yyxi yyxi requested a review from webpro July 17, 2025 09:50
Copy link
Member

@webpro webpro left a comment

Choose a reason for hiding this comment

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

Great, happy to see this working. Almost there :)

for (const projectFile of externalProjectFiles) {
inputs.add(toEntry(projectFile));
inputs.add(toConfig('vitest', projectFile));
}
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we can skip creating externalProjectFiles and add this to inputs directly above:

inputs.add(toConfig('vitest', projectFile, { containingFilePath: options.configFilePath }));

These items are added as entry files automatically (i.e. toEntry is redundant).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works?

Copy link

pkg-pr-new bot commented Jul 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/knip@1171

commit: 6181b91

@yyxi yyxi requested a review from webpro July 17, 2025 10:26
@webpro
Copy link
Member

webpro commented Jul 17, 2025

Please see CI for remaining issue: https://github.com/webpro-nl/knip/actions/runs/16342525311. You can run bun format to apply the configured formatting.

Add support for Vitest projects configuration that allows defining test projects
through inline configurations and external file patterns. External project files
are resolved from glob patterns and their dependencies are correctly assigned to
their respective workspace locations.

Resolves #1114
@yyxi yyxi force-pushed the feat/vitest-projects-support branch from 772a23d to 6181b91 Compare July 17, 2025 10:43
@yyxi
Copy link
Contributor Author

yyxi commented Jul 17, 2025

fixed the formatting

@webpro
Copy link
Member

webpro commented Jul 17, 2025

Thank you very much! Let's go 🚀

@webpro webpro merged commit cd0ed32 into webpro-nl:main Jul 17, 2025
29 of 30 checks passed
@webpro
Copy link
Member

webpro commented Jul 18, 2025

🚀 This pull request is included in v5.62.0. See Release 5.62.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

🐛 Vitest workspaces deprecated in v 3.2.0
2 participants