Skip to content

Commit a0378f7

Browse files
authored
feat: add unchanged info and toggle button for plugin details (#90)
1 parent cbcb0f8 commit a0378f7

File tree

5 files changed

+76
-20
lines changed

5 files changed

+76
-20
lines changed

packages/devtools-vite/src/app/components/data/PluginDetailsTable.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ const filtered = computed(() => {
4646
return b.duration - a.duration
4747
})
4848
: props.buildMetrics.calls
49-
return sorted.filter((i) => {
50-
if (!i.module)
51-
return false
52-
const matched = getFileTypeFromModuleId(i.module)
53-
return filterModuleTypes.value.includes(matched.name)
54-
}).filter(settings.value.pluginDetailSelectedHook ? i => i.type === settings.value.pluginDetailSelectedHook : Boolean)
49+
return sorted
50+
.filter((i) => {
51+
if (!i.module)
52+
return false
53+
const matched = getFileTypeFromModuleId(i.module)
54+
return filterModuleTypes.value.includes(matched.name)
55+
})
56+
.filter(settings.value.pluginDetailSelectedHook ? i => i.type === settings.value.pluginDetailSelectedHook : Boolean)
57+
.filter((i) => {
58+
if (settings.value.pluginDetailsShowType === 'all' || !['load', 'transform'].includes(settings.value.pluginDetailSelectedHook))
59+
return true
60+
61+
return settings.value.pluginDetailsShowType === 'changed' ? !i.unchanged : i.unchanged
62+
})
5563
})
5664
5765
function toggleModuleType(rule: FilterMatchRule) {

packages/devtools-vite/src/app/components/flowmap/PluginFlow.vue

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup lang="ts">
2+
import type { ClientSettings } from '~~/app/state/settings'
23
import type { RolldownPluginBuildMetrics, SessionContext } from '~~/shared/types/data'
3-
import { useToggle } from '@vueuse/core'
4+
import { useCycleList, useToggle } from '@vueuse/core'
45
import { computed, ref, watch } from 'vue'
56
import { settings } from '~~/app/state/settings'
67
7-
defineProps<{
8+
const props = defineProps<{
89
session: SessionContext
910
buildMetrics: RolldownPluginBuildMetrics
1011
}>()
@@ -46,11 +47,43 @@ const searchValue = ref<{ selected: string[] | null, search: false }>({
4647
selected: settings.value.pluginDetailsTableFields,
4748
search: false,
4849
})
50+
4951
const selectedFields = computed(() => settings.value.pluginDetailsTableFields ? settings.value.pluginDetailsTableFields : tableFieldFilterRules.map(rule => rule.name))
52+
const { state: showTypeState, next: _toggleShowType } = useCycleList<ClientSettings['pluginDetailsShowType']>(['changed', 'unchanged', 'all'], {
53+
initialValue: settings.value.pluginDetailsShowType,
54+
})
55+
const showTypeText = computed(() => {
56+
if (showTypeState.value === 'all')
57+
return 'Show Changed'
58+
if (showTypeState.value === 'changed')
59+
return 'Show Unchanged'
60+
return 'Show All'
61+
})
62+
const showUnchangedInfo = computed(() => {
63+
if (!['load', 'transform'].includes(settings.value.pluginDetailSelectedHook))
64+
return false
65+
66+
if (!props.buildMetrics.calls?.filter(i => i.type === settings.value.pluginDetailSelectedHook).filter(i => i.unchanged).length)
67+
return false
68+
return true
69+
})
70+
const unchangedInfo = computed(() => {
71+
const unchanged = props.buildMetrics.calls?.filter(i => i.type === settings.value.pluginDetailSelectedHook).filter(i => i.unchanged)
72+
const unchangedDuration = unchanged.reduce((acc, i) => acc + i.duration, 0)
73+
return {
74+
count: unchanged.length,
75+
duration: unchangedDuration,
76+
}
77+
})
5078
5179
watch(() => searchValue.value.selected, (value) => {
5280
settings.value.pluginDetailsTableFields = value
5381
})
82+
83+
function toggleShowType() {
84+
_toggleShowType()
85+
settings.value.pluginDetailsShowType = showTypeState.value
86+
}
5487
</script>
5588

5689
<template>
@@ -71,17 +104,28 @@ watch(() => searchValue.value.selected, (value) => {
71104
</FlowmapPluginFlowTimeline>
72105
</div>
73106
<div flex-1 of-y-auto h-full flex="~ col">
74-
<div px2 h10 border="b base" bg-base rounded-t-2 of-x-auto ws-nowrap flex="~ items-center">
75-
<button v-if="!expanded" w8 h8 rounded-full cursor-pointer mr1 hover="bg-active" flex="~ items-center justify-center" @click="toggleExpanded(true)">
76-
<i i-fluent:panel-left-expand-20-regular inline-flex op50 />
77-
</button>
78-
<DataSearchPanel
79-
v-model="searchValue"
80-
h8
81-
border-none selected-container-class="p0! border-none bg-none flex-nowrap!"
82-
:rules="tableFieldFilterRules"
83-
class="[&_[icon-catppuccin]]:(filter-none!)"
84-
/>
107+
<div flex="~ items-center justify-between" border="b base" px2 h10 bg-base rounded-t-2 of-x-auto ws-nowrap>
108+
<div flex="~ items-center" h-full>
109+
<button v-if="!expanded" w8 h8 rounded-full cursor-pointer mr1 hover="bg-active" flex="~ items-center justify-center" @click="toggleExpanded(true)">
110+
<i i-fluent:panel-left-expand-20-regular inline-flex op50 />
111+
</button>
112+
<DataSearchPanel
113+
v-model="searchValue"
114+
h-full border-none selected-container-class="px0! py1 border-none bg-none flex-nowrap! h-full"
115+
:rules="tableFieldFilterRules"
116+
class="[&_[icon-catppuccin]]:(filter-none!)"
117+
/>
118+
</div>
119+
<div v-if="showUnchangedInfo" flex="~ items-center justify-center gap1" h-full text-xs py1>
120+
<p class="op50" flex="~ items-center gap-1">
121+
<DisplayNumberBadge :number="unchangedInfo.count" /> module unchanged, but cost <DisplayDuration :duration="unchangedInfo.duration" />
122+
</p>
123+
<button rounded-md px2 py1 select-none h-full border="~ base rounded-lg" hover="bg-active" :title="showTypeText" @click="toggleShowType">
124+
<div class="text-xs op50">
125+
{{ showTypeText }}
126+
</div>
127+
</button>
128+
</div>
85129
</div>
86130
<div flex-1 of-y-auto overscroll-contain>
87131
<DataPluginDetailsTable

packages/devtools-vite/src/app/state/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ClientSettings {
2121
pluginDetailsModuleTypes: string[] | null
2222
pluginDetailsDurationSortType: string
2323
pluginDetailSelectedHook: string
24+
pluginDetailsShowType: 'changed' | 'unchanged' | 'all'
2425
}
2526

2627
export const settings = useLocalStorage<ClientSettings>(
@@ -44,6 +45,7 @@ export const settings = useLocalStorage<ClientSettings>(
4445
pluginDetailsModuleTypes: null,
4546
pluginDetailsDurationSortType: '',
4647
pluginDetailSelectedHook: '',
48+
pluginDetailsShowType: 'all',
4749
},
4850
{
4951
mergeDefaults: true,

packages/devtools-vite/src/node/rolldown/events-manager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class RolldownEventsManager {
8686
...info,
8787
type: 'load',
8888
module: event.module_id,
89+
unchanged: !event.content,
8990
})
9091
}
9192
else if (event.action === 'HookTransformCallEnd') {
@@ -108,6 +109,7 @@ export class RolldownEventsManager {
108109
...info,
109110
type: 'transform',
110111
module: event.module_id,
112+
unchanged: _start.content === _end.content,
111113
})
112114
}
113115
this.plugin_build_metrics.set(pluginId, plugin_build_metrics)

packages/devtools-vite/src/shared/types/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface PluginBuildInfo {
3232
export interface PluginBuildMetrics {
3333
plugin_name: string
3434
plugin_id: number
35-
calls: PluginBuildInfo[]
35+
calls: (PluginBuildInfo & { unchanged?: boolean })[]
3636
}
3737

3838
export type { PluginItem }

0 commit comments

Comments
 (0)