Skip to content

Commit 29d7eb9

Browse files
webfansplzclaude
andauthored
feat(rolldown): add modules to session compare (#615)
* feat(rolldown): add modules to session compare Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * feat(rolldown): inline module details in compare --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 76282b9 commit 29d7eb9

8 files changed

Lines changed: 424 additions & 5 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<script setup lang="ts">
2+
import type { SessionContext } from '~~/shared/types'
3+
import { onKeyStroke } from '@vueuse/core'
4+
import { computed, reactive, watch } from 'vue'
5+
import { useRpc } from '#imports'
6+
import { getFileTypeFromName } from '~/utils/icon'
7+
8+
interface ModuleSide {
9+
session: string
10+
module: string
11+
}
12+
13+
const props = defineProps<{
14+
previous?: ModuleSide
15+
current?: ModuleSide
16+
side: 'previous' | 'current'
17+
}>()
18+
19+
const emit = defineEmits<{
20+
(e: 'close'): void
21+
(e: 'update:side', side: 'previous' | 'current'): void
22+
}>()
23+
24+
const rpc = useRpc()
25+
26+
// Lazily load and cache the full SessionContext for each session id.
27+
const sessionCache = new Map<string, SessionContext>()
28+
const contexts = reactive<Record<string, SessionContext | undefined>>({})
29+
30+
async function loadSession(id: string) {
31+
if (sessionCache.has(id)) {
32+
contexts[id] = sessionCache.get(id)
33+
return
34+
}
35+
const summary = await rpc.value.call('vite:rolldown:get-session-summary', { session: id })
36+
const context: SessionContext = {
37+
id,
38+
meta: summary.meta!,
39+
modulesList: summary.modules.map(mod => ({
40+
id: mod.id,
41+
fileType: getFileTypeFromName(mod.id).name,
42+
imports: mod.imports ?? [],
43+
importers: mod.importers ?? [],
44+
buildMetrics: mod.build_metrics,
45+
})),
46+
buildDuration: summary.build_duration,
47+
}
48+
sessionCache.set(id, context)
49+
contexts[id] = context
50+
}
51+
52+
const activeSide = computed(() => props.side === 'current' ? props.current : props.previous)
53+
const activeSession = computed(() => activeSide.value ? contexts[activeSide.value.session] : undefined)
54+
55+
watch(activeSide, (sideValue) => {
56+
if (sideValue)
57+
loadSession(sideValue.session)
58+
}, { immediate: true })
59+
60+
onKeyStroke('Escape', (e) => {
61+
e.preventDefault()
62+
emit('close')
63+
})
64+
</script>
65+
66+
<template>
67+
<div
68+
class="fixed right-0 bottom-0 top-20 left-20 z-panel-content bg-glass border-l border-t border-base rounded-tl-xl of-hidden"
69+
>
70+
<DataModuleDetailsLoader
71+
v-if="activeSide && activeSession"
72+
:key="`${activeSide.session}:${activeSide.module}`"
73+
:module="activeSide.module"
74+
:session="activeSession"
75+
@close="emit('close')"
76+
/>
77+
<VisualLoading v-else />
78+
79+
<!-- A/B switch floats above the loader, only meaningful when both sides exist -->
80+
<div
81+
v-if="previous && current"
82+
class="absolute top-2 left-1/2 translate-x--1/2 z-panel-content flex items-center gap-1 p0.5 bg-glass border border-base rounded-lg"
83+
>
84+
<button
85+
type="button"
86+
class="px3 py1 rounded-md text-sm"
87+
:class="side === 'previous' ? 'bg-active font-600' : 'op60 hover:op100'"
88+
@click="emit('update:side', 'previous')"
89+
>
90+
Session A
91+
</button>
92+
<button
93+
type="button"
94+
class="px3 py1 rounded-md text-sm"
95+
:class="side === 'current' ? 'bg-active font-600' : 'op60 hover:op100'"
96+
@click="emit('update:side', 'current')"
97+
>
98+
Session B
99+
</button>
100+
</div>
101+
</div>
102+
</template>

‎packages/rolldown/src/app/components/compare/SingleSideRow.vue‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@ withDefaults(defineProps<{
1414
delta: number
1515
format: 'bytes' | 'duration' | 'number'
1616
subtitle?: string
17+
link?: string
1718
badges?: string[]
1819
stats?: SingleSideDiffStat[]
20+
selectable?: boolean
1921
}>(), {
2022
subtitle: '',
2123
titleMeta: '',
2224
badges: () => [],
2325
stats: () => [],
26+
selectable: false,
2427
})
28+
29+
const emit = defineEmits<{
30+
(e: 'select'): void
31+
}>()
2532
</script>
2633

2734
<template>
@@ -32,7 +39,13 @@ withDefaults(defineProps<{
3239
{{ sessionLabel }}
3340
</div>
3441
<div class="flex items-baseline gap-2 min-w-0 font-mono" :title="titleMeta ? `${title} (${titleMeta})` : title">
35-
<span class="truncate">{{ title }}</span>
42+
<button v-if="selectable" type="button" class="truncate hover:underline text-left" @click="emit('select')">
43+
{{ title }}
44+
</button>
45+
<NuxtLink v-else-if="link" :to="link" class="truncate hover:underline">
46+
{{ title }}
47+
</NuxtLink>
48+
<span v-else class="truncate">{{ title }}</span>
3649
<span v-if="titleMeta" class="flex-none op50">({{ titleMeta }})</span>
3750
</div>
3851
<div v-if="subtitle" class="truncate text-xs op55 mt1" :title="subtitle">

‎packages/rolldown/src/app/components/compare/SplitRow.vue‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const props = withDefaults(defineProps<{
1616
currentTitleMeta?: string
1717
previousSubtitle?: string
1818
currentSubtitle?: string
19+
previousLink?: string
20+
currentLink?: string
1921
previousStats?: SplitDiffStat[]
2022
currentStats?: SplitDiffStat[]
2123
previousBadges?: string[]
@@ -25,14 +27,20 @@ const props = withDefaults(defineProps<{
2527
delta: number
2628
format: 'bytes' | 'duration' | 'number'
2729
ratioText?: string
30+
selectable?: boolean
2831
}>(), {
2932
previousStats: () => [],
3033
currentStats: () => [],
3134
previousBadges: () => [],
3235
currentBadges: () => [],
3336
ratioText: '',
37+
selectable: false,
3438
})
3539
40+
const emit = defineEmits<{
41+
(e: 'select', side: 'previous' | 'current'): void
42+
}>()
43+
3644
const ratioClass = computed(() => {
3745
if (props.delta > 0)
3846
return 'text-red-500'
@@ -62,7 +70,13 @@ const ratioClass = computed(() => {
6270
Session A
6371
</div>
6472
<div class="flex items-baseline gap-2 min-w-0 font-mono font-600" :title="previousTitleMeta ? `${previousTitle} (${previousTitleMeta})` : previousTitle">
65-
<span class="truncate">{{ previousTitle }}</span>
73+
<button v-if="selectable" type="button" class="truncate hover:underline text-left" @click="emit('select', 'previous')">
74+
{{ previousTitle }}
75+
</button>
76+
<NuxtLink v-else-if="previousLink" :to="previousLink" class="truncate hover:underline">
77+
{{ previousTitle }}
78+
</NuxtLink>
79+
<span v-else class="truncate">{{ previousTitle }}</span>
6680
<span v-if="previousTitleMeta" class="flex-none font-400 op50">({{ previousTitleMeta }})</span>
6781
</div>
6882
<div v-if="previousSubtitle" class="truncate text-xs op50 mt1" :title="previousSubtitle">
@@ -92,7 +106,13 @@ const ratioClass = computed(() => {
92106
Session B
93107
</div>
94108
<div class="flex items-baseline gap-2 min-w-0 font-mono font-600" :title="currentTitleMeta ? `${currentTitle} (${currentTitleMeta})` : currentTitle">
95-
<span class="truncate">{{ currentTitle }}</span>
109+
<button v-if="selectable" type="button" class="truncate hover:underline text-left" @click="emit('select', 'current')">
110+
{{ currentTitle }}
111+
</button>
112+
<NuxtLink v-else-if="currentLink" :to="currentLink" class="truncate hover:underline">
113+
{{ currentTitle }}
114+
</NuxtLink>
115+
<span v-else class="truncate">{{ currentTitle }}</span>
96116
<span v-if="currentTitleMeta" class="flex-none font-400 op50">({{ currentTitleMeta }})</span>
97117
</div>
98118
<div v-if="currentSubtitle" class="truncate text-xs op50 mt1" :title="currentSubtitle">

0 commit comments

Comments
 (0)