MCPcopy
hub / github.com/mastra-ai/mastra / discoverProjects

Function discoverProjects

vitest.config.ts:37–102  ·  view source on GitHub ↗

* Discovers all vitest projects from package configs. * For configs with nested projects, expands them with the correct root path. * For simple configs, returns the directory as a project path.

()

Source from the content-addressed store, hash-verified

35 * For simple configs, returns the directory as a project path.
36 */
37async function discoverProjects(): Promise<TestProjectConfiguration[]> {
38 const projects: TestProjectConfiguration[] = [];
39
40 // Find all vitest.config.ts files
41 const configPaths = PROJECT_GLOBS.flatMap(pattern => globSync(pattern));
42
43 for (const configPath of configPaths) {
44 const projectDir = dirname(configPath);
45
46 // Skip excluded directories
47 if (EXCLUDED_DIRS.has(projectDir)) {
48 continue;
49 }
50
51 // Read the config file to check if it has nested projects
52 const configContent = readFileSync(configPath, 'utf-8');
53 const hasNestedProjects = /test:\s*\{[\s\S]*?projects:\s*\[/.test(configContent);
54
55 if (!hasNestedProjects) {
56 // Simple config - use directory path
57 projects.push(projectDir);
58 continue;
59 }
60
61 // Config has nested projects - load it using Vite's config loader
62 try {
63 const absolutePath = resolve(process.cwd(), configPath);
64 const loaded = await loadConfigFromFile({} as any, absolutePath);
65 if (!loaded) {
66 projects.push(projectDir);
67 continue;
68 }
69 const config = loaded.config as UserWorkspaceConfig;
70
71 if (!config.test?.projects) {
72 // Fallback if config parsing didn't work as expected
73 projects.push(projectDir);
74 continue;
75 }
76
77 // Expand nested projects with root path
78 for (const nestedProject of config.test.projects) {
79 if (typeof nestedProject === 'string') {
80 // String reference - resolve relative to the config's directory
81 projects.push(`${projectDir}/${nestedProject}`);
82 } else {
83 // Inline project config - add root path
84 const projectConfig = nestedProject as UserWorkspaceConfig;
85 projects.push({
86 ...projectConfig,
87 test: {
88 ...projectConfig.test,
89 root: `./${projectDir}`,
90 },
91 });
92 }
93 }
94 } catch (error) {

Callers 1

vitest.config.tsFile · 0.85

Calls 6

dirnameFunction · 0.85
testMethod · 0.80
hasMethod · 0.65
warnMethod · 0.65
resolveFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…