Skip to content

Commit b76b0fc

Browse files
committed
feat: basic data fetcher
1 parent 6a70b79 commit b76b0fc

File tree

15 files changed

+216
-28
lines changed

15 files changed

+216
-28
lines changed

packages/devtools/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@
4747
"p-limit": "catalog:deps",
4848
"pathe": "catalog:deps",
4949
"publint": "catalog:deps",
50+
"stream-json": "catalog:deps",
5051
"structured-clone-es": "catalog:deps",
5152
"tinyglobby": "catalog:deps",
5253
"unconfig": "catalog:deps",
5354
"unstorage": "catalog:deps",
5455
"ws": "catalog:deps"
5556
},
5657
"devDependencies": {
58+
"@types/stream-json": "catalog:types",
5759
"@unocss/nuxt": "catalog:build",
5860
"@vueuse/nuxt": "catalog:build",
5961
"d3": "catalog:frontend",

packages/devtools/src/app/app.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useHead } from '#app/composables/head'
33
import { shallowRef } from 'vue'
44
import { createDevBackend } from './backends/dev'
55
import { backend } from './state/backend'
6-
import { fetchData, rawEvents } from './state/data'
6+
import { fetchData } from './state/data'
77
88
import 'floating-vue/dist/style.css'
99
import './styles/global.css'
@@ -29,7 +29,13 @@ createDevBackend()
2929
</script>
3030

3131
<template>
32-
<div>
33-
{{ rawEvents }}
32+
<div v-if="error" text-red>
33+
{{ error }}
34+
</div>
35+
<div v-else-if="!backend">
36+
Connecting...
37+
</div>
38+
<div v-else>
39+
<NuxtPage />
3440
</div>
3541
</template>

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,6 @@ export function createWebSocketBackend(options: WebSocketBackendOptions): Backen
8686
await connectPromise
8787
},
8888
isDynamic: true,
89-
functions: {
90-
'vite:get-payload': async () => {
91-
try {
92-
return await rpc['vite:get-payload']()
93-
}
94-
catch (err) {
95-
error.value = err
96-
throw err
97-
}
98-
},
99-
'vite:open-in-editor': async (filename: string) => rpc['vite:open-in-editor'].asEvent(filename),
100-
'vite:open-in-finder': async (filename: string) => rpc['vite:open-in-finder'].asEvent(filename),
101-
},
89+
functions: rpc,
10290
}
10391
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup lang="ts">
2+
import { backend } from '../../state/backend'
3+
4+
const builds = await backend.value!.functions['vite:rolldown:list-builds']()
5+
</script>
6+
7+
<template>
8+
<div flex="~ col gap-2">
9+
<NuxtLink
10+
v-for="build of builds"
11+
:key="build.id"
12+
:to="`/build/${build.id}`"
13+
hover="bg-active"
14+
border="~ base rounded-md"
15+
p="x-2 y-1"
16+
>
17+
{{ build.id }}
18+
</NuxtLink>
19+
</div>
20+
</template>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script setup lang="ts">
2+
import type { Event } from '@rolldown/debug'
3+
import { useRoute } from '#app/composables/router'
4+
import { onMounted, shallowRef } from 'vue'
5+
import { backend } from '~/state/backend'
6+
7+
const params = useRoute().params
8+
9+
const events = shallowRef<Event[]>([])
10+
11+
onMounted(async () => {
12+
events.value = await backend.value!.functions['vite:rolldown:get-raw-events']({
13+
buildId: params.id,
14+
})
15+
})
16+
</script>
17+
18+
<template>
19+
<div>
20+
{{ params }}
21+
{{ events }}
22+
</div>
23+
</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>
6-
Redirecting...
6+
<PanelSelectBuild />
77
</div>
88
</template>

packages/devtools/src/node/rpc/functions/get-payload.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { defineRpcFunction } from '../types'
33
export const getPayload = defineRpcFunction({
44
name: 'vite:get-payload',
55
type: 'static',
6-
setup: () => ({
7-
handler: async () => ({
8-
timestamp: Date.now(),
9-
}),
10-
}),
6+
setup: () => {
7+
return {
8+
handler: async () => ({
9+
timestamp: Date.now(),
10+
}),
11+
}
12+
},
1113
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Event } from '@rolldown/debug'
2+
import fs from 'node:fs/promises'
3+
import { join } from 'pathe'
4+
import { parseJsonStreamWithConcatArrays } from '../../utils/json-parse-stream'
5+
import { defineRpcFunction } from '../types'
6+
7+
export const rolldownGetRawEvents = defineRpcFunction({
8+
name: 'vite:rolldown:get-raw-events',
9+
type: 'query',
10+
setup: ({ cwd }) => {
11+
return {
12+
handler: async ({ buildId }) => {
13+
const raw = await fs.open(join(cwd, '.rolldown', buildId, 'log.json'), 'r')
14+
const stream = raw.createReadStream()
15+
const events = await parseJsonStreamWithConcatArrays(stream) as Event[]
16+
return events
17+
},
18+
}
19+
},
20+
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'node:fs/promises'
2+
import { join } from 'pathe'
3+
import { defineRpcFunction } from '../types'
4+
5+
export interface BuildInfo {
6+
id: string
7+
createdAt: number
8+
}
9+
10+
export const rolldownListBuilds = defineRpcFunction({
11+
name: 'vite:rolldown:list-builds',
12+
type: 'query',
13+
setup: ({ cwd }) => {
14+
return {
15+
handler: async (): Promise<BuildInfo[]> => {
16+
const builds = await fs.readdir(join(cwd, '.rolldown'), {
17+
withFileTypes: true,
18+
})
19+
return await Promise.all(builds
20+
.filter(d => d.isDirectory())
21+
.map(async (d): Promise<BuildInfo> => {
22+
// TODO: read from meta.json
23+
const stats = await fs.stat(join(cwd, '.rolldown', d.name))
24+
return {
25+
id: d.name,
26+
createdAt: stats.birthtime.getTime(),
27+
}
28+
}),
29+
)
30+
},
31+
}
32+
},
33+
})

packages/devtools/src/node/rpc/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import type { DefinitionsToFunctions, FilterDefinitions } from './types'
22
import { getPayload } from './functions/get-payload'
33
import { openInEditor } from './functions/open-in-editor'
44
import { openInFinder } from './functions/open-in-finder'
5+
import { rolldownGetRawEvents } from './functions/rolldown-get-raw-events'
6+
import { rolldownListBuilds } from './functions/rolldown-list-builds'
57

68
export const rpcFunctions = [
79
openInEditor,
810
openInFinder,
911
getPayload,
12+
rolldownListBuilds,
13+
rolldownGetRawEvents,
1014
] as const
1115

1216
export type ServerFunctions = DefinitionsToFunctions<typeof rpcFunctions>

0 commit comments

Comments
 (0)