2
2
import type { TreeNodeInput } from ' nanovis'
3
3
import type { PluginBuildInfo , RolldownPluginBuildMetrics , SessionContext } from ' ~~/shared/types'
4
4
import { Flamegraph , normalizeTreeNode } from ' nanovis'
5
+ import { relative } from ' pathe'
5
6
import { computed , onMounted , onUnmounted , ref , shallowRef , useTemplateRef , watch } from ' vue'
6
7
import { parseReadablePath } from ' ~/utils/filepath'
7
8
import { normalizeTimestamp } from ' ~/utils/format'
@@ -21,68 +22,73 @@ const parsedPaths = computed(() => props.session.modulesList.map((mod) => {
21
22
type ,
22
23
}
23
24
}))
24
-
25
- // filter current module list existed module type
26
- const existedModuleTypes = computed (() => ModuleTypeRules .filter (rule => parsedPaths .value .some (mod => rule .match .test (mod .mod .id ))))
25
+ const moduleTypes = computed (() => ModuleTypeRules .filter (rule => parsedPaths .value .some (mod => rule .match .test (mod .mod .id ))))
27
26
28
27
const n = (node : TreeNodeInput <PluginBuildInfo >) => normalizeTreeNode (node , undefined , false )
29
28
29
+ function normalizeModulePath(path : string ) {
30
+ const normalized = path .replace (/ %2F/ g , ' /' )
31
+ const cwd = props .session ! .meta .cwd
32
+ let relate = cwd ? relative (cwd , normalized ) : normalized
33
+ if (! relate .startsWith (' .' ))
34
+ relate = ` ./${relate } `
35
+ if (relate .startsWith (' ./' ))
36
+ return relate
37
+ if (relate .match (/ ^ (?:\.\.\/ ){1,3} [^ . ] / ))
38
+ return relate
39
+ return normalized
40
+ }
41
+
30
42
const tree = computed (() => {
31
- // build children: module group by module type
32
- const resolveIds = existedModuleTypes .value .map ((type , idx ) => n ({
43
+ const resolveIds = moduleTypes .value .map ((type , idx ) => n ({
33
44
id: ` resolveId-${type .name }-${idx } ` ,
34
- text: type .name ,
45
+ text: type .description ,
35
46
children: props .buildMetrics .resolveIdMetrics .filter ((item ) => {
36
47
return getFileTypeFromModuleId (item .module ).name === type .name
37
48
}).map ((id , idx ) => n ({
38
49
id: ` resolveId-${idx } ` ,
39
- text: id .module ,
50
+ text: normalizeModulePath ( id .module ) ,
40
51
size: id .duration ,
41
- meta: id ,
42
52
})),
43
53
}))
44
-
45
- const loads = existedModuleTypes .value .map ((type , idx ) => n ({
54
+ const loads = moduleTypes .value .map ((type , idx ) => n ({
46
55
id: ` loads-${type .name }-${idx } ` ,
47
- text: type .name ,
56
+ text: type .description ,
48
57
children: props .buildMetrics .loadMetrics .filter ((item ) => {
49
58
return getFileTypeFromModuleId (item .module ).name === type .name
50
59
}).map ((id , idx ) => n ({
51
60
id: ` resolveId-${idx } ` ,
52
- text: id .module ,
61
+ text: normalizeModulePath ( id .module ) ,
53
62
size: id .duration ,
54
- meta: id ,
55
63
})),
56
64
}))
57
-
58
- const transforms = existedModuleTypes .value .map ((type , idx ) => n ({
65
+ const transforms = moduleTypes .value .map ((type , idx ) => n ({
59
66
id: ` transforms-${type .name }-${idx } ` ,
60
- text: type .name ,
67
+ text: type .description ,
61
68
children: props .buildMetrics .transformMetrics .filter ((item ) => {
62
69
return getFileTypeFromModuleId (item .module ).name === type .name
63
70
}).map ((id , idx ) => n ({
64
71
id: ` resolveId-${idx } ` ,
65
- text: id .module ,
72
+ text: normalizeModulePath ( id .module ) ,
66
73
size: id .duration ,
67
- meta: id ,
68
74
})),
69
75
}))
70
76
71
77
// resolve/load/transform -> module type -> module
72
78
const children = [
73
79
n ({
74
80
id: ' ~resolves' ,
75
- text: ' resolve ' ,
81
+ text: ' Resolve Id ' ,
76
82
children: resolveIds ,
77
83
}),
78
84
n ({
79
85
id: ' ~loads' ,
80
- text: ' load ' ,
86
+ text: ' Load ' ,
81
87
children: loads ,
82
88
}),
83
89
n ({
84
90
id: ' ~transforms' ,
85
- text: ' transform ' ,
91
+ text: ' Transform ' ,
86
92
children: transforms ,
87
93
}),
88
94
]
0 commit comments