Skip to content

Commit 861a480

Browse files
committed
feat: date rolldown data structure
1 parent ccdf780 commit 861a480

14 files changed

Lines changed: 129 additions & 122 deletions

File tree

packages/devtools/src/app/backends/static.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ServerFunctionsDump } from '../../node/rpc'
1+
import type { ServerFunctions, ServerFunctionsDump } from '../../node/rpc'
22
import type { Backend } from '../types/backend'
33
import { useRuntimeConfig } from '#app/nuxt'
44
import { parse } from 'structured-clone-es'
@@ -32,6 +32,6 @@ export function createStaticBackend(): Backend {
3232
'vite:get-payload': async () => {
3333
return getDump.then(dump => dump['vite:get-payload'])
3434
},
35-
},
35+
} as ServerFunctions,
3636
}
3737
}

packages/devtools/src/app/components/data/RawEventsTable.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RolldownEvent } from '../../../node/rolldown/events-manager'
33
import { Dropdown as VDropdown } from 'floating-vue'
44
import { defineProps, withDefaults } from 'vue'
55
6-
type FIELDS = 'module_id' | 'kind' | 'source' | 'timestamp' | 'event_id' | 'plugin_name' | '*'
6+
type FIELDS = 'module_id' | 'action' | 'source' | 'timestamp' | 'event_id' | 'plugin_name' | '*'
77
88
const props = withDefaults(
99
defineProps<{
@@ -13,7 +13,7 @@ const props = withDefaults(
1313
{
1414
fields: () => [
1515
'event_id',
16-
'kind',
16+
'action',
1717
'module_id',
1818
'plugin_name',
1919
'timestamp',
@@ -38,13 +38,13 @@ function omit(obj: RolldownEvent, inputs: string[]) {
3838
}
3939
4040
function getSource(event: RolldownEvent) {
41-
if (event.kind === 'HookLoadCallEnd') {
41+
if (event.action === 'HookLoadCallEnd') {
4242
return event.source
4343
}
44-
if (event.kind === 'HookTransformCallStart') {
44+
if (event.action === 'HookTransformCallStart') {
4545
return event.source
4646
}
47-
if (event.kind === 'HookTransformCallEnd') {
47+
if (event.action === 'HookTransformCallEnd') {
4848
return event.transformed_source
4949
}
5050
return null
@@ -58,7 +58,7 @@ function getSource(event: RolldownEvent) {
5858
<template v-for="field of props.fields" :key="field">
5959
<td px2>
6060
<DisplayModuleId v-if="field === 'module_id'" :id="'module_id' in event ? event.module_id : ''" />
61-
<DisplayBadge v-else-if="field === 'kind'" :text="event.kind" />
61+
<DisplayBadge v-else-if="field === 'action'" :text="event.action" />
6262
<div v-else-if="field === 'plugin_name' && 'plugin_name' in event">
6363
<DisplayPluginName font-mono :name="event.plugin_name" />
6464
<code op50>#{{ event.plugin_index }}</code>

packages/devtools/src/app/components/panel/SelectBuild.vue renamed to packages/devtools/src/app/components/panel/SessionSelector.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<script setup lang="ts">
22
import { backend } from '../../state/backend'
33
4-
const builds = await backend.value!.functions['vite:rolldown:list-sessions']()
4+
const sessions = await backend.value!.functions['vite:rolldown:list-sessions']()
55
</script>
66

77
<template>
88
<div flex="~ col gap-2">
99
<NuxtLink
10-
v-for="build of builds"
11-
:key="build.id"
12-
:to="`/build/${build.id}`"
10+
v-for="session of sessions"
11+
:key="session.id"
12+
:to="`/session/${session.id}`"
1313
hover="bg-active"
1414
border="~ base rounded-md"
1515
p="x-2 y-1" font-mono
1616
>
17-
{{ build.id }}
17+
{{ session.id }}
1818
</NuxtLink>
1919
</div>
2020
</template>

packages/devtools/src/app/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
<template>
55
<div p4>
6-
<PanelSelectBuild />
6+
<PanelSessionSelector />
77
</div>
88
</template>

packages/devtools/src/app/pages/build/[build]/flow.vue renamed to packages/devtools/src/app/pages/session/[session]/flow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { useAsyncState } from '@vueuse/core'
44
import { backend } from '../../../state/backend'
55
66
const params = useRoute().params as {
7-
build: string
7+
session: string
88
}
99
const query = useRoute().query
1010
1111
const { state: info } = useAsyncState(
1212
async () => {
1313
return await backend.value!.functions['vite:rolldown:get-module-info']?.({
14-
session: params.build as string,
14+
session: params.session as string,
1515
module: query.module as string,
1616
})
1717
},

packages/devtools/src/app/pages/build/[build]/index.vue renamed to packages/devtools/src/app/pages/session/[session]/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { computed, onMounted, reactive, shallowRef } from 'vue'
55
import { backend } from '../../../state/backend'
66
77
const params = useRoute().params as {
8-
build: string
8+
session: string
99
}
1010
1111
const modules = shallowRef<{ id: string }[]>([])
@@ -28,7 +28,7 @@ const filtered = computed(() => {
2828
2929
onMounted(async () => {
3030
modules.value = await backend.value!.functions['vite:rolldown:get-module-list']!({
31-
session: params.build,
31+
session: params.session,
3232
})
3333
fuse.setCollection(modules.value)
3434
})
@@ -46,7 +46,7 @@ onMounted(async () => {
4646
</div>
4747
<template v-for="mod of filtered" :key="mod">
4848
<NuxtLink
49-
:to="{ path: `/build/${params.build}/flow`, query: { module: mod.id } }"
49+
:to="{ path: `/session/${params.session}/flow`, query: { module: mod.id } }"
5050
hover="bg-active" block px2 p1
5151
border="~ base rounded"
5252
>

packages/devtools/src/app/pages/build/[build]/raw.vue renamed to packages/devtools/src/app/pages/session/[session]/raw.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import { useAsyncState } from '@vueuse/core'
44
import { backend } from '../../../state/backend'
55
66
const params = useRoute().params as {
7-
build: string
7+
session: string
88
}
99
const query = useRoute().query
1010
1111
const events = useAsyncState(
1212
async () => {
1313
return await backend.value!.functions['vite:rolldown:get-module-raw-events']?.({
14-
build: params.build as string,
14+
session: params.session as string,
1515
module: query.module as string,
1616
})
1717
},

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import type { Action, Event } from '@rolldown/debug'
1+
import type { Event } from '@rolldown/debug'
22

3-
export type RolldownEvent = Action & {
3+
export type RolldownEvent = Event & {
44
event_id: string
5-
timestamp: string
65
}
76

87
export class RolldownEventsManager {
98
events: RolldownEvent[] = []
109

1110
handleEvent(raw: Event) {
1211
const event = {
13-
...raw.fields.action,
12+
...raw,
1413
event_id: `${raw.timestamp}#${this.events.length}`,
15-
timestamp: raw.timestamp,
1614
}
1715
this.events.push(event)
1816
return event

packages/devtools/src/node/rpc/functions/rolldown-get-module-info.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const rolldownGetModuleInfo = defineRpcFunction({
7070
setup: ({ cwd }) => {
7171
return {
7272
handler: async ({ session, module }: { session: string, module: string }) => {
73-
const reader = RolldownEventsReader.get(join(cwd, '.rolldown', session, 'log.json'))
73+
const reader = RolldownEventsReader.get(join(cwd, '.rolldown', session, 'logs.json'))
7474
await reader.read()
7575
const events = reader.manager.events.filter(event => 'module_id' in event && event.module_id === module)
7676

@@ -87,9 +87,9 @@ export const rolldownGetModuleInfo = defineRpcFunction({
8787
}
8888

8989
for (const event of events) {
90-
if (event.kind === 'HookLoadCallEnd') {
90+
if (event.action === 'HookLoadCallEnd') {
9191
// TODO: use ID to pair start and end
92-
const start = events.find(e => e.kind === 'HookLoadCallStart' && e.module_id === event.module_id && e.plugin_index === event.plugin_index)
92+
const start = events.find(e => e.action === 'HookLoadCallStart' && e.module_id === event.module_id && e.plugin_index === event.plugin_index)
9393
if (!start) {
9494
console.error(`[rolldown] Load call start not found for ${event.event_id}`)
9595
continue
@@ -111,10 +111,10 @@ export const rolldownGetModuleInfo = defineRpcFunction({
111111
}
112112

113113
for (const event of events) {
114-
if (event.kind === 'HookTransformCallEnd') {
114+
if (event.action === 'HookTransformCallEnd') {
115115
// TODO: use ID to pair start and end
116-
const start = events.find(e => e.kind === 'HookTransformCallStart' && e.module_id === event.module_id && e.plugin_index === event.plugin_index)
117-
if (!start || start.kind !== 'HookTransformCallStart') {
116+
const start = events.find(e => e.action === 'HookTransformCallStart' && e.module_id === event.module_id && e.plugin_index === event.plugin_index)
117+
if (!start || start.action !== 'HookTransformCallStart') {
118118
console.error(`[rolldown] Transform call start not found for ${event.event_id}`)
119119
continue
120120
}
@@ -147,10 +147,10 @@ export const rolldownGetModuleInfo = defineRpcFunction({
147147
}
148148

149149
for (const event of events) {
150-
if (event.kind === 'HookResolveIdCallEnd') {
150+
if (event.action === 'HookResolveIdCallEnd') {
151151
// TODO: use ID to pair start and end
152-
const start = events.find(e => e.kind === 'HookResolveIdCallStart' && e.plugin_index === event.plugin_index)
153-
if (!start || start.kind !== 'HookResolveIdCallStart') {
152+
const start = events.find(e => e.action === 'HookResolveIdCallStart' && e.plugin_index === event.plugin_index)
153+
if (!start || start.action !== 'HookResolveIdCallStart') {
154154
console.error(`[rolldown] resolveId call start not found for ${event.event_id}`)
155155
continue
156156
}

packages/devtools/src/node/rpc/functions/rolldown-get-module-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const rolldownGetModuleList = defineRpcFunction({
88
setup: async ({ cwd }) => {
99
return {
1010
handler: async ({ session }: { session: string }) => {
11-
const reader = RolldownEventsReader.get(join(cwd, '.rolldown', session, 'log.json'))
11+
const reader = RolldownEventsReader.get(join(cwd, '.rolldown', session, 'logs.json'))
1212
await reader.read()
1313
const modules = new Set<string>()
1414
for (const event of reader.manager.events) {

0 commit comments

Comments
 (0)