Skip to content

Commit fa267ed

Browse files
committed
chore: update
1 parent 6eb480c commit fa267ed

File tree

2 files changed

+30
-57
lines changed

2 files changed

+30
-57
lines changed

packages/devtools-vite/src/app/components/chart/PluginFlamegraph.vue

Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,53 @@
22
import type { TreeNodeInput } from 'nanovis'
33
import type { PluginBuildInfo, RolldownPluginBuildMetrics, SessionContext } from '~~/shared/types'
44
import { Flamegraph, normalizeTreeNode } from 'nanovis'
5+
import { relative } from 'pathe'
56
import { computed, onMounted, onUnmounted, ref, shallowRef, useTemplateRef, watch } from 'vue'
6-
import { parseReadablePath } from '~/utils/filepath'
77
import { normalizeTimestamp } from '~/utils/format'
8-
import { getFileTypeFromModuleId, ModuleTypeRules } from '~/utils/icon'
98
109
const props = defineProps<{
1110
session: SessionContext
1211
buildMetrics: RolldownPluginBuildMetrics
1312
}>()
1413
15-
const parsedPaths = computed(() => props.session.modulesList.map((mod) => {
16-
const path = parseReadablePath(mod.id, props.session.meta.cwd)
17-
const type = getFileTypeFromModuleId(mod.id)
18-
return {
19-
mod,
20-
path,
21-
type,
22-
}
23-
}))
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))))
27-
2814
const n = (node: TreeNodeInput<PluginBuildInfo>) => normalizeTreeNode(node, undefined, false)
2915
16+
function normalizeModulePath(path: string) {
17+
const normalized = path.replace(/%2F/g, '/')
18+
const cwd = props.session!.meta.cwd
19+
let relate = cwd ? relative(cwd, normalized) : normalized
20+
if (!relate.startsWith('.'))
21+
relate = `./${relate}`
22+
if (relate.startsWith('./'))
23+
return relate
24+
if (relate.match(/^(?:\.\.\/){1,3}[^.]/))
25+
return relate
26+
return normalized
27+
}
28+
3029
const tree = computed(() => {
31-
// build children: module group by module type
32-
const resolveIds = existedModuleTypes.value.map((type, idx) => n({
33-
id: `resolveId-${type.name}-${idx}`,
34-
text: type.name,
35-
children: props.buildMetrics.resolveIdMetrics.filter((item) => {
36-
return getFileTypeFromModuleId(item.module).name === type.name
37-
}).map((id, idx) => n({
38-
id: `resolveId-${idx}`,
39-
text: id.module,
40-
size: id.duration,
41-
meta: id,
42-
})),
30+
const resolveIds = props.buildMetrics.resolveIdMetrics.map((id, idx) => n({
31+
id: `resolveId-${idx}`,
32+
text: normalizeModulePath(id.module),
33+
size: id.duration,
34+
meta: id,
4335
}))
4436
45-
const loads = existedModuleTypes.value.map((type, idx) => n({
46-
id: `loads-${type.name}-${idx}`,
47-
text: type.name,
48-
children: props.buildMetrics.loadMetrics.filter((item) => {
49-
return getFileTypeFromModuleId(item.module).name === type.name
50-
}).map((id, idx) => n({
51-
id: `resolveId-${idx}`,
52-
text: id.module,
53-
size: id.duration,
54-
meta: id,
55-
})),
37+
const loads = props.buildMetrics.loadMetrics.map((id, idx) => n({
38+
id: `loads-${idx}`,
39+
text: normalizeModulePath(id.module),
40+
size: id.duration,
41+
meta: id,
5642
}))
5743
58-
const transforms = existedModuleTypes.value.map((type, idx) => n({
59-
id: `transforms-${type.name}-${idx}`,
60-
text: type.name,
61-
children: props.buildMetrics.transformMetrics.filter((item) => {
62-
return getFileTypeFromModuleId(item.module).name === type.name
63-
}).map((id, idx) => n({
64-
id: `resolveId-${idx}`,
65-
text: id.module,
66-
size: id.duration,
67-
meta: id,
68-
})),
44+
const transforms = props.buildMetrics.transformMetrics.map((id, idx) => n({
45+
id: `transforms-${idx}`,
46+
text: normalizeModulePath(id.module),
47+
size: id.duration,
48+
meta: id,
6949
}))
7050
71-
// resolve/load/transform -> module type -> module
51+
// resolve/load/transform -> module
7252
const children = [
7353
n({
7454
id: '~resolves',

packages/devtools-vite/src/app/pages/session/[session]/plugins.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,3 @@ debouncedWatch(
9090
</div>
9191
</div>
9292
</template>
93-
94-
<!--
95-
TODO: plugins framegraph
96-
Two different views direction:
97-
- plugins -> hooks -> modules
98-
- modules -> hooks -> plugins
99-
-->

0 commit comments

Comments
 (0)