Skip to content

Commit 58605dd

Browse files
liangmiQwQantfu
andauthored
feat: add imports display in chunk details (#82)
Co-authored-by: Anthony Fu <github@antfu.me>
1 parent 6598187 commit 58605dd

7 files changed

Lines changed: 170 additions & 9 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function openInEditor() {
115115
:chunk="chunk"
116116
:session="session"
117117
:show-modules="false"
118+
:show-imports="false"
118119
/>
119120
</div>
120121
</div>

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

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,51 @@ withDefaults(defineProps<{
66
chunk: ChunkInfo
77
session: SessionContext
88
showModules?: boolean
9+
showImports?: boolean
910
}>(), {
1011
showModules: true,
12+
showImports: true,
1113
})
1214
</script>
1315

1416
<template>
1517
<div flex="~ col gap-3">
16-
<div flex="~ gap-4 items-center">
18+
<div flex="~ gap-3 items-center">
1719
<div flex="~ gap-2 items-center" :title="`Chunk #${chunk.chunk_id}`">
1820
<div i-ph-shapes-duotone />
1921
<div>{{ chunk.name || '[unnamed]' }}</div>
2022
<DisplayBadge :text="chunk.reason" />
2123
</div>
24+
2225
<div flex-auto />
26+
2327
<span op50 font-mono>#{{ chunk.chunk_id }}</span>
28+
<div flex="~ gap-1 items-center">
29+
<div i-carbon-document-import />
30+
{{ chunk.imports.length }}
31+
</div>
2432
<div flex="~ gap-1 items-center">
2533
<div i-ph-package-duotone />
2634
{{ chunk.modules.length }}
2735
</div>
2836
</div>
2937

30-
<!-- TODO -->
31-
<!-- <div op50>
32-
Imports
33-
</div>
34-
<div flex="~ col gap-1" ws-nowrap>
35-
{{ chunk.imports }}
36-
</div> -->
38+
<template v-if="showImports && chunk.imports.length > 0">
39+
<div op50>
40+
Imports
41+
</div>
42+
<div flex="~ col gap-1" ws-nowrap>
43+
<DisplayChunkImports
44+
v-for="(importChunk, index) in chunk.imports"
45+
:key="index"
46+
:chunk-import="importChunk"
47+
:session="session"
48+
:importer="chunk"
49+
hover="bg-active"
50+
border="~ base rounded" px2 py1 w-full
51+
/>
52+
</div>
53+
</template>
3754

3855
<template v-if="showModules">
3956
<div op50>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang="ts">
2+
import type { SessionContext } from '../../../shared/types/data'
3+
import { useRpc } from '#imports'
4+
import { useAsyncState } from '@vueuse/core'
5+
6+
const props = defineProps<{
7+
chunk: number
8+
session: SessionContext
9+
}>()
10+
11+
const emit = defineEmits<{
12+
(e: 'close'): void
13+
}>()
14+
15+
const rpc = useRpc()
16+
const { state, isLoading } = useAsyncState(
17+
async () => {
18+
return await rpc.value!['vite:rolldown:get-chunk-info']?.({
19+
session: props.session.id,
20+
id: props.chunk,
21+
})
22+
},
23+
null,
24+
)
25+
</script>
26+
27+
<template>
28+
<VisualLoading v-if="isLoading" />
29+
30+
<div v-if="state" p4 pt-12 relative h-full w-full of-auto z-panel-content>
31+
<DisplayCloseButton
32+
absolute right-2 top-1.5
33+
@click="emit('close')"
34+
/>
35+
<DataChunkDetails :session="session" :chunk="state" />
36+
</div>
37+
</template>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script lang="ts" setup>
2+
import type { ChunkImport, Chunk as ChunkInfo } from '@rolldown/debug'
3+
import type { SessionContext } from '../../../shared/types/data'
4+
import { useRoute } from '#app/composables/router'
5+
import { useAsyncState } from '@vueuse/core'
6+
import { useRpc } from '../../../modules/rpc/runtime/composables/rpc'
7+
8+
const props = defineProps<{
9+
chunkImport: ChunkImport
10+
session: SessionContext
11+
importer: ChunkInfo
12+
}>()
13+
14+
const route = useRoute()
15+
16+
const rpc = useRpc()
17+
const { state: chunk } = useAsyncState(
18+
async () => {
19+
return await rpc.value!['vite:rolldown:get-chunk-info']?.({
20+
session: props.session.id,
21+
id: props.chunkImport.chunk_id,
22+
})
23+
},
24+
null,
25+
)
26+
</script>
27+
28+
<template>
29+
<!-- <VisualLoading /> -->
30+
<NuxtLink v-if="chunk" flex="~ items-center" :to="{ path: route.path, query: { chunk: chunk.chunk_id } }">
31+
<!-- Icon, Name, Reason -->
32+
<div flex="~ gap-2 items-center" :title="`Chunk #${chunk.chunk_id}`">
33+
<div v-if="chunkImport.kind === 'import-statement'" i-ph-file-duotone />
34+
<div v-if="chunkImport.kind === 'dynamic-import'" i-ph-lightning-duotone />
35+
<div>{{ chunk.name || '[unnamed]' }}</div>
36+
<DisplayBadge :text="chunk.reason" />
37+
38+
<!-- Import Kind -->
39+
<DisplayBadge v-if="chunkImport.kind === 'import-statement'" text="statement" :color="210" />
40+
<DisplayBadge v-if="chunkImport.kind === 'dynamic-import'" text="dynamic" :color="30" />
41+
</div>
42+
43+
<div flex-auto />
44+
45+
<div text-sm flex="~ items-center gap-2">
46+
<span op50 font-mono>#{{ chunk.chunk_id }}</span>
47+
<div flex="~ gap-1 items-center">
48+
<div i-carbon-document-import />
49+
{{ chunk.imports.length }}
50+
</div>
51+
<div flex="~ gap-1 items-center">
52+
<div i-ph-package-duotone />
53+
{{ chunk.modules.length }}
54+
</div>
55+
</div>
56+
</NuxtLink>
57+
</template>
58+
59+
<style>
60+
61+
</style>

packages/devtools-vite/src/app/pages/session/[session].vue

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ function closePluginPanel() {
3535
router.replace({ query: { ...route.query, plugin: undefined } })
3636
}
3737
38+
function closeChunkPanel() {
39+
router.replace({ query: { ...route.query, chunk: undefined } })
40+
}
41+
3842
onKeyDown('Escape', (e) => {
3943
e.preventDefault()
4044
4145
if (!e.isTrusted || e.repeat)
4246
return
4347
44-
const { module, asset, plugin } = route.query
48+
const { module, asset, plugin, chunk } = route.query
4549
4650
if (module)
4751
closeFlowPanel()
@@ -51,6 +55,9 @@ onKeyDown('Escape', (e) => {
5155
5256
if (plugin)
5357
closePluginPanel()
58+
59+
if (chunk)
60+
closeChunkPanel()
5461
})
5562
5663
useSideNav(() => {
@@ -168,5 +175,25 @@ onMounted(async () => {
168175
/>
169176
</div>
170177
</div>
178+
179+
<!-- for chunks -->
180+
<div
181+
v-if="route.query.chunk" fixed inset-0
182+
backdrop-blur-8 backdrop-brightness-95 z-panel-content
183+
@click.self="closeChunkPanel"
184+
>
185+
<div
186+
:key="(route.query.chunk as string)"
187+
fixed right-0 bottom-0 top-20 z-panel-content
188+
bg-glass border="l t base rounded-tl-xl"
189+
class="left-20 xl:left-100 2xl:left-150"
190+
>
191+
<DataChunkDetailsLoader
192+
:chunk="(Number(route.query.chunk))"
193+
:session="session"
194+
@close="closeChunkPanel"
195+
/>
196+
</div>
197+
</div>
171198
</div>
172199
</template>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineRpcFunction } from '@vitejs/devtools-kit'
2+
import { getLogsManager } from '../utils'
3+
4+
export const rolldownGetChunkInfo = defineRpcFunction({
5+
name: 'vite:rolldown:get-chunk-info',
6+
type: 'query',
7+
setup: (context) => {
8+
const manager = getLogsManager(context)
9+
return {
10+
handler: async ({ session, id }: { session: string, id: number }) => {
11+
const reader = await manager.loadSession(session)
12+
return reader.manager.chunks.get(id)
13+
},
14+
}
15+
},
16+
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { openInEditor } from './functions/open-in-editor'
44
import { openInFinder } from './functions/open-in-finder'
55
import { rolldownGetAssetDetails } from './functions/rolldown-get-asset-details'
66
import { rolldownGetAssetsList } from './functions/rolldown-get-assets-list'
7+
import { rolldownGetChunkInfo } from './functions/rolldown-get-chunk-info'
78
import { rolldownGetChunksGraph } from './functions/rolldown-get-chunks-graph'
89
import { rolldownGetModuleInfo } from './functions/rolldown-get-module-info'
910
import { rolldownGetModuleRawEvents } from './functions/rolldown-get-module-raw-events'
@@ -27,6 +28,7 @@ export const rpcFunctions = [
2728
rolldownGetAssetsList,
2829
rolldownGetAssetDetails,
2930
rolldownGetPluginDetails,
31+
rolldownGetChunkInfo,
3032
] as const
3133

3234
export type ServerFunctions = RpcDefinitionsToFunctions<typeof rpcFunctions>

0 commit comments

Comments
 (0)