Skip to content

Commit 69f71ba

Browse files
committed
fix: filter graph modules
1 parent 2d417ea commit 69f71ba

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

packages/vite/src/rpc/graph.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,30 @@ export function getGraphFunctions(ctx: RpcFunctionCtx) {
2424
})
2525
: null
2626
) || []
27-
return modules
27+
const filteredModules = modules.filter((m) => {
28+
return m.id.match(/\.(vue|js|ts|jsx|tsx|html|json)($|\?v=)/)
29+
})
30+
const graph = filteredModules.map((i) => {
31+
function searchForVueDeps(id: string, seen = new Set<string>()): string[] {
32+
if (seen.has(id))
33+
return []
34+
seen.add(id)
35+
const module = modules.find(m => m.id === id)
36+
if (!module)
37+
return []
38+
return module.deps.flatMap((i) => {
39+
if (filteredModules.find(m => m.id === i))
40+
return [i]
41+
return searchForVueDeps(i, seen)
42+
})
43+
}
44+
45+
return {
46+
id: i.id,
47+
deps: searchForVueDeps(i.id),
48+
}
49+
})
50+
return graph
2851
},
2952
}
3053
}

0 commit comments

Comments
 (0)