Skip to content

Commit 58195fc

Browse files
authoredOct 10, 2024··
feat(kit): for better naming of index.vue components (#628)
1 parent 60dea66 commit 58195fc

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed
 

‎packages/devtools-kit/src/core/component/utils/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { basename, classify } from '@vue/devtools-shared'
33
import { Fragment } from '../../../shared/stub-vue'
44

55
function getComponentTypeName(options: VueAppInstance['type']) {
6-
return options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
6+
const name = options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
7+
if (name === 'index' && options.__file?.endsWith('index.vue')) {
8+
return ''
9+
}
10+
return name
711
}
812

913
function getComponentFileName(options: VueAppInstance['type']) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup lang="ts">
2+
const text = ref('Index')
3+
</script>
4+
5+
<template>
6+
<div>
7+
{{ text }} Component
8+
</div>
9+
</template>

‎packages/playground/basic/src/pages/Home.vue

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
import Foo from '../components/Foo.vue'
3+
import IndexComponent from '../components/IndexComponent/index.vue'
34
45
const visible = ref(false)
56
@@ -23,6 +24,7 @@ const toRefObj = toRefs(obj)
2324
<div class="m-auto mt-3 h-80 w-120 flex flex-col items-center justify-center rounded bg-[#363636]">
2425
Home
2526
<Foo v-if="visible" />
27+
<IndexComponent v-if="visible" />
2628
<img src="/vite.svg" alt="Vite Logo">
2729
<button class="w-30 cursor-pointer" @click="visible = !visible">
2830
Toggle Foo

‎packages/shared/src/general.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ export function kebabize(str: string) {
2828
}
2929

3030
export function basename(filename: string, ext: string): string {
31-
const normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
31+
let normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
32+
if (normalizedFilename.endsWith(`index${ext}`)) {
33+
normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext)
34+
}
3235
const lastSlashIndex = normalizedFilename.lastIndexOf('/')
3336
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1)
34-
3537
if (ext) {
3638
const extIndex = baseNameWithExt.lastIndexOf(ext)
3739
return baseNameWithExt.substring(0, extIndex)

0 commit comments

Comments
 (0)
Please sign in to comment.