-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: Module graph in workspace of UI package #3636
Changes from 11 commits
cb8669b
bc9a074
bec512c
a688acf
3ed6363
da1de1f
5385c5e
f66c06b
480b7e5
76711f6
6afbb17
f5ce65e
e1348d2
11bb99d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import type { ModuleNode } from 'vite' | ||
import type { ModuleGraphData, Vitest } from '../types' | ||
|
||
export async function getModuleGraph(ctx: Vitest, id: string): Promise<ModuleGraphData> { | ||
export async function getModuleGraph(ctx: Vitest, id: string, workspaceName?: string): Promise<ModuleGraphData> { | ||
const graph: Record<string, string[]> = {} | ||
const externalized = new Set<string>() | ||
const inlined = new Set<string>() | ||
|
@@ -29,7 +29,18 @@ export async function getModuleGraph(ctx: Vitest, id: string): Promise<ModuleGra | |
graph[id] = (await Promise.all(mods.map(m => get(m, seen)))).filter(Boolean) as string[] | ||
return id | ||
} | ||
await get(ctx.server.moduleGraph.getModuleById(id)) | ||
|
||
const workspaceProject = ctx.projects.find(project => project.getName() === workspaceName) | ||
const workspaceModules = workspaceProject?.ctx.getModuleProjects(id) | ||
const selectedModule = workspaceModules?.find(module => module.getName() === workspaceName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You do the same thing you did on #L33. Why? You need to find the project by name and fallback to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sheremet-va Upon investigating, I have found that the conditons that executes the
This might be hacky, but I have found only this way where we get the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it will be null if there is no core project. This is why I added Core workspace project should be used AS THE LAST RESORT. Regular projects should be used if they are found by name.
Then you must be doing something wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Workspace project is just a project with the same name. If there is no such projects, just fallback to context which is always defined |
||
let workspaceMod: ModuleNode | undefined | ||
if (selectedModule) { | ||
const { server, browser } = selectedModule | ||
const mod = server.moduleGraph.getModuleById(id) || browser?.moduleGraph.getModuleById(id) | ||
workspaceMod = mod | ||
} | ||
|
||
await get(ctx.server.moduleGraph.getModuleById(id) || workspaceMod) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't you fallback to |
||
return { | ||
graph, | ||
externalized: Array.from(externalized), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code can be removed, you already have access to
ctx