Skip to content

Commit 63c5bdd

Browse files
committed
feat: chunk importers
1 parent b9979b4 commit 63c5bdd

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

packages/vite/src/app/components/display/ChunkImports.vue renamed to packages/vite/src/app/components/chunks/ImportItem.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,3 @@ const route = useRoute()
3838
</div>
3939
</NuxtLink>
4040
</template>
41-
42-
<style>
43-
44-
</style>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script lang="ts" setup>
2+
import type { RolldownChunkImport } from '~~/shared/types/data'
3+
4+
defineProps<{
5+
imports: RolldownChunkImport[]
6+
}>()
7+
</script>
8+
9+
<template>
10+
<div flex="~ col gap-1" mt2 ws-nowrap>
11+
<ChunksImportItem
12+
v-for="(chunk, index) in imports"
13+
:key="index"
14+
:chunk="chunk"
15+
hover="bg-active"
16+
border="~ base rounded" px2 py1 w-full
17+
/>
18+
</div>
19+
</template>

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

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ const { state, isLoading } = useAsyncState(
4343
null,
4444
)
4545
46+
const normalizedChunks = computed(() => props.chunks || state.value)
47+
4648
const imports = computed((): RolldownChunkImport[] => {
4749
return props.chunk.imports.map((importChunk) => {
48-
const chunk = (props.chunks || state.value)?.find(c => c.chunk_id === importChunk.chunk_id)
50+
const chunk = normalizedChunks.value?.find(c => c.chunk_id === importChunk.chunk_id)
4951
5052
return {
5153
...importChunk,
@@ -56,6 +58,20 @@ const imports = computed((): RolldownChunkImport[] => {
5658
}
5759
})
5860
})
61+
62+
const importers = computed((): RolldownChunkImport[] => {
63+
return normalizedChunks.value?.filter(c => c.imports.some(i => i.chunk_id === props.chunk.chunk_id)).map((chunk) => {
64+
const importChunk = chunk.imports.find(i => i.chunk_id === props.chunk.chunk_id)!
65+
66+
return {
67+
...importChunk,
68+
name: chunk.name || '[unnamed]',
69+
reason: chunk.reason || 'common',
70+
imports: chunk.imports.length || 0,
71+
modules: chunk.modules.length || 0,
72+
}
73+
}) || []
74+
})
5975
</script>
6076

6177
<template>
@@ -100,22 +116,22 @@ const imports = computed((): RolldownChunkImport[] => {
100116
</div>
101117
</details>
102118

103-
<!-- TODO: imports seems to be "imported-by" instead of "imports", maybe something wrong on Rolldown side? -->
104-
<!-- TODO: We might want to display both "imports" and "imported-by" relationship -->
105-
<details v-if="showImports && chunk.imports.length > 0" open="true">
106-
<summary op50>
107-
<span>Imports ({{ chunk.imports.length }})</span>
108-
</summary>
109-
<VisualLoading v-if="isLoading" />
110-
<div v-else flex="~ col gap-1" mt2 ws-nowrap>
111-
<DisplayChunkImports
112-
v-for="chunkImport in imports"
113-
:key="chunkImport.chunk_id"
114-
:chunk="chunkImport"
115-
hover="bg-active"
116-
border="~ base rounded" px2 py1 w-full
117-
/>
118-
</div>
119-
</details>
119+
<VisualLoading v-if="isLoading" />
120+
121+
<template v-else-if="showImports">
122+
<details v-if="chunk.imports.length" open="true">
123+
<summary op50>
124+
<span>Imports ({{ chunk.imports.length }})</span>
125+
</summary>
126+
<ChunksImports :imports="imports" />
127+
</details>
128+
129+
<details v-if="importers.length" open="true">
130+
<summary op50>
131+
<span>Importers ({{ importers.length }})</span>
132+
</summary>
133+
<ChunksImports :imports="importers" />
134+
</details>
135+
</template>
120136
</div>
121137
</template>

packages/vite/src/app/pages/session/[session]/chunks.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ function toggleDisplay(type: ClientSettings['chunkViewType']) {
5858
<div :class="viewType.icon" />
5959
{{ viewType.label }}
6060
</button>
61-
<!-- TODO: add graph views -->
6261
</div>
6362
</div>
6463
<template v-if="settings.chunkViewType === 'list'">

0 commit comments

Comments
 (0)