Skip to content

Commit

Permalink
feat(kit): for better naming of index.vue components (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
niksy authored Oct 10, 2024
1 parent 60dea66 commit 58195fc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/devtools-kit/src/core/component/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { basename, classify } from '@vue/devtools-shared'
import { Fragment } from '../../../shared/stub-vue'

function getComponentTypeName(options: VueAppInstance['type']) {
return options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
const name = options.name || options._componentTag || options.__VUE_DEVTOOLS_COMPONENT_GUSSED_NAME__ || options.__name
if (name === 'index' && options.__file?.endsWith('index.vue')) {
return ''
}
return name
}

function getComponentFileName(options: VueAppInstance['type']) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts">
const text = ref('Index')
</script>

<template>
<div>
{{ text }} Component
</div>
</template>
2 changes: 2 additions & 0 deletions packages/playground/basic/src/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import Foo from '../components/Foo.vue'
import IndexComponent from '../components/IndexComponent/index.vue'
const visible = ref(false)
Expand All @@ -23,6 +24,7 @@ const toRefObj = toRefs(obj)
<div class="m-auto mt-3 h-80 w-120 flex flex-col items-center justify-center rounded bg-[#363636]">
Home
<Foo v-if="visible" />
<IndexComponent v-if="visible" />
<img src="/vite.svg" alt="Vite Logo">
<button class="w-30 cursor-pointer" @click="visible = !visible">
Toggle Foo
Expand Down
6 changes: 4 additions & 2 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export function kebabize(str: string) {
}

export function basename(filename: string, ext: string): string {
const normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
let normalizedFilename = filename.replace(/^[a-z]:/i, '').replace(/\\/g, '/')
if (normalizedFilename.endsWith(`index${ext}`)) {
normalizedFilename = normalizedFilename.replace(`/index${ext}`, ext)
}
const lastSlashIndex = normalizedFilename.lastIndexOf('/')
const baseNameWithExt = normalizedFilename.substring(lastSlashIndex + 1)

if (ext) {
const extIndex = baseNameWithExt.lastIndexOf(ext)
return baseNameWithExt.substring(0, extIndex)
Expand Down

0 comments on commit 58195fc

Please sign in to comment.