22import type { ModuleInfo , RolldownModuleTransformInfo , SessionContext } from ' ~~/shared/types'
33import { useRpc } from ' #imports'
44import { computedAsync } from ' @vueuse/core'
5- import { nextTick , ref , watchEffect } from ' vue'
5+ import { computed , nextTick , ref , watchEffect } from ' vue'
6+ import { getContentByteSize } from ' ~~/app/utils/format'
67
78const props = defineProps <{
89 session: SessionContext
@@ -44,6 +45,41 @@ const info = computedAsync(async () => {
4445 } as ModuleInfo
4546})
4647
48+ const durations = computed (() => {
49+ const data = info .value
50+ const _resolveIds = data ?.resolve_ids .reduce ((t , node ) => {
51+ t += node .duration
52+ return t
53+ }, 0 ) ?? 0
54+ const _loads = data ?.loads ?.reduce ((t , node ) => {
55+ t += node .duration
56+ return t
57+ }, 0 ) ?? 0
58+ const _transforms = data ?.transforms .reduce ((t , node ) => {
59+ t += node .duration
60+ return t
61+ }, 0 ) ?? 0
62+ const total = _resolveIds + _loads + _transforms
63+ return {
64+ resolveIds: _resolveIds ,
65+ loads: _loads ,
66+ transforms: _transforms ,
67+ total ,
68+ }
69+ })
70+
71+ const sourceCodeSize = computed (() => {
72+ const data = info .value ?.transforms
73+ const source = data ?.[0 ]?.content_from ?? ' '
74+ return getContentByteSize (source )
75+ })
76+
77+ const transformedCodeSize = computed (() => {
78+ const data = info .value ?.transforms ?.filter (t => t .content_to )?.reverse ()
79+ const source = data ?.[0 ]?.content_to ?? ' '
80+ return getContentByteSize (source )
81+ })
82+
4783function selectFlowNode(v : boolean ) {
4884 flowNodeSelected .value = v
4985}
@@ -60,7 +96,40 @@ function selectFlowNode(v: boolean) {
6096 border =" ~ base rounded-lg"
6197 flex =" ~ col gap-2"
6298 >
63- <DisplayModuleId :id =" module" px2 py1 :session />
99+ <DisplayModuleId :id =" module" px2 pt1 :session />
100+ <div text-xs font-mono flex =" ~ items-center gap-3" ml2 >
101+ <DisplayDuration
102+ :duration =" durations.resolveIds" flex =" ~ gap-1 items-center"
103+ :title =" `resolveId hooks cost: ${durations.resolveIds}ms`"
104+ >
105+ <span i-ph-magnifying-glass-duotone inline-block />
106+ </DisplayDuration >
107+ <DisplayDuration
108+ :duration =" durations.loads" flex =" ~ gap-1 items-center"
109+ :title =" `load hooks cost: ${durations.loads}ms`"
110+ >
111+ <span i-ph-upload-simple-duotone inline-block />
112+ </DisplayDuration >
113+ <DisplayDuration
114+ :duration =" durations.transforms" flex =" ~ gap-1 items-center"
115+ :title =" `transform hooks cost: ${durations.transforms}ms`"
116+ >
117+ <span i-ph-magic-wand-duotone inline-block />
118+ </DisplayDuration >
119+ <span op40 >|</span >
120+ <DisplayDuration
121+ :duration =" durations.total" flex =" ~ gap-1 items-center"
122+ :title =" `Total build cost: ${durations.total}ms`"
123+ >
124+ <span i-ph-clock-duotone inline-block />
125+ </DisplayDuration >
126+ <span op40 >|</span >
127+ <div flex =" ~ gap-1 items-center" >
128+ <DisplayFileSizeBadge title =" Source code size" :bytes =" sourceCodeSize" />
129+ <span i-carbon-arrow-right op50 />
130+ <DisplayFileSizeBadge title =" Transformed code size" :bytes =" transformedCodeSize" />
131+ </div >
132+ </div >
64133 <div flex =" ~ gap-2" >
65134 <button
66135 :class =" view === 'flow' ? 'text-primary' : ''"
0 commit comments